Shellies Discovery Script

I am now testing Shelly RGBW2. Trying with the “transition” data atribute from service light.turn_on and unfortunately it didnt works. As I have checked the MQTT “template” schema supports transitions . Maybe Shellies generally do not support transition? Or it is not implemented in the shellies discovery script?

According to the Shelly API page RGBW2 doesn’t support transitions between states. I don’t have RGBW2 so I can’t confirm this. Ask Shelly support.

I have a Shelly 1, and I can’t configure it as a light:

- 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 }}'
      shelly1_98F4ABF245F3_relay_0: 'light'

I just stays a switch, and there is no light entity in my MQTT integration.

Your configuration is wrong. Please read the open post.

I see your point.

- 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 }}'
      shelly1-98F4ABF245F3-relay-0: 'light'

This should be correct right? Something seems broken. When first upon entering invalid entries I still got a broken light bulb in the MQTT integration page. But now with the above code the switch is there but no light entity.

Can you please guide me in the right direction? That would be much appreciated!

This is correct. You can turn on debug information from the script: https://github.com/bieniu/ha-shellies-discovery#how-to-debug

New version: 0.17.0

Changelog:

  • add ignored_devices argument to ignore devices from discovery (you can also remove discovered devices with this argument)
2020-03-10 21:07:44 INFO (MainThread) [homeassistant.helpers.script] Script Shellies Announce: Running script
2020-03-10 21:07:44 INFO (MainThread) [homeassistant.helpers.script] Script Shellies Announce: Executing step call service
2020-03-10 21:07:44 INFO (MainThread) [homeassistant.helpers.script] Script Shellies Discovery: Running script
2020-03-10 21:07:44 INFO (MainThread) [homeassistant.helpers.script] Script Shellies Discovery: Executing step call service
2020-03-10 21:07:44 INFO (MainThread) [homeassistant.helpers.script] Script Shellies Discovery: Executing step call service
2020-03-10 21:07:44 INFO (SyncWorker_7) [homeassistant.components.python_script] Executing shellies_discovery.py: {'id': 'shelly1-gang_beneden', 'mac': '98F4ABF245F3', 'fw_ver': '20200206-083100/v1.5.10@e6a4205e', 'shelly1-98F4ABF245F3-relay-0': 'light'}
2020-03-10 21:07:44 DEBUG (SyncWorker_7) [homeassistant.components.python_script.shellies_discovery.py] id: shelly1-gang_beneden, mac: 98F4ABF245F3, fw_ver: 20200206-083100/v1.5.10@e6a4205e
2020-03-10 21:07:44 INFO (SyncWorker_6) [homeassistant.components.python_script] Executing shellies_discovery.py: {'id': 'shellyduo-kelder', 'mac': '98F4ABD12E09', 'fw_ver': '20200129-155730/master@a18bfaec', 'shelly1-98F4ABF245F3-relay-0': 'light'}
2020-03-10 21:07:44 DEBUG (SyncWorker_7) [homeassistant.components.python_script.shellies_discovery.py] Send to MQTT broker: homeassistant/switch/shelly1-gang_beneden-relay-0/config {"name":"Shelly1 gang_beneden Relay 0","cmd_t":"~relay/0/command","stat_t":"~relay/0","pl_off":"off","pl_on":"on","avty_t":"~online","pl_avail":"true","pl_not_avail":"false","uniq_id":"shelly1-gang_beneden-relay-0","qos":"0","dev": {"ids": ["98F4ABF245F3"],"name":"Shelly1 gang_beneden","mdl":"Shelly1","sw":"20200206-083100/v1.5.10@e6a4205e","mf":"Allterco Robotics"},"~":"shellies/shelly1-gang_beneden/"}
2020-03-10 21:07:44 DEBUG (SyncWorker_6) [homeassistant.components.python_script.shellies_discovery.py] id: shellyduo-kelder, mac: 98F4ABD12E09, fw_ver: 20200129-155730/master@a18bfaec
2020-03-10 21:07:44 DEBUG (SyncWorker_7) [homeassistant.components.python_script.shellies_discovery.py] Send to MQTT broker: homeassistant/light/shelly1-gang_beneden-relay-0/config
2020-03-10 21:07:44 DEBUG (SyncWorker_7) [homeassistant.components.python_script.shellies_discovery.py] Send to MQTT broker: homeassistant/fan/shelly1-gang_beneden-relay-0/config
2020-03-10 21:07:44 DEBUG (SyncWorker_7) [homeassistant.components.python_script.shellies_discovery.py] Send to MQTT broker: homeassistant/binary_sensor/shelly1-gang_beneden-input-0/config {"name":"Shelly1 gang_beneden Input 0","stat_t":"~input/0","pl_on":"1","pl_off":"0","avty_t":"~online","pl_avail":"true","pl_not_avail":"false","uniq_id":"shelly1-gang_beneden-input-0","qos":"0","dev": {"ids": ["98F4ABF245F3"],"name":"Shelly1 gang_beneden","mdl":"Shelly1","sw":"20200206-083100/v1.5.10@e6a4205e","mf":"Allterco Robotics"},"~":"shellies/shelly1-gang_beneden/"}
2020-03-10 21:07:44 DEBUG (SyncWorker_7) [homeassistant.components.python_script.shellies_discovery.py] Send to MQTT broker: homeassistant/binary_sensor/shelly1-gang_beneden-longpush-0/config {"name":"Shelly1 gang_beneden Longpush 0","stat_t":"~longpush/0","pl_on":"1","pl_off":"0","avty_t":"~online","off_delay":"3","pl_avail":"true","pl_not_avail":"false","uniq_id":"shelly1-gang_beneden-longpush-0","qos":"0","dev": {"ids": ["98F4ABF245F3"],"name":"Shelly1 gang_beneden","mdl":"Shelly1","sw":"20200206-083100/v1.5.10@e6a4205e","mf":"Allterco Robotics"},"~":"shellies/shelly1-gang_beneden/"}

