Skip to content

Latest commit

 

History

History
79 lines (54 loc) · 1.75 KB

File metadata and controls

79 lines (54 loc) · 1.75 KB

Shelly-and-Homeassistant

ShellyScripts for Home Assistant integration

This repository contains native scripts for Shelly Pro 4PM and Shelly Dimmer Pro 2PM devices.

It includes:

  • A script for button events → MQTT
  • A script for output control + Home Assistant MQTT discovery

The Shelly Pro 4PM script implements:

  • up
  • down
  • held
  • double-tap
    …matching the behavior of the Shelly Dimmer Pro 2PM.

Features

  • Native ShellyScript implementation
  • Automatic Home Assistant MQTT discovery
  • Reliable button event handling
  • MQTT-based output state reporting
  • Consistent behavior across 4PM and 2PM models

MQTT Configuration (Required)

Set the following MQTT settings on your Shelly device:

Enable 'MQTT Control'                  ON
Enable RPC over MQTT                  OFF
RPC status notifications over MQTT    OFF
Generic status update over MQTT       ON

Note: I never got RPC over MQTT working.


File Structure

/scripts
   button_to_mqtt.js
   output_discovery.js

README.md

Installation

  1. Open the Shelly Web UI.
  2. Go to Scripts → Add script.
  3. Paste in the desired script from the scripts/ folder.
  4. Set the script to Enabled + Startup
  5. Ensure your MQTT broker is reachable and credentials are configured.

Home Assistant Integration

Once the script is running:

  • Switch and sensor entities will appear automatically if MQTT discovery is enabled in Home Assistant.
  • Button events will be published to MQTT under the topic structure defined inside the script.
  • No YAML configuration is required.

Notes

  • These scripts are designed for devices running the latest Shelly Gen2 firmware.
  • MQTT discovery entity names can be customized inside the scripts.