Error occurred while testing condition: template value should be a string for dictionary value @ data['value_template']. Got None

Dear community,

a couple of days ago, I updated to 2022.7.5. I now realised that one of my automations is not running anymore. When I test my template conditions, I always get the same error:

template value should be a string for dictionary value @ data[‘value_template’]. Got None

My template conditions:

{{ not is_number(states('sensor.openweathermap_uv_index')) }}

or

{{ 1.5 > states('sensor.openweathermap_uv_index')|float(0) >= 1.0 }}

or

{{ 1.0 > states('sensor.openweathermap_uv_index')|float(0) }}

or

{{ ( 2.0 > states('sensor.openweathermap_uv_index')|float(0) >= 1.5 ) and ( states('sensor.dachzimmer_temperatur')|float(none) > 22.5 )}}

Can anybody please help? What do I need to change?

best regards,
Chris

There is a bug in the condition test tool in the GUI automation editor… it does not work with template conditions. This doesn’t affect the actual function of template conditions in automations, it’s just the tester that’s broken.

Your templates look fine. What does the automation trace show for the one that isn’t working as expected?

Oh, lucky me, I did ask before messing it up…

Well, my automation is managing the roof-window-shutters. This morning, they should have closed, but they didn’t. I tried to have a look at the trace, but I could not figure out, why it didn’t work in the morning. In the afternoon, it was working fine.
4 guesses:

  • my wife worked against the automation
  • my kids played with the shutters
  • one of the input values did not provide a number, but a string
  • any combination of the three above

Do you mind having a short look at my configuration and checking, if my error handling - in case there is a string instead of a number - should work?

input sensor 1: UV-index by api

input sensor 2: indoor temperatur by mqtt-sensor

mqtt:
  sensor:
    - name: "Dachzimmer Temperatur"
      unique_id: "mqtt.Dachzimmer.temp"
      state_topic: "tele/D1mini/Dachzimmer/SENSOR"
      device_class: "temperature"
      unit_of_measurement: "°C"
      value_template: "{{ value_json.DHT11.Temperature | float(none) }}"
      state_class: "measurement"

(this is in a splitted config-file mqtt.yaml - so never mind the indentation)

Automation:

alias: Dach Rollo Management v4
description: |-
  Based on UV-index, window shutters are opened/closed in 4 steps.
  no number -> stop 
  0 - 1.0 -> fully open
  1.0 - 1.5 -> 1/3-closed
  1.5 - 2.0 -> 50%-closed
  2.0 - 2.5 -> 2/3-closed
  2.5+ -> 100%-closed
trigger:
  - platform: state
    entity_id:
      - sensor.openweathermap_uv_index
    for:
      hours: 0
      minutes: 0
      seconds: 0
  - platform: numeric_state
    entity_id: sensor.dachzimmer_temperatur
    for:
      hours: 0
      minutes: 5
      seconds: 0
    above: '22.5'
condition: []
action:
  - choose:
      - conditions:
          - condition: template
            value_template: '{{ not is_number(states(''sensor.openweathermap_uv_index'')) }}'
        sequence:
          - stop: UV-Index liefert keine Zahlenwerte.
            error: true
      - conditions:
          - condition: template
            value_template: '{{ 1.0 > states(''sensor.openweathermap_uv_index'')|float(0) }}'
        sequence:
          - service: script.dach_rollos_auf_2
            data: {}
      - conditions:
          - condition: template
            value_template: >-
              {{ 1.5 > states('sensor.openweathermap_uv_index')|float(0) >= 1.0
              }}
        sequence:
          - service: script.dach_rollos_33_zu_2
            data: {}
      - conditions:
          - condition: template
            value_template: >-
              {{ ( 2.0 > states('sensor.openweathermap_uv_index')|float(0) >=
              1.5 ) and ( states('sensor.dachzimmer_temperatur')|float(none) >
              22.5 )}}
        sequence:
          - service: script.dach_rollos_50_zu_v2
            data: {}
      - conditions:
          - condition: template
            value_template: >-
              {{  (2.5 > states('sensor.openweathermap_uv_index')|float(0) >=
              2.0 ) and ( states('sensor.dachzimmer_temperatur')|float(none) >
              23 ) }}
        sequence:
          - service: script.dach_rollos_66_zu_v2
            data: {}
      - conditions:
          - condition: template
            value_template: >-
              {{ ( states('sensor.openweathermap_uv_index')|float(0) >= 2.5 )
              and ( states('sensor.dachzimmer_temperatur')|float(none) > 24 ) }}
        sequence:
          - service: script.dach_rollos_zu_2
            data: {}
    default:
      - stop: no significant change in state
  - delay:
      minutes: 15
