StyraHem / ShellyForHASS

Shelly smart home platform for Home Assistant
MIT License
620 stars 111 forks source link

MQTT is not working correctly with Shelly Dimmer 2 #534

Closed hebgit closed 2 years ago

hebgit commented 3 years ago

Environment

Describe the bug

Added Shelly Dimmer 2 to ShellyForHASS via MQTT, using the supervised Mosquitto Broker. When turning the light on or off there is no "command=on" published on the MQTT topic of the device.

Steps to Reproduce

Turn light on or off and check with MQTT explorer

Expected behavior

"on" should be published at "shellies/shellydimmer2-xx/light/0/command"

Screenshots

image

Traceback/Error logs

Additional context

hebgit commented 3 years ago

Thanks for your fast fix. On/off is working fine now but unfortunately the status isn’t reflected in home assistant instantly. As soon as I toggle the light on, home assistant sets the status of the light back to off. After a few seconds it turns on again without any interaction.

pa-sleo commented 3 years ago

@whig0 : This problem usually happens if your network has a problem with multicasting. This app uses CoAP/CoIoT to get the state back. But in some networks like ASUS AI-Meshs this is not working. The app also uses polling to ge the state but without the direct feedback after your action you get that effect.

@hakana : For the CoAp/CoIoT problems: I would prefer a slightly different approach than currently implemented:

The app should keep the state set by the user until it recognize the different either by CoAP or Polling. So the state would be correct in 99%. The case that the action hasn't performed and so the user setted state has to be reverted is in my opinion much rare in a good working network than the opposite.

hebgit commented 3 years ago

This app uses CoAP/CoIoT to get the state back.

Is CoAP used even when the Shellies are discovered via MQTT?

Currently I have two entities for the same Shelly. One via CoAP, one via MQTT (with custom MQTT prefix). The status of the CoAP entity changes instantly when turned on via a physical switch. The status of the MQTT changes after ~10 seconds.

hakana commented 3 years ago

@IQS-Leopold The status should change to user-set until next received update

@whig0 I'm not sure if I understand. If you use MQTT with ShellyForHass you should not change to a customized MQTT prefix because then it will not work. Yes, CoAP runs in parallel with MQTT.

pa-sleo commented 3 years ago

@hakana Thema this isnt Wirkung properly and we should open, an extra Bug. Behavior at my Setup:

User set light on. State is on. State goes off. State goes in after some seconds.

So it seems there ist a problem causing a state flip.

hebgit commented 3 years ago

@hakana The strange thing is that this is working fine with my Shelly 1 and Shelly 1l. Only the Shelly Dimmer 2 have this problem. Maybe the MQTT status is not read on the correct MQTT topic as it is different. ('light' instead of 'relay')