Trying to get sensor data to know the initial (and subsequent) states of a relay for a toggle switch using button-card. My sensor data looks like this:
- switch:
name: "Master Bedroom Chimney Fan"
command_on: "/usr/bin/curl -X GET http://192.168.12.11/state.xml?relay1=1"
command_off: "/usr/bin/curl -X GET http://192.168.12.11/state.xml?relay1=0"
command_state: curl -X GET http://192.168.12.11/state.xml
Is there a way to use the sensor data (which is correct in showing the intial and current state) for the icon and use a toggle action (or equivalent) using the switch call?
As of now, not even toggle switches the state of the relay, all it does is turns it on if it is off, but I cannot turn it off pressing the same button. Also, the initial or subsequent states of the relay are never updated (i.e. change in color).
Thanks for your response, but neither seems to work. I had tried your first suggestion before, but it didn’t work. I was trying to use is_state or, as someone suggested, a template but I am new to this and am getting a bit confused on templates and their uses.
will give the correct state if I place it in developer tools-> template and see the output. The problem is any switch that I use does not give a correct initial state and the slider switch card included in overview has its initial state of the relay as off, even if on. Further, when I turn the switch on, it changes the relay state to on, but slides back to off on the slider switch card.
Could the return of states be the problem? That is, states returns a string, should I convert it to true/false?