I’m a total newbie. I’m trying to get the time since last motion was detected. The tricky part is… I want this to be triggered by that motion sensor.
In other words when the motion will be activated I would like to get TTS saying how long ago the previous motion was detected, something like: ‘last motion was detected 4 hours ago’.
but that automation returns ‘Last motion detected 0 seconds ago’ since the trigger… changes the last_changed to current timestamp. How can I get the time between now and previous state change?
not solution to your code but a suggestion
? why dont you use -service: tts.google_say
you would need to store the last_trigger in a diferent sensor, as the trigger indeed was triggerred 0 seconds ago .
I thought maybe it’s because of the order - I first call the service to read state of entity_id: input_datetime.last_motion and after that I call the service to actually set it up - therefore I got NaN.
And I know the order is important, since I want to read timestamp of previous executions; But just for testing I switched the order like that:
I still got the same warning in the logs. - Unable to find referenced entities input_datetime.last_motion
Since this service create a new entity with entity_id: input_datetime.last_motion - Should I be able to find it in Developers Tools -> States -> Entities and be able to read it’s state and attributes?