tplink kasa, smart motion dimmer, the auto time off value is the default length of time when someone turns it on, so it never changes.
It seems the time it is going to turn off is stored as a timestamp, which I’d hoped would be easy as pie to throw into a template and then just check that value … but nothing with templates is ever as easy as pie for me it seems.
I work with Kubernetes. I do golang templating all day. I have no idea why it fights with me so badly when it comes to Home Assistant
Anyway -
states.sensor.bathroom_fan_auto_off_at = <template TemplateState(<state sensor.bathroom_fan_auto_off_at=2025-06-12T20:39:55+00:00; device_class=timestamp, friendly_name=Bathroom Fan Auto-off at @ 2025-06-12T16:30:19.618571-04:00>)>
state_attr('sensor.bathroom_fan_auto_off_at', 'device_class') = timestamp
yay
state_attr('sensor.bathroom_fan_auto_off_at', 'sensor.bathroom_fan_auto_off_at') = None
though, and
state_attr('sensor.bathroom_fan_auto_off_at', 'bathroom_fan_auto_off_at') = None
too
Once I have that, I’m hoping I can throw it in one of those numeric template thingies in my config to just spit out the number of minutes remaining. I’m hoping this will yield that?
Before helping you, I would like to know if you have read at least the first few sections of the Templating documentation? Specifically the States section?
The reason why I ask is because the template examples you posted contain fundamental errors.
You will need to use Home Assistant’s terminology because it’s unclear where you want to use the template. Perhaps in a Template Sensor helper or a Template Condition?
Copy-paste the following template into the Template Editor (Developer Tools ->Template) and let me know what it reports.
I’ve read so much. I’ve fought this battle so many times. That page looks familiar, but, fresh, or perhaps thoroughly-beaten eyes looking at it again today, yes, seeing some things of note. Honestly most of what I do and have done for 30 years of an IT career is just piece things together from examples until they work. It’s usually a pretty successful method - especially when you are expected to know a massive breadth of things, languages, etc., and really can’t go deep on all of them.
Looking at that, and trying this instead though - {{ states('sensor.bathroom_fan_auto_off_at') }}
does seem to be yielding just the timestamp!
I’m sorry, I don’t know what it’s called, again, cobbled some examples together last time and got something working. The NVMe wear one is the working on, the other was my first crack at the new one before going to the template editor to test (which, actually, it doesn’t even look like I got as far as updating the variables in).
sensor:
- platform: template
sensors:
nvme_wear:
friendly_name: "NVMe Wear"
value_template: "{{ state_attr('binary_sensor.hdd_smart', 'percentage_used') }}"
bathroom_fan_ttl:
friendly_name: "Bathroom Fan Time To Live"
value_template: "{{ state_attr('binary_sensor.hdd_smart', 'percentage_used') }}"
-152.61707592010498
I’m guessing that is seconds remaining, and I’m guessing that is exactly what I am looking for for my ‘template thingie’ … thank you so so so very much. As I cobble together more examples I’ll eventually become self-sufficient, I swear, it really does work.