Beside the Shelly1 as a light not working also my newly installed Duo bulb is not working. It is detected but the entity is unavailable.

Executing shellies_discovery.py: {'id': 'shellyduo-kelder', 'mac': '98F4ABD12E09', 'fw_ver': '20200129-155730/master@a18bfaec', 'shelly1-98F4ABF245F3-relay-0': 'light'}

Not sure why the shelly1 parameter is used for my duo bulb.

You’ve changed Shellies IDs. It’s not supported. IDs have to be default.

Hi Bienu,

Thank you for your reply. I didn’t change the ID of the shelly’s (not sure that is even possible) only the MQTT prefix. But if that is not supported that would explain everything. Thank you for the explanation.

It’s not default Shelly ID. Topics also have to be default.

Hi.

Is it possible to use plug S as a light switch ?

Tried this in config but it doesnt work.

shellyplugs-IDXXX-relay-0: ‘light’

It worked with shellyplug-s-IDXXX-relay-0: ‘light’

Thanks

1 Like

New version: 0.17.3

Changelog:

  • change template for external temperature sensor
  • add input binary_sensor for Shelly RGBW2
  • add energy and power sensors for Shelly DUO
  • add new sensors for Shelly 3EM

New version: 0.17.4

Changelog:

  • fix RGBW2 binary_sensors

I had a shelly dimmer working fine with this script, but now has come time to remove it from HA. First I disabled mqtt on the shelly, then I tried deleting the related messages using mqtt explorer. The problem is they come back after a few seconds of deleting. I also tried publishing blank payloads with retain to all the related topics, but they same result they keep showing up again after a few seconds. I added the lines to my automations then rebooted a few times to try and fix this:

        ignored_devices:
          - shellydimmer-XXXXXX

If I use the ui to delete the entities, they get deleted but I can’t remove the actual ‘device’ without deleting the whole mqtt integration. After rebooting, the deleted entities show up again. There has to be some simple step(s) I’m missing here. Any help is appreciated.

[edit: Just noticed those mqtt payloads were actually live, so looks like for whatever glitchy reason turning off mqtt on the shellydimmer didn’t stick until I rebooted it. After rebooting the dimmer, deleting the related payloads now seems to stick. Will report back if I fail to succeed from here…]

Unfortunately, there is no easy way to remove MQTT device from HA. After adding device to ignored_devices, restarting HA and removing entities from entity registry, the device will still be present in integrations.
I saw on GitHub PR which will add the ability to remove MQTT devices from integration. You have to wait for it.

Not sure if it helps anyone, but I was able to remove the device after the shelly reboot. The reboot made the mqtt messages stop, which allowed deleting the retained messages. After restarting HA, the now greyed out entities could be deleted from the gui. Then I had to edit my device registry file by deleting the json for the shellydimmer device. After rebooting, the device is now gone for good. I wish it was easier; editing device registry for one seems a bit hacky. Would be nice we could simply delete a device from the integration via the gui, and that takes care of removing the device and entities… wishful thinking. I’m curious to see what that PR does.

@Bieniu @truglodite
Has either of you tested Zigbee2MqttAssistant? According to the features list, it should be able to remove (with forced remove) mqtt entities.

I wanted to test it in the next time, but for now, I haven’t, so can’t say if it works. :slight_smile: