Shellies Discovery Script

I have a bunch of shelly door/window 2 - I often get them go unavailable when I have them set up by the discovery script see below - they kick back in if I open / Clsoe them but it is really buggin me :slight_smile: My manual MQTT setup ones don’t do this anyone got any ideas as this is soooo much eaier than manual setup!

TIA

Stuart

" Was closed

15:44:02 - 36 minutes ago

Was opened

15:43:03 - 37 minutes ago

Was closed

15:29:39 - 50 minutes ago

Became unavailable

5:33:21 - 11 hours ago

9 October 2020

Was closed

17:33:21 - 23 hours ago"

but with my manual mqtt

Change expire_after for this device.

So looking here - https://github.com/bieniu/ha-shellies-discovery

Do I need to manually edit the shellies discovery automation for each device - (I have about 40!)

OR would it be possible to have some sort of catch all with a *

shellydw2*:
expire_after: “??” <-- What should I use here some windows aren’t open for weeks - can we set it to never expire?

Many thanks for such a fab script and your advice.

Warm Regards

Stuart

Yes, every device has own configuration.

I use 1,5 * sleep_mode.period (you can check device sleep_mode.period via rest /settings)

@Bieniu How to reset shelly 1 correctly?

I think via www panel.

@Bieniu: In 0.31.1 you removed the SENSOR_GAS in line 793 for shelly gas sensor. The class definition in line 802 should be also removed. Otherwise there will be errors.

1 Like

Since I upgraded my home assistant to 0.115, my shelly devices are unavailable after a reboot. I have one shelly 2.5 configured manually, which works fine. So I’m starting to think it may be this discovery script.

So I updated the python script, but unfortunately one of my shelly devices refuses to update to the latest firmware. This results in an error from the discovery script. It would be better if the discovery script would just skip this device and go on with the next?

1 Like

The script works separately for each device, so an exception for one device does not affect the other device.

First of all, thank you for all the hard work! 4 shellies connected easy and fast to my Home Assistant mosquitto broker with the help of your Discovery script. I have updated al my shellies to the latest firmware and reinstalled Home Assistand. Unfortunately only 1 shelly (2.5 relay) won’t show up in MQTT devices and I can’t find out why. Try everything to my knowledge.

I checked it first with MQTT explorer connected to my Home Assistant Mosquitto broker, fire the Announce script and it shows the missing Shelly under ‘shellies’. Still won’t appear in Home Assistant, not in devices or entities

Enable debug logger and and in the logs the missing shelly announce topic wil appear:

2020-10-19 19:40:08 DEBUG (MainThread) [homeassistant.components.mqtt] Received message on shellies/announce: b'{"id":"Shelly-hal-voordeur","model":"SHSW-25","mac":"E098069598C5","ip":"192.168.40.53","new_fw":false,"fw_ver":"20200827-065456/v1.8.3@4a8bc427"}'
2020-10-19 19:40:08 WARNING (MainThread) [homeassistant.components.automation.shellies_discovery] SHELLIES | Discovery: Already running


However it won’t appear in my home assistant Devices or > Configuration > Integrations > MQTT

Try to manually add the missing shelly MQTT in configuration.yaml and it works. However, in this way it will no longer be registered as a device. What could be the reason why the shelly does show announce topic in the MQTT debug logging but is not added?

Show me please debug log for python_script https://github.com/bieniu/ha-shellies-discovery#how-to-debug

Wait, you have warning already running. Are you sure your shrllies_discovery automation has those lines:

mode: queued
max: 999

I run announce and this is the python_script debug log output:

2020-10-19 20:06:17 INFO (SyncWorker_17) [homeassistant.components.python_script] Executing shellies_discovery.py: {'fw_ver': '20200827-065456/v1.8.3@4a8bc427', 'id': 'ShellyHalVoordeur', 'mac': 'E098069598C5'}
2020-10-19 20:06:17 DEBUG (SyncWorker_17) [homeassistant.components.python_script.shellies_discovery.py] id: ShellyHalVoordeur, mac: e098069598c5, fw_ver: 20200827-065456/v1.8.3@4a8bc427, model: None

