Shellies Discovery Script

Strange. I had a similar situation once, but didn’t have time to investigate it.

  • disable MQTT in the device webUI
  • remove device from HA (Integrations → MQTT → device screen → Remove)
  • restart HA (probably this step is not required but…)
  • configure the device with the core integration

@Bieniu Thanks for the info.
Will try the switch…

I have a few shelly plug s which are identified as switches. Now i want them to be identified as lights.

The entity is now: switch.shelly_plug_s_dcf4xx_relay_0

So in my automation i added:
‘’’
shelly_plug_s_dcf4xx:
relay-0: “light”
‘’’’
But it isnt recognised correctly, what do I miss?

Debug log for python script component.

how do i make a debug script for a python script?

Please read the documentation of the script.

You mean this logging?
2021-12-16 15:02:43 INFO (SyncWorker_1) [homeassistant.components.python_script] Executing shellies_discovery.py: {‘id’: ‘shellyplug-s-DCF4F7’, ‘mac’: ‘3C6105DCF4F7’, ‘fw_ver’: ‘20211109-130223/v1.11.7-g682a0db’, ‘model’: ‘SHPLG-S’, ‘mode’: ‘’, ‘shelly_1_b91c34’: {‘relay-0’: ‘light’}, ‘shelly_1_b96754’: {‘ext-temperature-0’: True, ‘relay-0’: ‘light’}, ‘shelly1_b96754’: {‘ext-temperature-0’: True, ‘relay-0’: ‘light’}, ‘shelly_plug_s_dcf4f7’: {‘relay-0’: ‘light’}}

This is a tiny tiny piece of log.

the log is big, but this is big part where the shelly is mentioned:
2021-12-16 21:00:32 INFO (SyncWorker_1) [homeassistant.components.python_script] Executing shellies_discovery.py: {‘id’: ‘shellyplug-s-DCF4F7’, ‘mac’: ‘3C6105DCF4F7’, ‘fw_ver’: ‘20211109-130223/v1.11.7-g682a0db’, ‘model’: ‘SHPLG-S’, ‘mode’: ‘’, ‘shelly_1_b91c34’: {‘relay-0’: ‘light’}, ‘shelly_1_b96754’: {‘ext-temperature-0’: True, ‘relay-0’: ‘light’}, ‘shelly1_b96754’: {‘ext-temperature-0’: True, ‘relay-0’: ‘light’}, ‘shelly_plug_s_dcf4f7’: {‘relay-0’: ‘light’}}

2021-12-16 21:00:32 DEBUG (SyncWorker_1) [homeassistant.components.python_script.shellies_discovery.py] id: shellyplug-s-DCF4F7, mac: 3c6105dcf4f7, fw_ver: 20211109-130223/v1.11.7-g682a0db, model: SHPLG-S

