Shellies Discovery Script

But HT sends info topic periodically

I asked Shelly devs about DW/DW2 and info topic, I’ll let you know what they replied.

Thanks a lot!

I wonder if there was a setting in the device itself on how often to update unter power saving options or something - i can check that later.

Also i wonder why it doesnt populate the RSSI sensor for my HT device. i just deleted the device in HA and rebootet both HA and the deivce multiple times, but the RSSI sensor isnt created. must be my fault.

Sorry, I forgot that rssi sensor is created for AC powered devices only, my HT uses USB adapter ha-shellies-discovery/python_scripts/shellies_discovery.py at 5f51161260bacdbe9405f53f12a05de05540c6ad · bieniu/ha-shellies-discovery · GitHub

Ah thx for the hint! I changed that and also found the part where i can insert so it adds the sensor for RSSI in the DW devices.:

if model_id == MODEL_SHELLYDW2_ID or dev_id_prefix == MODEL_SHELLYDW2_PREFIX:
    model = MODEL_SHELLYDW2

    sensors = {
        SENSOR_BATTERY: OPTIONS_SENSOR_BATTERY,
        SENSOR_IP: OPTIONS_SENSOR_IP,
        SENSOR_RSSI: OPTIONS_SENSOR_RSSI, # line added, Malte
        SENSOR_SSID: OPTIONS_SENSOR_SSID, # line added, Malte
        SENSOR_LUX: OPTIONS_SENSOR_LUX,
        SENSOR_TILT: OPTIONS_SENSOR_TILT,
        SENSOR_TEMPERATURE: OPTIONS_SENSOR_TEMPERATURE,
        SENSOR_TEMPERATURE_F: OPTIONS_SENSOR_TEMPERATURE_F,
    }

got rssi on both HT with battery and DWs working now - i guess i have to tinker on my own fork then if i want to keep getting updates for your code. I like the structure of your code - its well readable with all the global defines.

How often do you get rssi state from battery powered HT?

edit:
oh, you where asking about the rssi - im confused :slight_smile:
and ive reached the smamming maximmmum of 6 posts for the first day with the account i was told :slight_smile:

edit: i cant create any more posts today so i can just edit this old one. the code you posted below works for both HT with bat and DW2. Bot have the Wifi Signal fields as optional sensors.:


the battery level on this particular hardware (red circles) is bugged. i believe its a hardwaree fault. has been like that before where others work.

Please test this Release Version 0.44.7b0 · bieniu/ha-shellies-discovery · GitHub

Yo, not sure if you read the above, that new code is working and is integrating the wifi rssi sensor for both DW2 and HT with bat for me - if i got that right, as sometimes just deleting a device seems to leave some remnants for me.

Hey. Ive got a question that is not related directly to your script, but to the technical things behind it and i thought maybe you are able to help.

So i have a device created via the mqtt protocoll by your script and did set qos: 2 in automations.yaml. I created an “entities card” card on the HA dashboard and added one relay of the shelly device to it. There is just a light bulb connected to it and i want to switch that on and off using the dashboard.


To my understanding the “device” and its “entities” in HA are a higher order layer and by the configuration your script did perform HA knows, that mqtt with certain parameters (like topic names and names for the payload content) is to be used to communicate with that entities. From the HA users point of view the entitie is thus generalized in such a way, that interacting with an entity doesnt need to known if mqtt or something else is the unterliing communication protocoll.

Now the problem is, that the shelly is in an area where there is weak wifi coverage and the state of the device is shown as “unavailable” at times. When the state is unavailable the GUI element in the HA dashboard is greyed out and i cant click the slider. What i would exspect however is, that i can click the slider, but the relay doesnt react as its not reachable via wifi. Instead i would exspect, due to the qos: 2 and mqtt protocoll, that i can click the slider and this will que up a message saved on some stack of the mqtt broker. the mqtt broker will then try to deliever that message over and over again until it finally succeeds at some point.

is my understanding in principle correct?

so do i need to use some other interface instead of “entity” on “entities card” on the HA dashboard to maybe directly create an MQTT message, instead of having to rely on HAs higher level “entity” wrapper around it, or do i need to create the device via your script using some different settings so it “retains” the last known state and i can que up messages even if the device is unavailable?

what i could do is create an “input_button” in configuration.yaml and in node red have an mqtt message send, whenever that button is clicked. that would do the above, BUT then i loose the functionality of having the state of the relay beeing displayed in the dashboard.

sorry for the wall of text. this is a principle understanding problem of how the different things are interconnected here for me and it would help me greatly to understand that in general to also account for that in more complex code involving the HA “entities” in things like node-red where i already wrote my own “ACK” checks for network stability, but i get the feeling im “doing it wrong”.

All AC powered devices are configured with availability and because of this if the device is offline/disconnected their entities will be unavailable.

You can try with manually configured MQTT switch without availability and retained topic.

ah interesting. thank you very much. i didnt know “availability” was a thing.

im slowly getting there. the way youre code creates the devices is realy much more organized and thought through than the custom mess i was initially dealing with. it starts to make sense to me why you did it that way. there are realy many ways to define the damn device (i.e. switch or light) and most of them leed to pitfalls which are then tidious to correct (i.e. heaps of dead crap entries in the entities list piling up)

Yes, I spent a lot of time to organize it all in a logical way. I’m not entirely satisfied with the script itself, but the end result, devices and entities in HA, is pretty good :wink:

I have a DW2, and yes I can see the RSSI and battery voltage.

I used to see the battery level… but now I cant anymore… can you? (using HACS - battery state card)
It shows me now ON and OFF … :frowning:

image
image
image

When you start using Shellies Discovery, the standard battery sensor will appear :wink:

Mine is SONOFF DW2, not shelly … now I know I posted in the wrong topic

Some time ago I asked a question about reappearing my Shelly Vintage bulbs when I was trying to switch them to CoIoT and got this answer:

Finally I had some time to try to resolve it but failed again.
I can’t disable MQTT as I have some other devices that need it, so I added them to ignored_devices: in the automation configuration like this:

      ignored_devices:
        - ShellyVintage-6F556B
        - ShellyVintage-6F556B
        - ShellyVintage-6F5892

after that I deleted the devices from the MQTT integration devices screen and restarted HA.
As soon I restarted HA, the devices reappeared again.
I have double checked with MQTT Explorer and there are no topics related to them.
Also the Shelly integration doesn’t pick them after restart as it should.
I am really stuck now what to try next.
Factory reset of the shellies?

Probably you have to manually remove retained topics homeassistant/xxxxx/ShellyVintage-6F556B/config from MQTT broker. As xxxxx use light, sensor, binary_sensor, button. Sometimes HA doesn’t remove config topics when user removes the device in UI.

Is anyone having issues using this script with rgbw2 controllers, ever since 2022.6.1 update i am getting errors in the logs that “template white_value is deprecated”. I am using latest version of the script with the basic config example.

Fixed Release Version 0.44.8 · bieniu/ha-shellies-discovery · GitHub

2 Likes