I have a list of some window sensors, door sensors and motion sensors. I collected these sensors in three groups so to have a generic idea if a window or a door in my place is open, or there is some motion detected.
The following is from my groups.yaml file:
doors:
name: Main Doors
entities:
- binary_sensor.window_door_sensor_2
- binary_sensor.openclose_9
motion_sensors:
name: Motion Sensors
entities:
- binary_sensor.motion_sensor_2
- binary_sensor.presence_17
- binary_sensor.presence_18
windows:
name: Windows
entities:
- binary_sensor.openclose_13
- binary_sensor.openclose_12
- binary_sensor.openclose_14
When showing the corresponding groups on lovelave I can see the status changing from off to on when an activity is triggered, as I would expect.
However, I wanted to set up a binary template sensor to have a more personalized experience, like âopen/closedâ or âdetected/clearâ text. Additionally, the template sensor should come handy because I would like to have a different icon according to the sensor status.
This is how I set up the binary template sensors in my configuration.yaml:
binary_sensor:
- platform: template
sensors:
windows:
friendly_name: "Windows"
device_class: window
value_template: >-
{% if group.windows == 'on' %}
Open
{% elif group.windows == 'off' %}
Closed
{% else %}
n/a
{% endif %}
icon_template: >
{% if group.windows == 'on' %}
mdi:window-open
{% elif group.windows == 'off' %}
mdi:window-closed
{% else %}
mdi:help
{% endif %}
- platform: template
sensors:
doors:
friendly_name: "Doors"
device_class: door
value_template: >-
{% if group.doors == 'on' %}
Open
{% elif group.doors == 'off' %}
Closed
{% else %}
n/a
{% endif %}
icon_template: >
{% if group.doors == 'on' %}
mdi:door-open
{% elif group.doors == 'off' %}
mdi:door-closed
{% else %}
mdi:help
{% endif %}
- platform: template
sensors:
motion_sensors:
friendly_name: "Motion Sensors"
entity_id:
- binary_sensor.motion_sensor_2
- binary_sensor.presence_17
- binary_sensor.presence_18
value_template: >-
{% if is_state("binary_sensor.motion_sensor_2", "on")
or is_state('binary_sensor.presence_17', 'on')
or is_state('binary_sensor.presence_18', 'on') %}
Clear
{% else %}
Detected
{% endif %}
icon_template: >-
{% if is_state("binary_sensor.motion_sensor_2", "on")
or is_state('binary_sensor.presence_17', 'on')
or is_state('binary_sensor.presence_18', 'on') %}
mdi:human-male
{% else %}
mdi:human-handsup
{% endif %}
The door and window sensors always show closed with the âclosed-iconâ, even when something is open (and I can see the group status going correctly from off to on). While the motion sensor is always showing off, so not even the text changes to âClearâ.
Do you know what I am doing wrong? I guess it should be an easy thing to implement