I have two shelly plus 1 switches, that each control a lamp, configured in home assistant via MQTT (see below for my configuration). This works fine, I can turn my lights off and on via Homeassistant and do some automation with it via nodeRED, the only problem I’m facing is that if I restart homeassistant while at least one of the lights are on homeassistant doesn’t pick up the active state and/or simply defaults to an “off” state (physically lights remain “on”). This causes problems, as homeassistant can’t operate the shelly switches anymore until I turned them off either via the wall switch or via the web interface of the shelly switch. Are there any solutions to fix this, so that when I restart homeassistant he actually looks at the current state of the shelly switch instead of like just assuming it is “off”
This did indeed seem to do the trick! That then in combination with telling nodeRED to watch the state of the switch itself instead of the binary sensor state (as I cannot pass the optimistic flag to the binary sensor). Quick question: Does using this optimistic flag hold downfalls? Are there cases where this flag could give me disadvantages or whatever…?
This would indeed be the best solution I think, but unfortunately this can’t be done. I think it is possible with gen 1 shelly devices, but not (yet) with gen 2 (and I’m using gen2)
It does not, I’m afraid. Well, to be perfectly clear the code itself works, I can turn my lights on/off just as good, as with my code above, but the original problem is still there. Seems that I need to set the optimistic flag to true as long as shelly doesn’t change their software to allow the setting of the persistent flag (but that’s just a hypothesis).
I don’t know for you, but for me I had issues with the switch when I had my quotes for the value_template like this: ’ " " '. It only worked when " ’ ’ " was like this
I don’t know if you realised that after enabling MQTT we have to reboot the device and the make sure we activate “Generic status update over MQTT” under MQTT section (refresh the page to show this option, if needed).
Hello. Yes, the option is active and everything seems to work correctly but the warning I posted above appears in the log. It seems that the problem is similar to the one described in this topic: https://community.home-assistant.io/t/mqtt-dict-object-has-no-attribute/297330
but I don’t understand how to fix it.
Questa è la configurazione dell’interrutore, come quella di cvm
Have you checked your MQTT content with an MQTT explorer of some kind? Maybe the PM outputs differently towards MQTT? (would be weird I guess, but who knows…)