Hi everyone,
I see many topic on notification, but I was facing an issue;
Send a notification dynamically to a mobile depending it sensor.
In my case, the automation detect when somebody enter a zone. Send a Yes/No notification, if Yes, it starts an action.
The trick, was to don’t declare a static entity to notify but declare a variable (line 22).
I would like to share my code if someone can be interested, and if it can be improved.
Thank you
alias: Auto GarageDoor
description: ''
trigger:
- platform: device
device_id: 04f3b98e4924c358996481802d04641d
domain: device_tracker
entity_id: device_tracker.phone_fab
type: enters
zone: zone.home
- platform: device
device_id: b5f1ac2c8b31b7a7624af0ee435b4389
domain: device_tracker
entity_id: device_tracker.phone_bea
type: enters
zone: zone.home
condition: []
action:
- alias: Set up variables for the actions
variables:
action_oui: '{{ ''OUI_'' ~ context.id }}'
action_non: '{{ ''NON_'' ~ context.id }}'
phone_name: '{{ "notify.mobile_app_" ~ trigger.entity_id.split(".")[1] }}'
- alias: Ask to open garage door
service: '{{ phone_name }}'
data:
message: Ouvrir le garage?
data:
actions:
- action: '{{ action_oui }}'
title: Oui
- action: '{{ action_non }}'
title: Non
- alias: Wait for a response
wait_for_trigger:
- platform: event
event_type: mobile_app_notification_action
event_data:
action: '{{ action_oui }}'
- platform: event
event_type: mobile_app_notification_action
event_data:
action: '{{ action_non }}'
continue_on_timeout: false
- alias: Perform the action
choose:
- conditions:
- condition: template
value_template: '{{ wait.trigger.event.data.action == action_oui }}'
sequence:
- service: script.porte_garage
target:
entity_id: script.porte_garage
mode: restart