How to get a timestamp from a measurement in the past

Let’s say I have a sensor that generates a vaue - in this case, a powerwall. I can look it’s history graph and see the value rise and fall.

Is there a way in jinja to get the timetamp of when the value changed a certain way? For example:

“when did the value of this sensor go from zero to below zero and stay there for more than 5 minutes?”

It it even possible to make such a query in jinja?

I would say no, but I’m not a Jinja master.
But an automation can trigger on the state you are talking about.

Hum, I wonder if I could then use an automation to write a value somewhere to make that timestamp happen?

Perhaps if jinja had some kind of long term variable storage? or if an automation could write to a file?

You could set a datetime helper.
Or an input text.
Or write to a file (I guess is possible).

It depends on how this is being used later I guess.

File: File - Home Assistant

Example usage: Save state to text file - #4 by chairstacker

1 Like

My use case is this thread here: Calculating "powerwall survivability"

I’m trying to calculate “will my powerwall survive the night on battery and not go to grid before the sun comes up the next day”

To do this, one of the datapoints I need to find is “when do the solar panels get to a point they are generating more than the house needs, and power is flowing into the battery” - which is pretty easy to spot on the powerwalls graphs, but pretty hard to translate into a jinja query.

Ok… so you need this value in automations/calculations later.
Then use a input datetime

1 Like

Excellent, thanks!
Once I set this up, I’m presuming the result will be something like this: How do I show timestamps for the two states of the one switch? - #9 by mobisat - a sensor which is essentially just a log of timestamps.

Is there a way in jinja to query the last few days, and average the timetamps together?