I’m trying to track when my car was last charged to 100%. I’ve currently got a stats sensor that tells me the max values within the past 2 weeks which is good enough for automations; but for my dashboard time since last at 100% is what I actually want to see.
I was thinking of creating a templated binary sensor that’s true when the battery is at 100% and using its last changed state but last changed doesn’t persist through restarts so that’s useless.
You need a helper for date and time and then you need to set up an automation for when the sensor for charging reach 100% to then set in the current time in the date_time helper.
This will give you the time the car was last fully charged.
If you need to then have it as a difference between current time and that helper value, then you can make a template sensor that just subtracts the helper value from current time or you can do that directly in the lovelace card also.
Create a Trigger-based Template Sensor that detects when the car’s charge is 100% and sets its state value to the current date and time. The value will be retained, even after a restart.
The relative_time function can be used to report elapsed time.