Hi
i want to trigger an automation based on an Event (Garage door open + 10 minutes) - and want to repeat the automation every subsequent 10 minutes when the Event is still valid.
Currently i have only the initial trigger - but how can i implement the reminder?
- id: '1647686414969'
alias: Alexa Question GarageOpen
description: ''
trigger:
- platform: state
entity_id: binary_sensor.garage_open
to: 'on'
for:
hours: 0
minutes: 10
seconds: 0
condition: []
action:
- service: script.activate_alexa_actionable_notification
data:
text: The garage is open since 10 minutes - should i close it?
event_id: garage_left_open
alexa_device: media_player.wohnzimmer
mode: single
I´m open for any advice.
Thank you in advance
Kind regards
Thorsten
Here is something to consider. You will need another automation to stop adding 10 minutes. I am not 100% certain about the text template and if HA will evaluate it.
- id: '1647686414969'
alias: Alexa Question GarageOpen
description: ''
trigger:
- platform: state
entity_id: binary_sensor.garage_open
to: 'on'
for:
minutes: "{{ states('input_number.time_to_delay') | int(0) }}"
condition: []
action:
- service: script.activate_alexa_actionable_notification
data:
text: "{{ 'The garage is open since' ~ states(input_number.time_to_delay') ~ 'minutes - should i close it?' }}"
event_id: garage_left_open
alexa_device: media_player.wohnzimmer
- service: input_number.set_value
data_template:
entity_id: input_number.time_to_delay
value: "{{ states('input_number.time_to_delay') | int(0) + 10 }}"
mode: single
Hi
i get an
2022-05-26 20:25:49 ERROR (MainThread) [homeassistant.config] Invalid config for [automation]: template value should be a string for dictionary value @ data[âactionâ][0][âdataâ]. Got None. (See /config/configuration.yaml, line 8).
Line 8 is the line with the âminutes:â
Do i have to set/pre-define the âinput.number.time_to_delayâ somewhere?
Best
Thorsten
Hi @cyn
thanks for the hint. Is it possible to use the alert to trigger an automation?
This would be required to trigger my alexa asking me if i want to close it.
Best
Thorsten
Yes, once you set up the alert look in developer tools, states. I defined my alert as alert_control. When you look thru your entries you should see an entity called alert.alert_control. This entity has 3 states, idle, on & off. Use that as your automation trigger.
This wonât work. A state trigger only triggers when the state changes. If the for option is used then it only triggers after a state change if the entity remains in that same state for that amount of time. You canât keep adding time to it though, that wonât work. It wonât fire again until the state changes to off and then back on no matter what time_to_delay is set to. Try it on test entities if you donât believe me.
@thorsten-gehrig so this is actually a bit complicated unfortunately. @cyn is right, the tool for the job is alert. But alert has a problem since it can only call a notification service and you want to call a script, alert canât do that. So I guess hereâs the two options I would recommend, take your pick:
Alert to Script
Create a notification group like this. Yes services is supposed to be empty
notify:
- platform: group
name: Alexa actionable notification
services: []
Create an automation which listens for calls to that notification group and passes them to your script like this:
alert:
name: Garage door open
entity_id: binary_sensor.garage_open
state: 'on'
skip_first: true
repeat: 10
notifiers: 'alexa_actionable_notification'
message: "The garage is open since 10 minutes - should i close it?"
data:
event_id: garage_left_open
alexa_device: media_player.wohnzimmer
With these 3 the alert will call your notification service 10 minutes after the garage is open and every 10 minutes until it closes. And the automation will listen for calls for that service and pass them to the script.
Automation option
You can do this as a pure automation but it involves a template. Hereâs what you could do:
trigger:
- platform: template
value_template: >-
{% set minutes_diff = ((now() - states.binary_sensor.garage_open.last_changed).total_seconds() / 60) | int %}
{{ is_state('binary_sensor.garage_open', 'on') and minutes_diff > 1 and minutes_diff % 10 == 0 }}
action:
- service: script.activate_alexa_actionable_notification
data:
text: The garage is open since 10 minutes - should i close it?
event_id: garage_left_open
alexa_device: media_player.wohnzimmer
Since this template involves now() its going to be evaluated every minute. And what it will do is first get the total number of minutes between now and the last time the garage changed. If the garage is open and that total minutes is greater then 1 and itâs a multiple of 10 then it sends your notification.
Sorry I wish this was easier but if you really need a script to send your notification I think these are your best options since alert needs a workaround to do that.
I was going to suggest a repeat - while, to repeat the alexa notification script every ten minutes while the binary_sensor was on. However, I prefer your suggestion because itâs not only more concise but also survives restarts/reloads.
Sorry perhaps that first part came off more aggressive then I intended. I wasnât trying to start an argument or anything just wanted to make you and the thread author aware of the limitations of state-type triggers.
Hi guys
appreciate all your help.
Got it finally working!
I´ve understand the alert calls the notification.
The alert itself âdefinesâ the data âevent_idâ and âalexa_deviceâ and âmessageâ (to be used finally in the last step).
The ânotifyâ is defined as call the âAlexa actionable notificationâ -Service - which is empty.
End of this thread.
But the automation does recognize this call for the (empty) notification Service (trigger: call service / Aleca actionable notification) - as trigger - and as action calls the script âscript.activate_alexa_actionable_notificationâ (all the variables found by the template)
Somehow weird - but if it works I´m happy.
What I still confusing me - but guessing thatâs another story - while my Alert-condition âbinary_sensor.garage_obenâ is still state âonâ - the alert âalert.garage_doorâ is switching to Idle after the first call. Shoudnt the status stays âonâ while it´s neiter confirmed not cleared?
Yes it should, thatâs very odd. I have a lot of alerts and Iâve never seen anything like that. As long as binary_sensor.garage_open has state on then the alert should have state on. Unless you dismissed it, in which case it should have state off. It should only have state idle if binary_sensor.garage_open has a state other then on.
If you are seeing the alert with state idle while binary_sensor.garage_open has state on then you should report a bug. But I would really be scratching my head over here. I have been using alerts for years. I have 27 right now and have had more in the past, have never had an issue like that tbh.