Timecalculation Washing Maching - not working - something about the device class?

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

Anyone ???

Your output is a string. Strings cannot have a unit_of_measurement. Any sensor having a unit_of_measurement must be numerical. That is waht the error sais. So remove that line and try again.

I did not check your entire template, however the output does not seem to mach the template you show. Have you tested that in developer tools? It does seem overly complicated and error prone converting to timestamp. What is the output of the sensor you calculate from?

That did the trick ! Thanks a lot @Edwin_D !

1 Like