Just tried this script with my shelly-plug.
Both the switch and the power-sensor is added as entities under MQTT integration, but I think the power-sensor is not subscribing to the correct state_topic.
Ever since I included it with the script instead of the manual config, I get state unknown for the sensor.
I am new to Python, so I am not fully following the syntax, but seems that you are making the sensor subscribe to the wrong topic. Correct topic would be:
shellies/shellyplug-7BD83C//relay/0/power.
It is missing the relay-number.
With the current script, the sensor subscribes to:
shellies/shellyplug-7BD83C/relay/power
If i publish to that topic, the sensor updates directly.
As mentioned, I have never worked with python, so not 100% sure on how to get the syntax correct. Could you please update it?
On a related topic, is there any way I can review what settings the entities were created with? I am not finding the config-entries anywhere in the files, so the troubleshooting was a bit more guesswork than would have been nessecary if I could have reviewed the entity topics manually.
Yes you are right. I only have Shelly2 and it send topic without relay number. I will correct the script. Does Shelly Plug send correct data in topic energy?
Hi
Energy is published in “shellies/shellyplug-XXXXXX/relay/0/energy”
with unit [10 * Wh] seems like a very strange energy-unit.
So if you do end up adding it, please convert it to kWh directly, seems confusing to use a non SI unit of 10Wh
Yes, I have read API documentation. Shelly2 for two relays sends power in one topic and doesn’t send energy at all because of issue in firmware. I thought that Shelly Plug and Shelly4Pro have the same issue.
@Flanders Please, write whether the sensors are working properly on the new version of the script. @elRadix Thanks for the configuration. Soon I will add support for ShellyH&T to the script.
I don’t understand What’s the benefit using this script… Shelly have already mqtt support by default in their fw.
Or with this script we can get more infos that i missed?
You add only the script and two automations to HA configuration, and each Shelly will be added to HA via MQTT Discovery with support for device registry and entity registry.
Hi!
Forgot to post feedback after testing yesterday, sorry.
Tested it, and works fine. Power sensor is added with correct topic and is now working.
The old non working power sensor is still there though. not sure if it was re-added, or if I failed to delete it completely.
The 2nd and 3rd I re-named and are the working ones, the first one is the sensor with the wrong topic that gets re-added even after deleting it in the entity-registry.
Send empty message to MQTT broker with topic shellies/shellyplug-7BD83C/relay/power and retain flag. You can use this command mosquitto_pub -h MQTT_BROKER_IP -p MQTT_BROKER_PORT -u MQTT_USER -P MQTT_PASSWORD -r -t 'shellies/shellyplug-7BD83C/relay/power' -m ''
Remove sensor entity from entity registry. You can do it manually from file .storage/core.entity_registry (not recomended) or from Entity Registry in frontend (Settings -> Entity Registry).
restart Home Assistant
What about energy sensor? Does it work correctly?
EDIT: I found stupid mistake in script with energy sensor.
Where to send that command?
Via SSH from the Hassio mashine?
Or in the command line for mosquitto?
The energy sensor is added, but I am getting the following error message in the log.
State unknown for the sensor aswell
Exception in message_received when handling msg on ‘shellies/shellyplug-7BD83C/relay/0/energy’: ‘580’
Traceback (most recent call last):
File “/usr/local/lib/python3.7/site-packages/homeassistant/components/mqtt/sensor.py”, line 170, in message_received
payload, self._state)
File “/usr/local/lib/python3.7/site-packages/homeassistant/helpers/template.py”, line 174, in async_render_with_possible_json_value
return self._compiled.render(variables).strip()
File “/usr/local/lib/python3.7/site-packages/jinja2/asyncsupport.py”, line 76, in render
return original_render(self, *args, **kwargs)
File “/usr/local/lib/python3.7/site-packages/jinja2/environment.py”, line 1008, in render
return self.environment.handle_exception(exc_info, True)
File “/usr/local/lib/python3.7/site-packages/jinja2/environment.py”, line 780, in handle_exception
reraise(exc_type, exc_value, tb)
File “/usr/local/lib/python3.7/site-packages/jinja2/_compat.py”, line 37, in reraise
raise value.with_traceback(tb)
File “”, line 1, in top-level template code
TypeError: unsupported operand type(s) for /: ‘str’ and ‘int’