2021-12-16 21:00:32 DEBUG (SyncWorker_1) [homeassistant.components.python_script.shellies_discovery.py] {‘topic’: ‘homeassistant/button/shellyplug-s-DCF4F7-update_firmware/config’, ‘payload’: ‘{“name”: “Shelly Plug S DCF4F7 Update Firmware”, “cmd_t”: “~command”, “payload_press”: “update_fw”, “en”: “True”, “entity_category”: “config”, “avty_t”: “~online”, “pl_avail”: “true”, “pl_not_avail”: “false”, “uniq_id”: “shellyplug-s-dcf4f7-update_firmware”, “qos”: 0, “dev”: {“cns”: [[“mac”, “3c:61:05:dc:f4:f7”]], “name”: “Shelly Plug S DCF4F7”, “mdl”: “Shelly Plug S”, “sw”: “20211109-130223/v1.11.7-g682a0db”, “mf”: “Allterco Robotics”, “cu”: “http://None/”}, “~”: “shellies/shellyplug-s-DCF4F7/”, “dev_cla”: “update”}’, ‘retain’: True, ‘qos’: 0}

2021-12-16 21:00:32 DEBUG (SyncWorker_1) [homeassistant.components.python_script.shellies_discovery.py] Sending to MQTT broker: homeassistant/button/shellyplug-s-DCF4F7-update_firmware/config {‘name’: ‘Shelly Plug S DCF4F7 Update Firmware’, ‘cmd_t’: ‘~command’, ‘payload_press’: ‘update_fw’, ‘en’: ‘True’, ‘entity_category’: ‘config’, ‘avty_t’: ‘~online’, ‘pl_avail’: ‘true’, ‘pl_not_avail’: ‘false’, ‘uniq_id’: ‘shellyplug-s-dcf4f7-update_firmware’, ‘qos’: 0, ‘dev’: {‘cns’: [[‘mac’, ‘3c:61:05:dc:f4:f7’]], ‘name’: ‘Shelly Plug S DCF4F7’, ‘mdl’: ‘Shelly Plug S’, ‘sw’: ‘20211109-130223/v1.11.7-g682a0db’, ‘mf’: ‘Allterco Robotics’, ‘cu’: ‘http://None/’}, ‘~’: ‘shellies/shellyplug-s-DCF4F7/’, ‘dev_cla’: ‘update’}

2021-12-16 21:00:32 DEBUG (SyncWorker_1) [homeassistant.components.python_script.shellies_discovery.py] {‘topic’: ‘homeassistant/switch/shellyplug-s-DCF4F7-relay-0/config’, ‘payload’: ‘{“name”: “Shelly Plug S DCF4F7 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”: “shellyplug-s-dcf4f7-relay-0”, “qos”: 0, “dev”: {“cns”: [[“mac”, “3c:61:05:dc:f4:f7”]], “name”: “Shelly Plug S DCF4F7”, “mdl”: “Shelly Plug S”, “sw”: “20211109-130223/v1.11.7-g682a0db”, “mf”: “Allterco Robotics”, “cu”: “http://None/”}, “~”: “shellies/shellyplug-s-DCF4F7/”}’, ‘retain’: True, ‘qos’: 0}

2021-12-16 21:00:32 DEBUG (SyncWorker_1) [homeassistant.components.python_script.shellies_discovery.py] Sending to MQTT broker: homeassistant/switch/shellyplug-s-DCF4F7-relay-0/config {‘name’: ‘Shelly Plug S DCF4F7 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’: ‘shellyplug-s-dcf4f7-relay-0’, ‘qos’: 0, ‘dev’: {‘cns’: [[‘mac’, ‘3c:61:05:dc:f4:f7’]], ‘name’: ‘Shelly Plug S DCF4F7’, ‘mdl’: ‘Shelly Plug S’, ‘sw’: ‘20211109-130223/v1.11.7-g682a0db’, ‘mf’: ‘Allterco Robotics’, ‘cu’: ‘http://None/’}, ‘~’: ‘shellies/shellyplug-s-DCF4F7/’}

2021-12-16 21:00:32 DEBUG (SyncWorker_1) [homeassistant.components.python_script.shellies_discovery.py] {‘topic’: ‘homeassistant/light/shellyplug-s-DCF4F7-relay-0/config’, ‘payload’: ‘’, ‘retain’: True, ‘qos’: 0}

2021-12-16 21:00:32 DEBUG (SyncWorker_1) [homeassistant.components.python_script.shellies_discovery.py] Sending to MQTT broker: homeassistant/light/shellyplug-s-DCF4F7-relay-0/config

Do some one have a fork for shelly plus models?
I am trying to implement the plus models but my python skills are not the best one.

Kinda upgrade my house to new units and now i am stuck :frowning:

Hello Bieniu,
I really like the script, but would have a problem. There is a Shelly EM3 at home and after using the script, strange values appeared on the energy panel (before the script I used manual mqtt settings in the configure.yaml file, the data in Wm). The energy panel does not show only minimal power consumption and zero production (there is an 8 kWp solar panel on the roof). Today it shows a consumption of 0.43kWh, although the usual net 10-25 kWh (depending on the sun). I calculated a little afterwards and I think this may be due to the conversion of EM3 data (Wm / 60,000 → kWh).
Example 1: 299 Wm (data from EM3) divided by 60,000 and rounded to 2 decimal places, the result is 0.00! Without rounding: 0.004983333.
Example 2: 300 Wm (data from EM3) divided by 60,000 and rounded to 2 decimal places, the result is 0.01! Without rounding: 0.005.
Based on the EM3 data, the energy produced was zero, even though it did 5.6 kWh according to the inverter.
Is it really caused by rounding or something else? If rounding, how could it be corrected?
The attached pictures(unfortunately I can only attach two pictures, but there is no consumption in the third phase during this period) show that there is no consumption at dawn and early in the morning and there are 2 APs, 1 Raspberry PI, 1 high performance server, 2 switches, 1 router, 1 NAS + heating (boiler and pumps). Consumption is unlikely to reach 299 Wm per phase.

Happy New Year and thank you for your help!

Pictures:


I don’t have this device so I’m not sure but the rounding may be the reason.

I will not remove the rounding if you ask for it. What is your suggestion?

I can’t reproduce your issue.

Please update the script and automations.

This script will not support gen2 devices. I’ll create a new script for them but this will take some time.

Unfortunately, I’m still a beginner with Home Assistant, but I’ve seen in various conversations an example of creating a full consumption sensor by adding up the consumption of the 3 phases. For example, it would be possible to make 3-3 extra sensors without rounding for per-phase consumption and returned-energy.
I would try to see what happens without rounding, but I don’t know how to turn it off. I would be grateful if you could help me! Based on the results, you will be able to decide if you need to fix or add to the script.

I thought there would be a few lines in the script settings that would allow the user to control rounding (default is 2, but could be 3-8) and unit of measure (default is kWh, but could be Wh, Wm, kWm).

What do you think?

Hello

Any idea how to solve the goofy numbers in my solar results after restart HA please?
I know there are already some topics about the template availability. But I do not know how to solve this in the Shellies Discovery Script.

Thanks for helping

Marijn

Solve what? I don’t understand your question.

I think I can add an option for devices that force to use Wmin for energy sensors.

I have some issues with the utility meter when I reboot my HA.
My utility meter looks like this in my configuration.yml:

utility_meter:
  daily_solar_energy:
    name: Solar Total Energy Daily
    source: sensor.shelly_em_solar_meter_total_returned_0
    cycle: daily

It gives me a peak number when I want to check the Energy panel when I rebooted my HA.
I think there might be a problem described like here:

So a availability_template with a check on the is_state (as described in the article in te link) should resolve the problem (I hope). But I do not know how to the availability_template to the template of the sensor (for example: sensor.shelly_em_solar_meter_total_returned_0)

Any idea how to solve this please?

Thanks a lot

Marijn