And using that as the trigger, then setting the time and state change to “home” as the conditions, but this seems like it might be really resource intensive?
I’ve also thought about using the state change as a trigger and the sensor as a condition, but in both approaches I’m concerned about the asynchronous nature of trying to use my device_tracker’s state change from not_home to home, while also using the not_home state in the binary_sensor’s 24 hour counter
Then create a new automation that triggers on your device tracker, just that nothing more.
Then the condition should be away. By some reason I have much better success with this method opposed to just using it as the trigger. Don’t ask me why.
And the action is update the input_datetime with the current datetime.
trigger:
- entity_id: device_tracker.YOUR_DEVICE TRACKER
platform: state
condition:
- condition: state
entity_id: device_YOUR_DEVICE TRACKER
state: away
action:
- data:
datetime: '{{ now().strftime(''%Y-%m-%d %H:%M:%S'') }}' # I don't know why this is repeating but it works....
data_template:
datetime: '{{ now().strftime(''%Y-%m-%d %H:%M:%S'') }}'
entity_id: input_datetime.YOUR_DATETIME
service: input_datetime.set_datetime
Then in your automation condition you can use something like this too see if it’s past 24 hours.
turn on automation 2 (with automation_turn.on action) if you are away for 24 hours. Use the trigger as away for 24 hours. Automation 1 can then have 2 primed for your trigger of arriving home ie
trigger:
- platform: state
entity_id: person.seana
to: 'not_home'
for:
hours: 24
the automation you have now. With the last step in the automation to disable itself with automation.turn_off.
I use a similar approach to let me know if my kids return home, but only if they have been away for more than an hour (to handle false not_home from tracking and for going for a jog etc).
Thanks - those are all much more workable than my ideas. I like the idea of the input boolean as then it’s also a no-brainer to be add to a dashboard if needed.
As a bonus, I’ve also learned about adding a condition to an action as a result of this. I moved the time condition from the condition block to the action block because while I always want to turn the boolean off when I return home, I only want to turn the switch on between certain hours.
For anyone interested, here’s where I am at present (testing with notifications instead of turning the switch on at present).
automations.yaml:
- id: '1589436412117'
alias: Away for 24 Hours
description: ''
trigger:
- entity_id: device_tracker.my_s10
for:
hours: 24
platform: state
to: not_home
condition: []
action:
- data: {}
entity_id: input_boolean.away_24hrs
service: input_boolean.turn_on
- id: '1589442878882'
alias: Home After 24 Hours
trigger:
- entity_id: device_tracker.my_s10
platform: state
to: home
condition:
- condition: state
entity_id: input_boolean.away_24hrs
state: 'true'
action:
- entity_id: input_boolean.away_24hrs
service: input_boolean.turn_off
- data:
message: Welcome home
title: 24 hour boolean on
service: notify.mobile_app_sm_g975f
- after: '6:00'
before: '11:00'
condition: time
- data:
message: Welcome home
title: Time condition correct
service: notify.mobile_app_sm_g975f