I’m trying to get a binary_sensor to report either ‘on’ or ‘off’ based on the value of another sensor.
I would like to binary_sensor to report ‘off’ if the other sensor value is below 5 and ‘on’ if it is above 5. So far my attempt below has not worked… Any tips?
I see too many questions like the OP and perhaps the main reason is the way it’s described in documentation:
Defines a template to set the state of the sensor.
It should be more explicit and descriptive, something like
The sensor is on if the template evaluates as True and off otherwise.
The actual appearance in UI (Open/Closed, Detected/Clear etc) depends on the sensor’s device_class value.
I agree. Also when I originally put the template in the development tool, I was getting ‘True’… But I don’t think I had binary_sensor in front of it… Can’t remember
That’s because the template evaluates to True or False. The binary sensor takes this information and maps it to on and off respectively. Even if you change the device class so the front end shows something different (detected / clear for a movement sensor for example) the binary sensor still reports on or off to the back end for triggers and templates.