I have a sensor that shows me my all-time high power for my solar panels. I want to make something that shows the date+time when this record first ocurred, but don’t know how to go about it. I’ve tried several iterations, but it either seems to result in an unknown, or shows the time/date when the sensor was updated by home assistant, which isn’t helpful in this case.
I would approach this using an input_number helper to hold the record high data and use: states.input_number.pv_max.last_changed
To retreave the date_time of the occurance. pv_max is just a place holder name it as needed.
EDIT: last_updated > last_changed my bobo
Thanks for your help. This isn’t something I’ve had to do before, so could you help me out with it please? Am I right in thinking I set the input number helper up as a kind of placeholder and then create an automation that updates that value? Also in your example, would I call the input number helper just pv_max, or the whole states.input_number.pv_max.last_changed?
Thanks again.
I’m still quite new to HA & I try to keep to simple solutions as I gain in knowledge so 123 Taras’ may be far more elegant than what is below.
HA equips the input_number helper with field last_changed. So:
if current pv_power > input_number.pv_max
input_number.pv_max = pv_power
endif
^^^ Sudo code ^^^
The above captures the max value and the last_changed field will retain the datetime of the latest maximum. All in the ‘input_number.max_pv’ helper. HA should never forget these as well. That may be also true with the template sensor example above though I’ve not proven that as yet.
The template output below demonstrates how to access the last_changed field and format it as human readable. It is using a helper on my instance.
Thanks for this. How will it work in practice? Will this record the record solar then keep the record+time and date separately? Then I just view sensor highest solar ever to view the time and date of the record?
The Template Sensor’s state value reports the highest value of sensor.givtcp_fd2319f222_pv_power. Its attribute named recorded contains the date and time (in ISO format) when the highest value was detected.