I need some help setting up a virtual switch that controls a relay but reflects the status of another sensor. I have a momentary relay that opens or closes a garage door and a contact sensor that returns the state (open or closed) of the door. Currently I have a virtual switch that reflects the status of the sensor but does not toggle the relay. Thanks for your help here and let me know if you need any more info.
Thanks for the feedback! I think this is close to what I am looking for. Is there a way to edit the YAML of a virtual entity? I wanted to do this on a dashboard originally, but now I think it would be better as an entity so I can use it in third party apps.
“switch.k” is the relay and “binary_sensor.k_garage_door_contact” is the contact sensor. I don’t see any changes to the switch, so either this isn’t configured properly or I am looking in the wrong place. Thanks for your inputs!
@Guerardi beat me to it: a state of a sensor and an attribute are not the same thing. You are trying to get the state as if it were an attribute. For state it is just is_state. Attributes are used less and less. You might need it for instance to get to the color or brightness of a light, while the state of the light is on or off.
So the value template should read (pretty much as the example in the documentation):
What @Guerardi also changed: instead of a switch you could implement a cover entity, which is a more true representation of the device you want to emulate. So while not an exact implementation of your question, it is an even better way to solve your original problem. There are some errors in his example though, a space is missing for the device class, and all operations do the same thing: turn on a light. But the idea is right.