Skip to content
Script that adds MQTT discovery support for Shellies devices
Python
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
images Add screnshot Jul 14, 2019
python_scripts Add power sensor for RGBW2 Oct 20, 2019
.gitignore Version 0.11.0 Aug 18, 2019
LICENSE Update LICENSE Nov 12, 2019
README.md Update README.md Nov 13, 2019
hacs.json Prettier Sep 4, 2019
info.md Update info.md Oct 16, 2019

README.md

Shellies Discovery

GitHub Release hacs_badge Community Forum Buy me a coffee

Screenshot

This script adds MQTT discovery support for Shellies in the Home Assistant.

This script use Home Assistant python_script component and you have to add it to your configuration.yaml file:

python_script:

You can install this script via HACS or just download shellies_discovery.py file and save it in /config/python_scripts folder.

After installing the script and adding automations, run Shellies Announce automation or restart Home Assistant twice.

Go to HA community for support and help.

Supported devices:

  • Shelly1
  • Shelly1PM
  • Shelly2 (relays and roller mode)
  • Shelly2.5 (relays and roller mode)
  • Shelly4Pro
  • Shelly Plug
  • Shelly Plug S
  • Shelly RGBW2 (color and white mode)
  • Shelly Bulb
  • Shelly H&T (with or without USB adapter)
  • Shelly Smoke
  • Shelly Sense
  • ShellyEM
  • Shelly Flood

Troubleshooting checklist

  • correct MQTT configuration in Home Assistant with discovery enabled
  • same discovery_prefix in Home Assistant configuration and in script configuration
  • Shellies firmware updated to current version
  • Home Assistant updated to current version
  • enabled MQTT in Shellies configuration
  • default topics configuration in Shellies

Minimal configuration

python_script:

automation:
  - id: shellies_announce
    alias: 'Shellies Announce'
    trigger:
      - platform: homeassistant
        event: start
    action:
      service: mqtt.publish
      data:
        topic: shellies/command
        payload: announce

  - id: 'shellies_discovery'
    alias: 'Shellies Discovery'
    trigger:
      - platform: mqtt
        topic: shellies/announce
    action:
      service: python_script.shellies_discovery
      data_template:
        id: '{{ trigger.payload_json.id }}'
        mac: '{{ trigger.payload_json.mac }}'
        fw_ver: '{{ trigger.payload_json.fw_ver }}'

Custom configuration example

python_script:

automation:
  - id: shellies_announce
    alias: 'Shellies Announce'
    trigger:
      - platform: homeassistant
        event: start
    action:
      service: mqtt.publish
      data:
        topic: shellies/command
        payload: announce

  - id: 'shellies_discovery'
    alias: 'Shellies Discovery'
    trigger:
      - platform: mqtt
        topic: shellies/announce
    action:
      service: python_script.shellies_discovery
      data_template:
        id: '{{ trigger.payload_json.id }}'
        mac: '{{ trigger.payload_json.mac }}'
        fw_ver: '{{ trigger.payload_json.fw_ver }}'
        discovery_prefix: 'hass'
        temp_unit: 'F'
        qos: 2
        shelly1-001122-relay-0: 'light'
        shellyswitch-9900AA-relay-0: 'light'
        shellyswitch-9900AA-relay-1: 'fan'
        shellyswitch25-334411-relay-1: 'light'
        shellyswitch-334455: 'cover'
        shellyrgbw2-AABB22: 'white'
        shellyrgbw2-CC2211: 'rgbw'
        shellyht-2200AA: 'ac_power'

Script arguments

key optional type default description
discovery_prefix True string homeassistant MQTT discovery prefix
temp_unit True string C temperature unit, C for Celsius, F for Farenhait
qos True integer 0 MQTT QoS, you can use 0, 1 or 2
relay_id/shelly_id True string switch HA component to use with relay_id, for example: shelly1-001122-relay-0: 'light' means that relay 0 of shelly1-001122 will use light component in HA. You can use switch, light or fan. For Shelly2 and Shelly2.5 you can use shellyswitch-334455: 'cover' for roller mode. For ShellyRGBW2 you can use shellyrgbw2-AABB22: 'white' for wite mode.
You can’t perform that action at this time.