Shellies Discovery Gen2 Script

This script adds MQTT discovery support for Shelly Gen2 (Pro/Plus) devices.

Supported devices

  • Shelly Plus 1
  • Shelly Plus 1PM
  • Shelly Plus 2PM
  • Shelly Plus i4
  • Shelly Pro 1
  • Shelly Pro 1PM
  • Shelly Pro 2
  • Shelly Pro 2PM
  • Shelly Pro 4PM

Repository: https://github.com/bieniu/ha-shellies-discovery-gen2

Documentation: https://github.com/bieniu/ha-shellies-discovery-gen2/blob/master/README.md

Buy Me A Coffee

1 Like

Version 0.4.0

Downloads for this release

What’s Changed

Full Changelog: Comparing 0.3.0...0.4.0 ¡ bieniu/ha-shellies-discovery-gen2 ¡ GitHub

Information

Currently, the script is available in HACS.

Hi Bieniu,

Just for clarification purpose, this script is for the Shelly Gen2 device listed, so I understand if you have already the “Gen1” version of your script for older items, one will also need to install this one. (I am not done yet)

Will you at some point merge the 2 scripts ? (less maintenance, more newcomer friendly)

If you want to use gen2 devices you have to install this script but if you have only gen1 devices, you don’t need this.

No

Hi there! first of all thanks for taking the time and creating this. I’m a satisfied user of your gen1 script. And as i also bought a number of plus devices (Gen2) I would love to use this script also and be able to make full use of mqtt as i’m used to.

But I seem to be doing something wrong or i’m missing some info. I have the Gen2 running via HACS automations. But now i’m a bit lost with the minimal configuration required. The automations.yaml listed on your repository does not work when copy/paste. I do notice some ‘generic’ device id’s but do I need to use my own device id’s and create a entry for each device? and the status script example has a topic and payload that mismatches. topic = shellyplus1pm and payload = shellypro4pm.
So i’m a bit confused about what i need to do with the automation.yaml.

As with gen1 script I could just copy the entire script and it worked, but now I think i need to do more but not sure what.

Thanks!

Yes, you have to use your device ID in automations. I’m thinking of simplifying this.

Hi,
in case if someone getting error:

2022-02-08 02:36:45 ERROR (SyncWorker_6) [homeassistant.components.python_script.shellies_discovery_gen2.py] Error executing script: 'consumption_types'
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/python_script/__init__.py", line 224, in execute
    exec(compiled.code, restricted_globals)
  File "shellies_discovery_gen2.py", line 933, in <module>
  File "shellies_discovery_gen2.py", line 820, in configure_device
  File "/usr/local/lib/python3.9/site-packages/RestrictedPython/Eval.py", line 35, in default_guarded_getitem
    return ob[index]
KeyError: 'consumption_types'

The consumption type must be set!

Fixed https://github.com/bieniu/ha-shellies-discovery-gen2/releases/tag/1.0.1

1 Like

Version 1.1.0

Downloads for this release

What’s Changed

Full Changelog: https://github.com/bieniu/ha-shellies-discovery-gen2/compare/1.0.1...1.1.0

Version 1.1.2

Downloads for this release

What’s Changed

Full Changelog: https://github.com/bieniu/ha-shellies-discovery-gen2/compare/1.1.1...1.1.2

So if i understand correct. I need to change:

topic: "shellyplus1pm-112233445566/rpc"  # shellyplus1pm-112233445566 is a device ID

To:

topic: "44179393E8BC/rpc"  # As that is my device Id listed on the bottom webpage of the shelly plus 1 pm. 

And the same for:

    data:
      topic: shellyplus1pm-112233445566/rpc
      payload: "{{ {'id': 1, 'src':'shellyplus1pm-112233445566/status', 'method':'Shelly.GetStatus'} | to_json }}"  # shellyplus1pm-112233445566 is a device ID

that becomes:

    data:
      topic: shellyplus1pm-44179393e8bc/rpc #topic checked with MQTT Explorer
      payload: "{{ {'id': 1, 'src':'44179393E8BC/status', 'method':'Shelly.GetStatus'} | to_json }}"  #My own device ID

And how come this customization was not needed with the Gen1 script? Why do we need to add all device id’s manually?

Thanks!

No, 44179393E8BC is a device MAC address, ID is <MODEL>-<MAC>.

Gen1 devices support announce command, gen2 devices don’t.

Thanks for the help and all the effort you put into this.
I got it working, but its a shame they did not add a announce command with the gen2.

Hi, I’m just wondering how I could use this to get a trigger from an i4 input?

You can use device automations (if input type is button):

or binary sensor will be created if input type is switch.

Thanks…

I don’t tend to use automations within home assistant I run them through node red so didn’t even look at that.

I don’t quite understand your script also detects shelly plus 2pm set as cover?
Edit: Stupid me, I just read the changelog, thank you.

1 Like

Hi,

I’m using both Shellies Discovery Gen1 and Gen2.
I started to use Gen2 with one Shelly Plus 1. It is working fine but before some update (don’t know if HA updates or the Shellies Discovery script) the switch type in home assistant was a toggle switch, but now is two buttons for ON and OFF. I also added another one and it’s the same, in Button type or Switch type in the Shellies Website doesn’t change anything.

In the attached picture is one light with a Shelly 1PM that is controlled as a switch, and the other two are the Shelly Plus 1.

Any idea how to set those as a switch in HA?

Thanks!

Screenshot

1 Like

Hi,

And thank you for your valuable work!

I installed the gen2 discovery script now (I have the gen1 script already installed) and copied the minimal configuration to ‘Automations.yaml’ + changed the ID to the ones of my two Shelly Plus 1PM. The two units do not show up under “Entities” in HA though.
The Shellies are communicating over MQTT (checked with analyzer) but simply do not connect to HA.
In the logbook, I noticed that the “Shellies Discovery gen2” is not triggered automatically in the same way as the “Shellies Discovery” (gen1). I tried to trigger manually, but nothing happened. What can possibly be the issue?

BR,

Simon

Further to the above mentioned, I found this error in the log also

Error executing script: ‘name’

Traceback (most recent call last): File “/usr/src/homeassistant/homeassistant/components/python_script/init.py”, line 222, in execute exec(compiled.code, restricted_globals) File “shellies_discovery_gen2.py”, line 1096, in File “/usr/local/lib/python3.9/site-packages/RestrictedPython/Eval.py”, line 35, in default_guarded_getitem return ob[index] KeyError: ‘name’