I’m trying to do what I think is going to be a more complex template than anything I’ve ever tried before. I’m not a programmer, but I’ve been playing at HA for just about 2 years now and I’m getting better at figuring out the terminology of what I need to search for to get answers. But I’m a bit stumped.
Here’s my use case:
I have NFC stickers that will be located in various rooms, that, when scanned, will trigger an automation asking/reminding me to do various tasks. I have a rough schedule in my brain on when all of my tasks should be completed, so I think there needs to be a datatime component. Right now my lone automation is that if Tag A is scanned, that the Datatime Stamp is changed to that moment.
I want, after X amount of time AND if Tag B HASN’T been scanned, for an automation to remind me to scan B. Scanning Tag B then remind me to start those tasks.
I’m not sure if my brain is then trying to overcomplicating this. My brain insists that I need the datatime component, to make a template that if the most recent datatime stamp is greater than X amount of time, then I need the secondary reminder automation. (Tag B hasn’t been scanned yet!). I’m not even sure how I’d set that up from a template standpoint.
And I know from previous discussions with @123 that using templating as a trigger isn’t a best practice.
So I guess I’m flailing at windmills and hoping some one can point me in the right direction?
what’s the X amount of time between tag a and tag b? if it’s long enough that you worry about home assistant restarting in the middle, then doing a restorable timer may be the right thing. if it’s short enough or if you’re not concerned with homeassistant restarting in the middle, it’s pretty easy to do a wait_for_event after tag a.
well… one way to do it is to create an automation on scan of tag a, start a timer. set it to be restored on ha restart.
in that automation (or different one if you prefer) you also trigger on scan of tag b, and cancel the timer.
in that automation (again, or different if you prefer) you trigger on the timer firing. if it fires, then you haven’t scanned in time so go send all your notifications.
this can all be done in the ui. no yaml, template, coding needed.
you cancel the timer when tag b is scanned. which means the timer will not fire so you won’t get notified. but if tag b isn’t scanned, then the timer fires after 90 minutes and you notify.
tell you what… you’ve been on ha for 2 years now. give building the automation a try. then post it here and i can take a look at it instead of talking in abstract.
Okay, let’s see if my brain dead brain actually comprehends…
Automation to start doing tasks in the living room
alias: Living Room 1 - Tasks and Timer
description: ""
trigger:
- platform: tag
tag_id: LR1
condition: []
action:
- action: timer.start
metadata: {}
data: {}
target:
entity_id: timer.living_room_timer_1
- action: tts.speak
metadata: {}
data:
cache: true
media_player_entity_id: media_player.downstairs_devices
message: This is only an example. Modify me later.
target:
entity_id: tts.piper
mode: single
Automation when living room timer is done
description: ""
mode: single
trigger:
- platform: state
entity_id:
- timer.living_room_timer_1
from: active
to: idle
for:
hours: 0
minutes: 0
seconds: 2
condition: []
action:
- action: tts.speak
metadata: {}
data:
cache: true
media_player_entity_id: media_player.house_speakers_ben_s_room
message: Scan the tag in your bedroom to start the next set of tasks.
target:
entity_id: tts.piper
I don’t have a second tag created yet (I kinda wanted to try and figure this all out) but, scan THAT tag, have it disable the second automation. I already have an automation that resets some things at midnight, so that automation could be enabled again at that point.
looks like you’ve got the right direction. except this:
description: ""
mode: single
trigger:
- platform: event
event_type: timer.finished
event_data:
entity_id: timer.living_room_timer_1
condition: []
action:
- action: tts.speak
metadata: {}
data:
cache: true
media_player_entity_id: media_player.house_speakers_ben_s_room
message: Scan the tag in your bedroom to start the next set of tasks.
target:
entity_id: tts.piper
see how i changed the trigger event to use the timer.finished event? this is necessary to distinguish between when the timer is finished versus when it’s cancelled. if you only go from active to idle, that happens for both the finish case and the cancell case.
now go add the automation that triggers on tag b getting scanned and have that cancel the timer.
I’m not sure what gave you that impression. There is nothing wrong at all with using a template trigger.
You may be confusing it with using a time pattern trigger as not a best practice. And that I agree with.
Here is another take on this using input datetimes:
scan tag A
That triggers an automation to set an “input_datetime.tag_b_reminder” to some time in the future when tag B needs scanned before.
create a second automation using “input_datetime.tag_b_reminder” as the trigger and in that automation put in a condition to check if tag B has been scanned recently.
if tag B isn’t scanned before the “input_datetime.tag_b_reminder” time then run the second reminder actions. if it has then don’t run the reminder actions.
timers have gotten more reliable in HA recently with allowing them to restore after restart but using input_datetimes should always be at least as reliable than timers if not more.