when making an ‘automation’, while using the ‘state’ trigger, it is possible to state a ‘for’ argument.
for example - when the ‘state’ of a my phone turns to ‘home’ ‘for’ some period of time, lets say - 5 min.
is there a way to make a sensor that will show that time?
for now i use a “workaround” for that, as i create a counter/timer with same timespan and same trigger, but would love for more creative ideas, if any of you got any.
thanks for the quick reply!
i think i understand what you say - and it really is the “other way around”…
so… basically, instead of trying to get a “sensor” out of the state of an entity, i should based the “for” condition with something more visually representable, and use that as the “for” argument ?
could you please give a more suitable example to what i am trying to achieve in my description, so i can better understand how to implement this to my situation… ?
this is indeed very different from what i was trying to accomplish in the first place, but it gave me some new ideas to try out - thank you for your replay and for that explanation. i appreciate your time.
ill do some further experimenting and worst case scenario - i know how to write back (again)…
cheers!
ill be happy to, but i am not sure that it really applies to the question i presented in the headline, and therefor might be a little misleading…
don’t get me wrong - you helped me a lot, as your answer did give me some ideas to better address my problem.
but maybe ill try to better explain myself as to the original question i had in mind.
originally, i wanted a presentable time sensor to show the passing time for an entity state.
lets say, when my smart watch state turns “home” after it connected back to my wifi (via the router integration) - can i make a sensor that will show "how much time have passed since it turned to “home” state?
and when it changes to “not_home” - can that sensor show the time passing for that new state?
i want to create some automations that will allow things to happen only if that time (since the state changed to “home”) is “less than” 5 minutes… (like you can do with “numeric state”).
so when i get home, things could happen but only within a time frame of 5 min since i got home and that state had changed to “home”.
as i wrote, till now i am using “timers helper entities” that r being trigger simultaneously with those state changes, and using those timer entities as “numeric state” argues.
i thought there might be a way to extract those values from the secondary info of that smart watch entity state, instead of using “timer helpers”.
hope i m explaining myself better this time.
meanwhile, thanks for everything so far man
cheers
create a helper sensor of type date time.
create an automation that detect the state change an save the time in the helper date time.
As now you have the moment when the change is produced is easy to know how much time has elapsed. You only need to make a substraction between now and the time stored in the helper using template.
Anyway, i think you don’t need that for what you are explaining. Hava a look at state trigger:
You can make a triker that fires once some device changed it state and keep that state for a certain ammount of time.
automation:
trigger:
- platform: state
entity_id: device_traker.my_phone
# Must stay "home" for 5 minutes
to: "home"
for: "00:05:00"
great minds think alike… or, at list, we are in sync my friend - as your solution is exactly what i have been doing to address this issue so far.
the idea behind the headline question was to find a way to extract that info from the entity state, instead of creating helpers and more automatizations.
and i believe you are correct regarding the “state automation trigger”. its been working for me under the “not” condition, which have a similar affect as “less than”.
condition: not
conditions:
condition: state
entity_id: “device_tracker.entity_id”
state: home
for: ‘00:02’
meaning:
when the entity_id state is not home for 2 mins.
so state can be “not_home”, or “home” for less than 2 min, and the condition will identify as = “true”
as i mentioned - that what i’m doing so far. but still wanted help finding the way to extract time to a template from the entity state.
if there is no way to do that, your previous post is the best “workaround” i could find.
Have a look at next two examples. I take both from the documentation link I’ve sent you.
First one fires when is at home for 5 minuntes. Second one will fire when not at home for 5 minutes. Pay atention that we are detecting changes from “home” state to another one, so in fact that is the same as “not home”.
automation:
trigger:
- platform: state
entity_id: device_traker.my_phone
# Must stay "home" for 5 minutes
to: "home"
for: "00:05:00"
automation:
trigger:
- platform: state
entity_id: device_traker.my_phone
# Must stay "not home" for 5 minutes
from: "home"
for: "00:05:00"
Pay attention at the second example of the section Holding a state: