I’m trying to create a notification with the estimated completion time of my washing machine… however I cant figure out how to add the remaining time to the current time
the remaining time is in the format H:MM as an attribute to sensor.washer
Ive tried loads of different combos of as_timestamp or .timestamp() but always resulting in type errors
ive had a good read through the EPIC time conversion topic, but still cant make this work. There are several other topics asking for similar things but cant find a working solution
Hello there. I’m digging this up, with the same usecase - dishwasher (SmartThings) time remaining. Unfortunately the code does note seem to work for me - it spills the following log:
ValueError: Sensor sensor.custom_dishwasher_time_remaining has device class ‘None’, state class ‘None’ unit ‘minutes’ and suggested precision ‘None’ thus indicating it has a numeric value; however, it has the non-numeric value: ‘“20:58”’ (<class ‘str’>)
My sensor definition in yaml:
#dishwasher remaining time
- platform: template
sensors:
custom_dishwasher_time_remaining:
friendly_name: "Pozostały czas programu"
value_template: >
{% set t = strptime(states('sensor.zmywarka_dishwasher_completion_time'), '%H:%M', today_at()).time() %}
"{{ as_timestamp(now() + timedelta(hours=t.hour, minutes=t.minute, seconds=t.second)) | timestamp_custom('%H:%M') }}"
icon_template: mdi:clock
I tried with " " and without it - effect is the same…
The error you have quoted does not match the configuration you have posted. Either this is not the actual configuration you are using, or you have erroneously pasted YAML configuration in the Template Helper editor’s “State template” field.
The output of the timestamp_custom() filter will cause the state value to be returned in the string format “HH:MM”, so you cannot specify a value for the unit_of_measurement. Sensors using unit_of_measurement are required to return a purely numeric state.
Regardless, the quotes on the last line should not be there, since they will cause the final expression to be returned in its entirety as a string and you will end up with a state like: {{ as_timestamp(now() + timedelta(hours=t.hour, minutes=t.minute, seconds=t.second)) | timestamp_custom('%H:%M') }} instead of 10:15.
Thank you. The truth is that it actually was a log message that appeared when I tried to add this template sensor (just without the “”). And it blew my mind, as I have no clue why would it appear in the first place… The funny thing is though, that I have not restarted the HA, but just reloaded the config yesterday.
When I resterted completely HA today, it went without any hiccup. Anyhow, thanks again for the effort of replying to me!