dawidchyrzynski / arduino-home-assistant

ArduinoHA allows to integrate an Arduino/ESP based device with Home Assistant using MQTT.
https://dawidchyrzynski.github.io/arduino-home-assistant/
GNU Affero General Public License v3.0
508 stars 119 forks source link

light.setState publishing non-retained state #131

Closed milansim closed 9 months ago

milansim commented 1 year ago

using [2.0.15-rc.1] light.setState works, but after arduino restart state is not saved, despite setretain(true), only if turned on/off from Home assistant

My workaround is complex...I use tzapu's wifimanager to save topic for lights (e.g. "aha/c8f09e52f9d4/") then instead of set state I publish on cmd/t String light1 = light_topic + "Light1/cmd_t"; mqtt.publish(light1.c_str(), "ON", true); // mqtt.publish("customTopic", "customPayload", true); //true mean retained

Obviously "setState" needs retained flag in library like it has "force" flag

dawidchyrzynski commented 9 months ago

@milansim Closing this as I am unable to reproduce the issue. Retention works correctly in both directions; hence, it might be a bug within your implementation.

milansim commented 8 months ago

@milansim Closing this as I am unable to reproduce the issue. Retention works correctly in both directions; hence, it might be a bug within your implementation.

It is simple implementation so I doubt that. I will test again sometime but since my workaround works...

amalon commented 1 week ago

I see something similar. If I set rgb from HA, it puts a rgb_cmd_t in mqtt, but if I then send a button press to the device to trigger a reset to default colours, i have it changing state unilaterally from the arduino device, that changes rgb_stat_t, but leaves rgb_cmd_t at the now stale value set by HA, which is reloaded on reset.