Hi guys,
I am really struggling to get my automation running.
My plan is to have a trigger which is either a device-tracker entering a zone or a generic alternative (e.g. manually trigger the automation). The latter optionally induces the first actionable notification to ask which car shall be charged.
The second actionable notification triggers a sequence to open the charger-door, wait that the ev-charger is plugged in and then unlock the ev-charging station.
Both actionable notifications are defined in this script:
alias: Prepare Charging
sequence:
- alias: Set up variables for the actions
variables:
action_open: "{{ 'OPEN_' ~ context.id }}"
action_close: "{{ 'CLOSE_' ~ context.id }}"
arrived_car: "{{ arrived_car }}"
action_chargeKIRC: "{{ 'chargeKIRC_' ~ context.id }}"
action_chargeCarol: "{{ 'chargeCAROL_' ~ context.id }}"
- alias: Trigger-based or Generic Execution
choose:
- conditions: "{{arrived_car == 'generic' }}"
sequence:
- service: notify.mobile_app_rusty_s_iphone_2023
alias: Ask which Car to charge
data:
message: Which Car to charge?
data:
actions:
- action: "{{ action_chargeKIRC }}"
title: KIRC
- action: "{{ action_chargeCarol }}"
title: CAROL
- alias: Wait for a response
wait_for_trigger:
- platform: event
event_type: mobile_app_notification_action
event_data:
action: "{{ action_chargeKIRC }}"
- platform: event
event_type: mobile_app_notification_action
event_data:
action: "{{ action_chargeCarol }}"
timeout:
hours: 0
minutes: 0
seconds: 30
milliseconds: 0
- alias: Perform the action
choose:
- conditions: "{{wait.trigger.event.data.action == action_chargeKIRC }}"
sequence:
- variables:
charger_door: cover.kirc_charger_door
charger_sensor: binary_sensor.kirc_charger
- conditions: "{{ wait.trigger.event.data.action == action_chargeCarol }}"
sequence:
- variables:
charger_door: cover.carol_charger_door
charger_sensor: binary_sensor.carol_charger
- conditions: " {{arrived_car != 'generic' }}"
sequence: []
- alias: Ask to prepare Charging
service: notify.mobile_app_rusty_s_iphone_2023
data:
message: Prepare Charging?
data:
actions:
- action: "{{ action_open }}"
title: Yes, Prepare Charging.
- action: "{{ action_close }}"
title: No Charging.
- alias: Wait for a response
wait_for_trigger:
- platform: event
event_type: mobile_app_notification_action
event_data:
action: "{{ action_open }}"
- platform: event
event_type: mobile_app_notification_action
event_data:
action: "{{ action_close }}"
timeout:
hours: 0
minutes: 0
seconds: 30
milliseconds: 0
- alias: Perform the action
choose:
- conditions: "{{wait.trigger.event.data.action == action_open }}"
sequence:
- service: cover.open_cover
target:
entity_id: "{{ charger_door }}"
data: {}
- wait_template: "{{ states(charger_sensor) == 'on'}}"
continue_on_timeout: true
timeout: "60"
- service: lock.unlock
target:
entity_id: lock.keba_p30_authentication
data: {}
- service: notify.mobile_app_rusty_s_iphone_2023
data:
message: Succesfully executed Automation.
- conditions: "{{ wait.trigger.event.data.action == action_close }}"
sequence:
- service: notify.mobile_app_rusty_s_iphone_2023
data:
message: Automation terminated.
mode: single
Thatâs the automation:
alias: "Trigger Script: Prepare Charging"
description: ""
trigger:
- alias: KIRC Arrival
platform: zone
entity_id: device_tracker.kirc
zone: zone.home
event: enter
id: KIRC-Arrival
- alias: CAROL Arrival
platform: zone
entity_id: device_tracker.carol
zone: zone.home
event: enter
id: CAROL-Arrival
condition: []
action:
- service: script.prepare_charging
data_template:
arrived_car: |
{% if states('Trigger', 'entity_id') == 'device_tracker.carol' %}
cover.carol_charger_door
{% elif states('Trigger', 'entity_id') == 'device_tracker.kirc' %}
cover.kirc_charger_door
{% else %}
generic
{% endif %}
mode: single
Unfortunately, the script stops at that point where I want to use the conditional variables âcharger_doorâ .
Can you tell me, where my problem is?
Thanks in advance.