I’m looking for a way how I can calculate the time between 2 events as a condition for automation.
My scenario is:
Using Locative, when arriving home - check (the condition) if locative state “work” was active 30 minutes ago or less, run the script.
I’m trying to automate and run the scenario only if I go directly from work to home.
My idea here would be to create a hidden input_boolean which goes off if locative changes to work and on if locative changes from work to something else. This way you could check with the last state change attribute when the input_boolean was last changed.
At least I think this is how it works. No guarantee tho!
Why to have input boolean if i can see the status change of Lovative itself ? It changing from home/work (location name) to not_home. I just don’t know how (in code) I can get the previous status change and to make mathematics manipulation/calculation with it.
My bad I added that because I thought the state of locative is updating on a regular basis like owntracks but it only changes states when entering /exiting somewhere.
To calculate times take a look at templating and the jinja2 filters available in HA.