Hi Everyone,
I have 4-5 door sensor. I want to use an automation like " If x door/window is open, sent a notification" I can create a group for all sensor but how can i know which door/window is open? How can I do something special in the message to indicate which window is open? My Example yaml is below. How should i change it ?
alias: Demo
description: ''
trigger:
- platform: state
entity_id: binary_sensor.door_sensors
from: 'off'
to: 'on'
condition: []
action:
- service: notify.outlook
data:
message: Door is Open!
mode: single
tom_l
April 17, 2022, 1:40am
2
Change the group entity id to your group:
Trigger on the group and include this in your message:
data:
message: "Triggered by: {{ expand('group.all_smoke_sensors')|selectattr('state','eq','on')|map(attribute='name')|join(', ') }}"
I did but when i test, i see like this;
Triggered by: Door Sensors
In this group 4 door sensors but i can not see which sensor is opened
Also i share the current code,
condition:
- condition: state
entity_id: binary_sensor.door_sensors
state: 'on'
action:
- service: notify.mobile_app_okan_iphone
data:
message: >-
Triggered by: {{
expand('binary_sensor.door_Sensors')|selectattr('state','eq','on')|map(attribute='name')|join(',
') }}
- service: notify.outlook
data:
message: >-
Triggered by: {{
expand('binary_sensor.door_Sensors')|selectattr('state','eq','on')|map(attribute='name')|join(',
') }}
mode: single
with the window open, I used a smart plug as the trigger. I can get notification but i can not see whiich door is open. All command is below for test.
alias: forum deneme
description: ''
trigger:
- platform: state
entity_id: switch.perde_isigi_priz
from: 'off'
to: 'on'
condition:
- condition: state
entity_id: binary_sensor.door_sensors
state: 'on'
action:
- service: notify.mobile_app_okan_iphone
data:
message: >-
Triggered by: {{
expand('binary_sensor.door_Sensors')|selectattr('state','eq','on')|map(attribute='name')|join(',
') }}
- service: notify.outlook
data:
message: >-
Triggered by: {{
expand('binary_sensor.door_Sensors')|selectattr('state','eq','on')|map(attribute='name')|join(',
') }}
mode: single
tom_l
April 17, 2022, 2:44pm
7
So what do you get in the template editor for this?
{{ expand('binary_sensor.door_Sensors')|selectattr('state','eq','on')|map(attribute='name')|join(', ') }}
1 Like
If i use without Triggered by: {{ it’s not working but i found a command. Looks like it’s working. What do you think about this command? It’s looks like correct ?
alias: Okan Erdem
description: ''
trigger:
- platform: state
entity_id: switch.perde_isigi_priz
from: 'off'
to: 'on'
condition:
- condition: state
entity_id: binary_sensor.door_sensors
state: 'on'
action:
- service: notify.outlook
data:
message: >-
{{ dict((states|selectattr('entity_id', 'in',
state_attr('binary_sensor.door_Sensors',
'entity_id'))|list)|groupby('state'))['on']|map(attribute='name')|list|join(',
') }} Window is open!
mode: single```
I tested again, also worked your code. Thanks Tom_I
I see message like this; " Triggered by: Kitchen Window" or which windos is open. Problem was
binary_sensor.door_Sensors
normally should be small s for Sensors
Like this;
binary_sensor.door_sensors