I’m trying to create what I thought would be a simple automation to notify me when a garage door is left open. I’ve created the two garage door sensors as shown below and they show Open/Closed in the UI, but On/Off in the states. I wanted to know if there is some method to query the state in the context of the device class.
I feel like {{states('binary_sensor.k_garage')}} should respect the device class and return Open/Closed, but instead I get On/Off. Is there a method to use the same state that the UI is using?
I was trying to use the string in a notification and was hoping there was an easier way than to make an if statement for every condition. I wanted to use:
message: K garage is {{states('binary_sensor.k_garage')}}
in the notifier data, but of course that would say “K garage is on”
Specifying a device_class determines how the binary_sensor is depicted in the Lovelace UI. It controls the icon and the terminology used to describe the state values.
Regardless of a binary_sensor’s device_class, its state values are on/off. So if you make a template that checks the binary_sensor’s state, it should refer to values on and off (not Open/Closed, Detected/Clear, Wet/Dry, Unsafe/Safe, etc).
Yes, that is understood. I was asking for a method to query whatever Lovelace is looking at when displaying device-class specific states. I was trying to get to “open/closed” without writing convoluted logic to give me the string I want.