I followed a few guides here to get Persistent notification with buttons for delay on my phone.
I’m running into a weird issue that I’m not sure is syntax, or just impossible to do with the scripts.
I have a thermostat running in my garage, i want it to notify (persistent) with buttons for turn off, delay 20min, All ok, when the compressor has been running over 20 minutes.
I have a working solution with a dedicated script. but would like the script to be automation agnostic, in case I call it from a different automation. Currently I can only get it to work if I call the “automation.trigger” with hardcoded entity_id.
Any time I do the same, but with the entity_id variable, the script fails.
EDIT: I was an idiot and didn’t test the entire script. just selected “run” on the automation.trigger service in gui, which succeeded.
When running the entire script, even the hardcoded automation.trigger does not succeed…
My automation is this:
alias: GarageThermostatTest
description: ""
trigger:
- platform: device
type: turned_on
device_id: 7a315795d9c9edb21c23001289cc62cf
entity_id: 947a731813fbc75a590dfb2f159bf729
domain: switch
for:
hours: 0
minutes: 20
seconds: 0
condition: []
action:
- service: notify.mobile_app_rusty_phone
metadata: {}
data:
title: Thermostat Notification
message: Garage AC on more than 20 Minutes
data:
actions:
- action: TURNOFF
title: Turn AC OFF
- action: SNOOZE_20_MIN
title: Ignore 20 Min
- action: IGNORE
title: All OK
persistent: true
tag: garageTherm
- wait_for_trigger:
- platform: event
event_type: mobile_app_notification_action
event_data:
action: TURNOFF
- platform: event
event_type: mobile_app_notification_action
event_data:
action: SNOOZE_20_MIN
- platform: event
event_type: mobile_app_notification_action
event_data:
action: IGNORE
continue_on_timeout: true
timeout: "0:05"
- choose:
- conditions:
- condition: template
value_template: "{{wait.trigger.event.data.action == \"TURNOFF\"}}"
enabled: true
sequence:
- service: climate.set_hvac_mode
metadata: {}
data:
hvac_mode: "off"
target:
area_id: garage
- service: notify.mobile_app_rusty_phone
data:
message: clear_notification
data:
tag: garageTherm
- conditions:
- condition: template
value_template: "{{wait.remaining == 0}}"
enabled: true
sequence:
- service: climate.set_hvac_mode
metadata: {}
data:
hvac_mode: "off"
target:
area_id: garage
- service: notify.mobile_app_rusty_phone
data:
message: clear_notification
data:
tag: garageTherm
- conditions:
- condition: template
value_template: "{{wait.trigger.event.data.action == \"SNOOZE_20_MIN\"}}"
enabled: true
sequence:
- service: script.snooze_notifications_retrigger
data:
snooze_time_mins: 20
automation_name: automation.garagethermostattest
- conditions:
- condition: template
value_template: "{{ wait.trigger.event.data.action == \"IGNORE\"}}"
enabled: true
sequence:
- service: notify.mobile_app_rusty_phone
data:
message: clear_notification
data:
tag: garageTherm
mode: restart
My Script is this: (this one fails and doesn’t retrigger the automation, but does re-enable it)
alias: Snooze Notifications Retrigger
sequence:
- service: automation.turn_off
target:
entity_id: "{{ automation_name }}"
data:
stop_actions: false
- delay:
minutes: "{{ snooze_time_mins }}"
- service: automation.turn_on
target:
entity_id: "{{ automation_name }}"
- delay:
seconds: 1
- service: automation.trigger
metadata: {}
data:
skip_condition: true
target:
entity_id: "{{ automation_name }}"
mode: single
description: snooze Notifications, then fire again after snooze
This one succeeds, but is obviously not automation agnostic.
alias: Snooze Notifications Retrigger
sequence:
- service: automation.turn_off
target:
entity_id: "{{ automation_name }}"
data:
stop_actions: false
- delay:
minutes: "{{ snooze_time_mins }}"
- service: automation.turn_on
target:
entity_id: "{{ automation_name }}"
- delay:
seconds: 1
- service: automation.trigger
metadata: {}
data:
skip_condition: true
target:
entity_id: automation.garagethermostattest
mode: single
description: snooze Notifications, then fire again after snooze
So the real hangup is, Why does the automation.turn_on succeed with variable as entity_id, While the automation.trigger fails… (unless somehow I’ve got bad syntax. which is very possible) (See edit before code)