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.
- Native ShellyScript implementation
- Automatic Home Assistant MQTT discovery
- Reliable button event handling
- MQTT-based output state reporting
- Consistent behavior across 4PM and 2PM models
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.
/scripts
button_to_mqtt.js
output_discovery.js
README.md
- Open the Shelly Web UI.
- Go to Scripts → Add script.
- Paste in the desired script from the
scripts/folder. - Set the script to Enabled + Startup
- Ensure your MQTT broker is reachable and credentials are configured.
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.
- These scripts are designed for devices running the latest Shelly Gen2 firmware.
- MQTT discovery entity names can be customized inside the scripts.