Hi all,
I try to use this script in order to get the ‘resttime’ of my washingmachine into a sensor with value_template:
- platform: template
sensors:
wasmachine_tijd_verschil:
friendly_name: "Wasmachine Tijdverschil"
value_template: >-
{% set tijdstring = states('sensor.wasmachine_completion_time') %}
{% if tijdstring not in ['unknown', 'unavailable', 'none'] and tijdstring | length > 0 %}
{% set tijd_utc = as_timestamp(tijdstring) | float(0) %}
{% set nu_utc = utcnow().timestamp() | float(0) %}
{% set verschil = nu_utc - tijd_utc %}
{% if verschil < 0 %}
{% set resterende_tijd = (-verschil) | timestamp_custom('%H:%M:%S', false) %}
"{{ resterende_tijd }}"
{% else %}
{{ verschil | timestamp_custom('%H:%M:%S', false) }}
{% endif %}
{% else %}
"Geen data"
{% endif %}
unit_of_measurement: "HH:MM:SS"
Unfortunately I receive an ‘Unknown’ return with following log:
ValueError: Sensor sensor.wasmachine_tijd_verschil has device class ‘None’, state class ‘None’ unit ‘HH:MM:SS’ and suggested precision ‘None’ thus indicating it has a numeric value; however, it has the non-numeric value: '# Sensorwaarde als UTC timestamp
# Huidige tijd in UTC
"Over 00:39:58"' (<class 'str'>)
Is there anyone who can help me out ?
Much appreciated !!!
Kr,
Bart