- binary_sensor:
- name: "Pool Pump Status"
unique_id: templatebinarysensorpoolpump
device_class: power
state: >-
{%- if is_state('switch.aeotec_smart_switch_gen5_2_2', 'off') -%} Off
{%- elif is_state('switch.aeotec_smart_switch_gen5_2_2', 'unavailable') -%} Offline
{%- elif is_state('switch.aeotec_smart_switch_gen5_2_2', 'on') -%} On
{%- endif %}
icon: >-
{% if is_state('switch.aeotec_smart_switch_gen5_2_2', 'off') %} mdi:water-pump-off
{% else %} mdi:water-pump
{% endif %}
Updated from 2023.06.02 to 2023.08.02 and now my template sensors similar to the above display a state that doesn’t align to the template. The template generates the correct output for state and icon in the Template Developer Tool but the actual frontend shows the state as “Detected” or “Cleared”.
If I hash the device_class: power line it will display the desired On / Off / Offline state.
The documentation still says that Power should show On / Off so I’m not even sure why Detected / Cleared is an output.
Binary sensors must be on or off, nothing else and depending on their class, they will be rendered such as Online/Offline or Motion/No motion or Open/Close. Setting unavailable might make it Offline but not sure. Connectivity device class could be a better choice.
Keep in mind, unavailable is not a state that is a situation of availability of sensor.
I have used the template binary sensor successfully in the past to get more than an on / off. This is a Z-Wave switch where I had issues with them going offline (due to distance/signal).
My query was why the device class of Power was now giving a Detected / Cleared status when seeing the on / off state. It’s not a status for that device class. Removing the device class has resolved the issue.
The sensor is on if the template evaluates as True , yes , on , enable or a positive number. Any other value will render it as off. The actual appearance in the frontend (Open /Closed , Detected /Clear etc) depends on the sensor’s device_class value.
As for device_class: power the documentation’s image and written description seem to disagree on the reported values in the UI.