Now i see model: None. These are the last logs.

Within MQTT Explorer, announce topic shows:

{
  "id": "ShellyHalVoordeur",
  "model": "SHSW-25",
  "mac": "E098069598C5",
  "ip": "192.168.40.53",
  "new_fw": false,
  "fw_ver": "20200827-065456/v1.8.3@4a8bc427"
}

Update: I have installed Shelly Discovery true HACS, so i did nothing to the shellies_discovery.py script

Update2: One of my other Shelly who is added succesfully is also showing model:None . However, there is more input afther the announce what is missing with my Shelly2.5 announce:

Succesfully added shelly

DEBUG (SyncWorker_5) [homeassistant.components.python_script.shellies_discovery.py] id: ShellyBulbDuo-woonkamerTV, mac: bcddc2663eea, fw_ver: 20200827-065050/v1.8.3@4a8bc427, model: None
2020-10-19 20:04:32 DEBUG (SyncWorker_5) [homeassistant.components.python_script.shellies_discovery.py] Sending to MQTT broker: homeassistant/sensor/ShellyBulbDuo-woonkamerTV-rssi/config {"name": "Shelly DUO woonkamerTV RSSI", "stat_t": "~info", "frc_upd": "False", "uniq_id": "shellybulbduo-woonkamertv-rssi", "qos": 0, "dev": {"ids": ["bcddc2663eea"], "name": "Shelly DUO woonkamerTV", "mdl": "Shelly DUO", "sw": "20200827-065050/v1.8.3@4a8bc427", "mf": "Allterco Robotics"}, "~": "shellies/ShellyBulbDuo-woonkamerTV/", "unit_of_meas": "dB", "dev_cla": "signal_strength", "val_tpl": "{{value_json['wifi_sta'].rssi}}", "avty_t": "~online", "pl_avail": "true", "pl_not_avail": "false"}

It seems to me that your automations aren’t up to date.

You mean the shelly Discovery / Announce automation?
Installed yesterday via HACS.

How can I verify it?

Compare withe those from the docs https://github.com/bieniu/ha-shellies-discovery#minimal-configuration

You are a legend!!!

2020-10-19 20:38:30 INFO (SyncWorker_53) [homeassistant.components.python_script] Executing shellies_discovery.py: {'id': 'ShellyHalVoordeur', 'mac': 'E098069598C5', 'fw_ver': '20200827-065456/v1.8.3@4a8bc427', 'model': 'SHSW-25'}
2020-10-19 20:38:30 DEBUG (SyncWorker_53) [homeassistant.components.python_script.shellies_discovery.py] id: ShellyHalVoordeur, mac: e098069598c5, fw_ver: 20200827-065456/v1.8.3@4a8bc427, model: SHSW-25
1 Like

Hello Bieniu,

I don’t know if this problem lies with this script but after updating HA to 0.117.0 I have a problem with the status of 1 shelly. This is an existing shelly bulp that has worked perfectly.

I have deleted the shelly from MQTT devices and re-announce it but that won’t fix it. When i execute the announce script the latest state wil be updated in HA but I still can’t turn on the light. The following error wil be shown in the error log when i’m trying to switch it to on. Shelly bulp also works fine through its own interface. If I turn the lamp on or off there, I don’t see the status in HA either.

Logger: homeassistant.util.logging
Source: util/logging.py:108
First occurred: 2:05:36 PM (72 occurrences)
Last logged: 2:41:46 PM

