Shellies Discovery Script

Thanks @Bieniu, changing from hass to homeassistant for the discovery prefix fixed the problem. Don’t know how I missed it, but you might change it in your example automation to match the default.

I will check with Shelly support as to why the MAC doesn’t match the reported MAC

Hello @Bieniu and thanks for this beautiful script !

I’m trying to use it with my Shelly HT , and i feel like i’m not far from succeed but I don’t know what i’m missing.

I’m using embeded MQTT on home assistant on docker, i’m receiving well MQTT messages from my shelly , but no entity are created, do you know what I should watch next ?

thanks in advance

Best regards,

Do you use correct automation to run the script? In your topics thera aren’t MAC addresses and firmware versions.

- 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 }}'

Hello, thanks for your answer !

I have put this in the automations.yaml file

image

You have to write me full announce topic that your Shelly send to MQTT broker.

Thanks again for your answer, sorry i’m a bit new to MQTT.

From what I understand I need to subscribe with a MQTT client to directly read the shellies topic, right ?

my MQTT server isn’t exposed from outside so I can’t use an MQTT client right now, i’ll try tonight at home.

The only thing I can provide right now is the HA logs, where just before the “Transmitting messages” the MQTT component is logging the received message, which seems not that much verbose :

Regards,

Very strange. This isn’t correct payload for Shelly announce topic. This is example of correct payload:

{"id":"shellyht-XXXXXX","mac":"XXXXXXXXXXXX","ip":"192.168.1.56","new_fw":false, "fw_ver":"20190402-134544/v1.4.9@9be72c7e"}

Without that my script doesn’t work.
Maybe factory reset helps?

Yeah, mine feels a bit truncated :rofl:

I’ll try to maybe update my firmware and/or factory reset as suggested .
I’ll tell you result tonight !

Thanks for your advices !

So, I have updated the Shelly HT firmware, it seems better , but still no entities showing
There is one error showing 10 sec after your python script is processed , don’t know if it’s related :

Regards,

Now it looks good. Are you sure that there isn’t Shelly H&T in Settings -> Integrations -> MQTT in HA?
Please use text logs in post.

New version: 0.4.2

Changelog:

  • add energy sensor for Shelly2 (firmware 20190410-133926/v1.4.9-hotfix2@4e3bf27e or never)
  • fix detection of incorrect shelly/announce payload

I’m sure yes, there is no entities :

Are there any MQTT or Discovery errors in log associated? I can’t help if I don’t know where the problem is. You use the built-in MQTT broker. Have you considered installing the Mosquitto? The built-in broker has issues and will soon be removed from HA.

Hello again,

I installed mosquitto and had the same behaviour

I finally got it working, it was much more simple than I thought, I think this is basic for MQTT users, but for begginers like me it was not obvious. Maybe this should be written in your prerequierements :

Don’t use GUI MQTT configuration, configure MQTT in yaml file to put the discovery variable to true :

mqtt:
broker: 192.168.xxx.xx
port: 1883
username: xxxxx
password: xxxxx
discovery: true
discovery_prefix: homeassistant

This is what was missing for me for this to work :

discovery: true
discovery_prefix: homeassistant

Now I have another issue with the auto discover script. Even with the retain label on, sensors are getting unavailable in HA. I tried to create the sensor manually in the configuration.yaml and I don’t have this issue (left sensors auto discovered with your script, right manual with configuration.yaml) :

Here is my yaml :

platform: mqtt
name: "Humiditée Chambre"
state_topic: "shellies/shellyht-58FA2E/sensor/humidity"
unit_of_measurement: '%'
expire_after: 86400
force_update: true
json_attributes_topic: "shellies/shellyht-58FA2E/sensor/humidity"

Regards,

Do I understand correctly that the graph for the sensor is drawn but the state is unvailable? ShellyH&T connects to the network only from time to time and that is why most of the time is unavailable.

New version: 0.4.3

Changelog:

  • remove availability topic for Shelly H&T
1 Like

yes correct, Shelly HT comes only online every 4 or 5 hours or when the temperature exceeds the preset value.

New version: 0.4.4

Changelog:

  • fix unit conversion for energy sensors

New version: 0.5.0

Changelog:

  • add support for Shelly2.5 (experimental - there is no official information about Shelly2.5 on API documentation page)

New version: 0.5.1

Changelog:

  • once again fix unit conversion for energy sensors (with firmware 1.4.9 Shellies send energy in Watt-minutes)