Hello guys,
I do have a problem with the following configuration.
I have some temp sensors around the house and set up a fire alert to alert me if the temps get too high.
All the sensors are in a group I created.
I have also created a template binary sensor. However, everytime I restart my router, this alert gets triggered due to some wifi sensors being unavailable.
I have checked and tested but I cannot figure out why the template triggers this alert.
the binary sensor config is:
- binary_sensor:
- name: "Fire Alarm Sensor"
unique_id: "Fire Alarm Sensor"
device_class: heat
icon: >-
{% if is_state('binary_sensor.fire_alarm_sensor', 'on') %}
mdi:fire
{% else %}
mdi:fire-off
{% endif %}
state: >-
{% if (expand('group.fire_sensor_group') | selectattr('state', '>=', states('input_number.fire_alert_trigger_degree')) | list | count) > 0 %}
True
{% else %}
False
{% endif %}
delay_on: 00:00:05
delay_off: 00:00:05
availability: >-
{% set sensor_list = expand('group.fire_sensor_group') | map(attribute='state') | list %}
{{ (not 'unavailable' in sensor_list) and (not 'unknown' in sensor_list ) }}
attributes:
sensors: >-
{% if not is_state('group.fire_sensor_group', 'unavailable') %}
{% set sensor_list = expand('group.fire_sensor_group') | selectattr('state', '>', states('input_number.fire_alert_trigger_degree')) | map(attribute='name') | list | join(', ') %}
{{ sensor_list }}
{% endif %}
I put these availability checks but I need to remove them since it is a possible reason that a sensor may get unavailable but the alert should run fine nevertheless.
So what happens is, when router connection reestablishes it, the binary sensor goes “on” briefly triggering the alert. I know I can increase the delay with delay_on and delay_off but this is a workaround not a solution.
When I tested more putting this statement to template editor.
{{ (expand('group.fire_sensor_group') | selectattr('state', '>=', "50") | list | count) }}
I noticed that when a wifi temp sensor (DHT22, esp32 with esphome) loses connection and becomes unavailable, the template evaluates the statement and it counts towards the count.
So could please anyone explain to me why selectattr(‘state’, ‘>=’, “50”) also counts unavailable sensors?
How can I fix it?
Thanks in advance.