Exception in state_received when handling msg on 'shellies/Shelly-woonkamerTV/light/0/status': '{"ison":true,"has_timer":false,"timer_started":0,"timer_duration":0,"timer_remaining":0,"brightness":46,"white":0,"temp":2702}' Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/components/mqtt/debug_info.py", line 35, in wrapper msg_callback(msg) File "/usr/src/homeassistant/homeassistant/components/mqtt/light/schema_template.py", line 258, in state_received self._templates[ AttributeError: 'NoneType' object has no attribute 'async_render_with_possible_json_value'
Exception in state_received when handling msg on 'shellies/Shelly-woonkamerTV/light/0/status': '{"ison":false,"has_timer":false,"timer_started":0,"timer_duration":0,"timer_remaining":0,"brightness":46,"white":0,"temp":2702}' Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/components/mqtt/debug_info.py", line 35, in wrapper msg_callback(msg) File "/usr/src/homeassistant/homeassistant/components/mqtt/light/schema_template.py", line 258, in state_received self._templates[ AttributeError: 'NoneType' object has no attribute 'async_render_with_possible_json_value'

Debug log

Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/components/mqtt/debug_info.py", line 35, in wrapper
msg_callback(msg)
File "/usr/src/homeassistant/homeassistant/components/mqtt/light/schema_template.py", line 258, in state_received
self._templates[
AttributeError: 'NoneType' object has no attribute 'async_render_with_possible_json_value'
2020-10-29 14:48:59 ERROR (MainThread) [homeassistant.util.logging] Exception in state_received when handling msg on 'shellies/Shelly-woonkamerTV/light/0/status': '{"ison":false,"has_timer":false,"timer_started":0,"timer_duration":0,"timer_remaining":0,"brightness":46,"white":0,"temp":2702}'
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/components/mqtt/debug_info.py", line 35, in wrapper
msg_callback(msg)
File "/usr/src/homeassistant/homeassistant/components/mqtt/light/schema_template.py", line 258, in state_received
self._templates[
AttributeError: 'NoneType' object has no attribute 'async_render_with_possible_json_value'
2020-10-29 14:49:14 ERROR (MainThread) [homeassistant.util.logging] Exception in state_received when handling msg on 'shellies/Shelly-woonkamerTV/light/0/status': '{"ison":true,"has_timer":false,"timer_started":0,"timer_duration":0,"timer_remaining":0,"brightness":2,"white":0,"temp":2702}'
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/components/mqtt/debug_info.py", line 35, in wrapper
msg_callback(msg)
File "/usr/src/homeassistant/homeassistant/components/mqtt/light/schema_template.py", line 258, in state_received
self._templates[
AttributeError: 'NoneType' object has no attribute 'async_render_with_possible_json_value'
2020-10-29 14:49:14 ERROR (MainThread) [homeassistant.util.logging] Exception in state_received when handling msg on 'shellies/Shelly-woonkamerTV/light/0/status': '{"ison":true,"has_timer":false,"timer_started":0,"timer_duration":0,"timer_remaining":0,"brightness":46,"white":0,"temp":2702}'
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/components/mqtt/debug_info.py", line 35, in wrapper
msg_callback(msg)
File "/usr/src/homeassistant/homeassistant/components/mqtt/light/schema_template.py", line 258, in state_received
self._templates[
AttributeError: 'NoneType' object has no attribute 'async_render_with_possible_json_value'

And the announce logging of this specific device:

2020-10-29 14:48:01 INFO (MainThread) [homeassistant.components.automation.shellies_discovery] Shellies Discovery: Running automation actions
2020-10-29 14:48:01 INFO (MainThread) [homeassistant.components.automation.shellies_discovery] Shellies Discovery: Executing step call service
2020-10-29 14:48:02 INFO (SyncWorker_30) [homeassistant.components.python_script] Executing shellies_discovery.py: {'id': 'Shelly-woonkamerTV', 'mac': 'BCDDC2663EEA', 'fw_ver': '20200827-065050/v1.8.3@4a8bc427', 'model': 'SHBDUO-1'}
2020-10-29 14:48:02 DEBUG (SyncWorker_30) [homeassistant.components.python_script.shellies_discovery.py] id: Shelly-woonkamerTV, mac: bcddc2663eea, fw_ver: 20200827-065050/v1.8.3@4a8bc427, model: SHBDUO-1
2020-10-29 14:48:02 DEBUG (SyncWorker_30) [homeassistant.components.python_script.shellies_discovery.py] Sending to MQTT broker: homeassistant/sensor/Shelly-woonkamerTV-rssi/config {"name": "Shelly DUO woonkamerTV RSSI", "stat_t": "~info", "frc_upd": "False", "uniq_id": "shelly-woonkamertv-rssi", "qos": 0, "dev": {"ids": ["bcddc2663eea"], "name": "Shelly DUO woonkamerTV", "mdl": "Shelly DUO", "sw": "20200827-065050/v1.8.3@4a8bc427", "mf": "Allterco Robotics"}, "~": "shellies/Shelly-woonkamerTV/", "unit_of_meas": "dB", "dev_cla": "signal_strength", "val_tpl": "{{value_json['wifi_sta'].rssi}}", "avty_t": "~online", "pl_avail": "true", "pl_not_avail": "false"}
2020-10-29 14:48:02 DEBUG (SyncWorker_30) [homeassistant.components.python_script.shellies_discovery.py] Sending to MQTT broker: homeassistant/sensor/Shelly-woonkamerTV-ssid/config {"name": "Shelly DUO woonkamerTV SSID", "stat_t": "~info", "frc_upd": "False", "uniq_id": "shelly-woonkamertv-ssid", "qos": 0, "dev": {"ids": ["bcddc2663eea"], "name": "Shelly DUO woonkamerTV", "mdl": "Shelly DUO", "sw": "20200827-065050/v1.8.3@4a8bc427", "mf": "Allterco Robotics"}, "~": "shellies/Shelly-woonkamerTV/", "val_tpl": "{{value_json['wifi_sta'].ssid}}", "icon": "mdi:wifi", "avty_t": "~online", "pl_avail": "true", "pl_not_avail": "false"}
2020-10-29 14:48:02 DEBUG (SyncWorker_30) [homeassistant.components.python_script.shellies_discovery.py] Sending to MQTT broker: homeassistant/sensor/Shelly-woonkamerTV-uptime/config {"name": "Shelly DUO woonkamerTV Uptime", "stat_t": "~info", "frc_upd": "False", "uniq_id": "shelly-woonkamertv-uptime", "qos": 0, "dev": {"ids": ["bcddc2663eea"], "name": "Shelly DUO woonkamerTV", "mdl": "Shelly DUO", "sw": "20200827-065050/v1.8.3@4a8bc427", "mf": "Allterco Robotics"}, "~": "shellies/Shelly-woonkamerTV/", "dev_cla": "timestamp", "val_tpl": "{{(as_timestamp(now())-value_json.uptime)|timestamp_local}}", "icon": "mdi:timer-outline", "avty_t": "~online", "pl_avail": "true", "pl_not_avail": "false"}
2020-10-29 14:48:02 DEBUG (SyncWorker_30) [homeassistant.components.python_script.shellies_discovery.py] Sending to MQTT broker: homeassistant/binary_sensor/Shelly-woonkamerTV-firmware-update/config {"name": "Shelly DUO woonkamerTV Firmware Update", "stat_t": "~info", "uniq_id": "shelly-woonkamertv-firmware-update", "qos": 0, "dev": {"ids": ["bcddc2663eea"], "name": "Shelly DUO woonkamerTV", "mdl": "Shelly DUO", "sw": "20200827-065050/v1.8.3@4a8bc427", "mf": "Allterco Robotics"}, "~": "shellies/Shelly-woonkamerTV/", "val_tpl": "{%if value_json['update'].has_update==true%}ON{%else%}OFF{%endif%}", "avty_t": "~online", "pl_avail": "true", "pl_not_avail": "false", "json_attr_t": "~info", "json_attr_tpl": "{{value_json['update']|tojson}}"}
2020-10-29 14:48:02 DEBUG (SyncWorker_30) [homeassistant.components.python_script.shellies_discovery.py] Sending to MQTT broker: homeassistant/light/Shelly-woonkamerTV-0/config {"schema":"template","name":"Shelly DUO woonkamerTV Light 0","cmd_t":"~light/0/set","stat_t":"~light/0/status","avty_t":"~online","pl_avail":"true","pl_not_avail":"false","cmd_on_tpl":"{\"turn\":\"on\"{%if brightness is defined%},\"brightness\":{{brightness|float|multiply(0.3922)|round}}{%endif%}{%if color_temp is defined%},\"temp\":{{(1000000/(color_temp|int))|round(0,\"floor\")}}{%endif%}}","cmd_off_tpl":"{\"turn\":\"off\"}","stat_tpl":"{%if value_json.ison%}on{%else%}off{%endif%}","bri_tpl":"{{value_json.brightness|float|multiply(2.55)|round}}","clr_temp_tpl":"{{((1000000/(value_json.temp|int,2700)|max)|round(0,\"floor\"))}}","max_mireds":370,"min_mireds":153,"uniq_id":"shelly-woonkamertv-light-0","qos":"0","dev": {"ids": ["bcddc2663eea"],"name":"Shelly DUO woonkamerTV","mdl":"Shelly DUO","sw":"20200827-065050/v1.8.3@4a8bc427","mf":"Allterco Robotics"},"~":"shellies/Shelly-woonkamerTV/"}
2020-10-29 14:48:02 DEBUG (SyncWorker_30) [homeassistant.components.python_script.shellies_discovery.py] Sending to MQTT broker: homeassistant/sensor/Shelly-woonkamerTV-white-energy-0/config {"name": "Shelly DUO woonkamerTV Energy 0", "stat_t": "~light/0/energy", "unit_of_meas": "kWh", "val_tpl": "{{(value|float/60/1000)|round(2)}}", "dev_cla": "energy", "avty_t": "~online", "pl_avail": "true", "pl_not_avail": "false", "frc_upd": "False", "uniq_id": "shelly-woonkamertv-white-energy-0", "qos": 0, "dev": {"ids": ["bcddc2663eea"], "name": "Shelly DUO woonkamerTV", "mdl": "Shelly DUO", "sw": "20200827-065050/v1.8.3@4a8bc427", "mf": "Allterco Robotics"}, "~": "shellies/Shelly-woonkamerTV/"}
2020-10-29 14:48:02 DEBUG (SyncWorker_30) [homeassistant.components.python_script.shellies_discovery.py] Sending to MQTT broker: homeassistant/sensor/Shelly-woonkamerTV-white-power-0/config {"name": "Shelly DUO woonkamerTV Power 0", "stat_t": "~light/0/power", "unit_of_meas": "W", "val_tpl": "{{value|float|round(1)}}", "dev_cla": "power", "avty_t": "~online", "pl_avail": "true", "pl_not_avail": "false", "frc_upd": "False", "uniq_id": "shelly-woonkamertv-white-power-0", "qos": 0, "dev": {"ids": ["bcddc2663eea"], "name": "Shelly DUO woonkamerTV", "mdl": "Shelly DUO", "sw": "20200827-065050/v1.8.3@4a8bc427", "mf": "Allterco Robotics"}, "~": "shellies/Shelly-woonkamerTV/"}

In my opinion this is HA issue.

1 Like

Thanks again! Fixed now in 0.117.1, just released.

1 Like

I tried to update from shellies_discovery.py from the April 24 version.

It seems that with the last versions the unique_id created for HA is now in lower case
unique_id = f"...".lower()
when from the 24 April version it was not.

I intensively used UI renaming to change shelly entities name and all my entities are now back to their default name.
Do you know a way, a trick to migrate elegantly ?