I have managed to setup an automation that sends a basic notification to my iOS device when I am not at home and have left a door open. I’m now trying to build on the notification to include the specific door that was left open (see below):
- alias: 'Doors left open'
hide_entity: true
trigger:
platform: state
entity_id: binary_sensor.jonathan_presence
to: 'off'
condition:
condition: state
entity_id: group.doors
state: 'on'
action:
- service: notify.ios_ifone
data:
message: >
{% set open_doors = {{ states | selectattr('entity_id', 'in', state_attr('group.all_doors','entity_id')) | selectattr('state','in',['on','open']) | list | map(attribute='name') | join(', ') }}
The following doors have been left open: {{ open_doors }}
However this throws an error in the log:
2019-04-06 21:00:00 ERROR (MainThread) [homeassistant.components.automation] Error while executing automation automation.doors_left_open. Invalid data for call_service at pos 1: invalid template (TemplateSyntaxError: expected token ':', got '}') for dictionary value @ data['message']
Any suggestions on how I could make this work? Thanks
If you do have group.all_doors, try removing the argument within the set argument. There also wasn’t a %} to close the set.
{% set open_doors = states | selectattr('entity_id', 'in', state_attr('group.all_doors','entity_id')) | selectattr('state','in',['on','open']) | list | map(attribute='name') | join(', ') %}
The following doors have been left open: {{ open_doors }}
Thanks all - I managed to solve it (by chance!) through the following code:
- alias: 'Doors left open'
hide_entity: true
trigger:
platform: state
entity_id: binary_sensor.jonathan_presence
to: 'off'
condition:
condition: state
entity_id: group.doors
state: 'on'
action:
- service: notify.ios_ifone
data_template:
message: >
The following doors have been left open: {{ states | selectattr('entity_id', 'in', state_attr('group.doors','entity_id')) | selectattr('state','in',['on','open']) | list | map(attribute='name') | join(', ') }}
Which generates notifications that look like this:
You can create a dummy “negative” template sensor and to map the states on -> off, and off -> on and then group it with your other entities in the group…