mode: single
max_exceeded: silent

The automation is triggering different scripts, which set the shutters of two Velux shutters via the Velux integration and a shelly 2.5 via mqtt.

script example

alias: Dach Rollos 66% zu v2
sequence:
  - if:
      - condition: template
        value_template: >-
          {{ not ( 38 >= state_attr('cover.velux_rollo_nord_2',
          'current_position') >= 28 ) }}
    then:
      - service: cover.set_cover_position
        data:
          position: 33
        target:
          entity_id: cover.velux_rollo_nord_2
  - if:
      - condition: template
        value_template: >-
          {{ not ( 33 >= state_attr('cover.velux_rollo_sud', 'current_position')
          >= 28 ) }}
    then:
      - service: cover.set_cover_position
        data:
          position: 33
        target:
          entity_id: cover.velux_rollo_sud
    else: []
  - choose:
      - conditions:
          - condition: template
            value_template: >-
              {{ state_attr('cover.lukarne_rollo', 'current_position') > 33 and
              not ( 38 >= state_attr('cover.lukarne_rollo', 'current_position')
              >= 28 ) }}
        sequence:
          - service: cover.set_cover_position
            data:
              position: 33
            target:
              entity_id:
                - cover.lukarne_rollo
          - wait_template: '{{ not states("cover.lukarne_rollo") in ["opening", "closing"] }}'
            timeout: '00:01:00'
            continue_on_timeout: true
          - service: cover.open_cover
            data: {}
            target:
              entity_id: cover.lukarne_rollo
          - delay:
              hours: 0
              minutes: 0
              seconds: 0
              milliseconds: 400
          - service: cover.stop_cover
            data: {}
            target:
              entity_id: cover.lukarne_rollo
      - conditions:
          - condition: template
            value_template: >-
              {{ state_attr('cover.lukarne_rollo', 'current_position') < 33 and
              not ( 38 >= state_attr('cover.lukarne_rollo', 'current_position')
              >= 28 ) }}
        sequence:
          - service: cover.set_cover_position
            data:
              position: 33
            target:
              entity_id:
                - cover.lukarne_rollo
          - wait_template: '{{ not states("cover.lukarne_rollo") in ["opening", "closing"] }}'
            timeout: '00:01:00'
            continue_on_timeout: true
          - service: cover.close_cover
            data: {}
            target:
              entity_id: cover.lukarne_rollo
          - delay:
              hours: 0
              minutes: 0
              seconds: 0
              milliseconds: 500
          - service: cover.stop_cover
            data: {}
            target:
              entity_id: cover.lukarne_rollo
    default: null
mode: single
icon: mdi:window-shutter-open

(As the shelly does not provide a tilt, I need to check, if the blinds are going up or are comming down. Hence the complicated script. :slight_smile: )

What would happen, if the input sensors do not provide a number, but a string, such as “none” or “unknown”? Any feedback is highly welcome.

Chris

Update: this morning, the automation did not run as expected. I had a close look at the trace:

  1. red arrow: what does this “error: true” mean?
  2. the template conditions are formated differently. (compare orange vs. green) The green ones seem to work, the red ones don’t. The same formating is seen in the code of the automation. Is this meant to be like this?

EDIT: the “error: true” is because I set the option in the GUI…

EDIT2: I need to check in detail, but I think its the order of the choose-conditions. if UV-value rises fast in the morning, but inside temperature is still low, none of my conditions is met and therefore, the default-option is true. → I will re-order my conditions and make them more open, so that every possible combination of UV-index and inside temperatur will trigger something.