I have several Aeotec door and window sensors which return 22 if the contact is open, and 23 when it’s closed. Occasionally they return 254* when they’re asleep, so I’m using an input_boolean to filter out that state and feed a binary_sensor which I can set with device_class of door or window. I’m struggling with nested if statements in the data_template section of my automation. The goal is to set the right input_boolean “filter” sensor and notify me of any unknown states or sensors.
- id: '1591327292171'
alias: Aeotec Door and Window Boolean Filter
description: "Change the input boolean for known states of the door's access control\n\
\ sensor while filtering out state 254"
trigger:
- entity_id: sensor.sliding_glass_door_access_control, sensor.front_door_access_control,
sensor.garage_house_door_access_control, sensor.garage_side_door_access_control,
sensor.kevin_bed_window_access_control
platform: state
condition:
- condition: template
value_template: '{{ trigger.to_state|int != 255 }}'
- condition: state
entity_id: binary_sensor.system_ready
state: 'on'
action:
- service_template: >
{% if trigger.entity_id == 'sensor.sliding_glass_door_access_control' or trigger.entity_id == 'sensor.front_door_access_control' or trigger.entity_id == 'sensor.garage_house_door_access_control' or trigger.entity_id == 'sensor.garage_side_door_access_control' or trigger.entity_id == 'sensor.kevin_bed_window_access_control' %}
{% if trigger.to_state.state|int == 23 %}
input_boolean.turn_off
{% elif trigger.to_state.state|int == 22 %}
input_boolean.turn_on
{% else %}
notify.kevin
{% endif %}
{% else %}
notify.kevin
{% endif %}
data_template: >
{% if trigger.to_state.state|int == 23 or trigger.to_state.state|int == 22 %}
entity_id:
{% if trigger.entity_id == 'sensor.sliding_glass_door_access_control' %}
input_boolean.sliding_glass_door_filter
{% elif trigger.entity_id == 'sensor.front_door_access_control' %}
input_boolean.front_door_filter
{% elif trigger.entity_id == 'sensor.garage_house_door_access_control' %}
input_boolean.garage_house_door_filter
{% elif trigger.entity_id == 'sensor.garage_side_door_access_control' %}
input_boolean.garage_side_door_filter
{% elif trigger.entity_id == 'sensor.kevin_bed_window_access_control' %}
input_boolean.kevin_bed_window_filter
{% else %}
- data:
title: You have a problem with the {{ trigger.entity_id }}
message: The trigger.to_state is {{ trigger.to_state.state|int }}
{% endif %}
{% else %}
- data:
title: "You have a problem with the {{ trigger.entity_id }}"
message: The trigger.to_state is {{ trigger.to_state.state|int }}
{% endif %}
My configuration check returns:
Configuration invalid
Invalid config for [automation]: expected a dictionary for dictionary value @ data['action'][0]['data_template']. Got None. (See ?, line ?).
The configuration check passes if the data_template:
section is changed to:
data_template:
entity_id: >
{% if trigger.entity_id == 'sensor.sliding_glass_door_access_control' %}
input_boolean.sliding_glass_door_filter
{% elif trigger.entity_id == 'sensor.front_door_access_control' %}
input_boolean.front_door_filter
{% elif trigger.entity_id == 'sensor.garage_house_door_access_control' %}
input_boolean.garage_house_door_filter
{% elif trigger.entity_id == 'sensor.garage_side_door_access_control' %}
input_boolean.garage_side_door_filter
{% elif trigger.entity_id == 'sensor.kevin_bed_window_access_control' %}
input_boolean.kevin_bed_window_filter
{% else %}
- data:
title: You have a problem with the {{ trigger.entity_id }}
message: The trigger.to_state is {{ trigger.to_state.state|int }}
{% endif %}
I’d appreciate any help in understanding what I’m doing wrong, or pointers to documentation.
* The automation condition is set to 255 and not 254 intentionally so that I can test the notification when the device goes to sleep. I’ll correct it later once I know it’s working.