Help with value template- error: string for dictionary value

i am triing to build a condition in an atomation but i get always the following error.
I try to compare the humidity of two sensors.

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

what´s my mistake?

my condition:

condition: template
value_template: >-
  "{{(states.sensor.sensor.absolute_humidity_draussen_absolutehumidity.state) |
  float > (states.sensor.absolute_humidity_garage_absolutehumidity.state) |
  float }}"

Maybe the states.sensor.sensor… in the first entry?

1 Like

That’s a bug in the Automation Editor (and to many sensor domains in your code I think, as kbrown01 already said).

If you like, you can change your code that way:

          {% set a = states('sensor.absolute_humidity_draussen_absolutehumidity') |float(0)  %}
          {% set b = states('sensor.absolute_humidity_garage_absolutehumidity') |float(0) %}
          {{ (a > b) }}

will return true or false.

Avoid using states.sensor.temperature.state , instead use states('sensor.temperature') . It is strongly advised to use the states() , is_state() , state_attr() and is_state_attr() as much as possible, to avoid errors and error message when the entity isn’t ready yet (e.g., during Home Assistant startup).

Source: Templating States

1 Like

Many thanks a lot!!
. Yes the skipt works but only the “Test Template” button was the issue.