Automation: template value should be a string for dictionary value @ data['value_template']. Got None

A condition in my automation gives errors and I cannot understand what is wrong with it.

condition: template
value_template: >-
  {{(states('sensor.maxtemp24h') | float -
  states('input_number.some_variabele') | float)>0}}

My intention was to only do the action part if sensor.max24h minus input_number.some_variable is greater than 0.
Whenever I put in the jinja template in the template section of the developer tools I get a true as a outcome. So in my opinion this should work…

The error I get is :

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

Any ideas ?

1 Like

Two things:

  1. Make sure your entity ids in the template match the actual entity ids. For example, is the misspelling of “some_variable” intentional?

  2. Assign defaults to your floats i.e. float(0).

Well, in Dutch it isn’t a misspelling :slight_smile: . It was a Dutch variable name but I changed it just before posting.
I forgot to mention in the OP that my code works in the template section of the developer tools and it returns true.
For sanity I’ve add the default zero but unfortunately this doesn’t seem to help…

This is an issue with the automation editor, not your template.

13 Likes

Seriously? wow. I’ve spent so much time trying to fix this trying to rewrite my template :rofl:
Thanks!

OMG I was spending so much time with this one too LOL

1 Like

I’m facing this problem too…

Even though @tom_l his answer is marked as the solution, it’s the explanation/reason for the problem not a fix.

Yeah a fix hasn’t been merged yet but at least the issue is known. Don’t let it go stale.

3 Likes

What does that mean in this context?

Is this considered as a bug?
There seem to be no activity on GH towards solving it…

2 Likes

@ with this problem: is(are) your automation(s) still working?

I am having this issue and my automations do not work…

1 Like

Can somebody please explain what this error means?

BTW: the solution refers to a GH thread that has not been assigned so it it solved?

@pathia: did the GH thread solve this for you?

Well, it is only a issue in the automation editor when editing and testing. Just test your templates in the developer section (templates tab) and all should work fine.
So the GH link doesn’t help me but I learned to live with the issue :grinning:

Just got bit by this after spinning a lot of cycles trying to figure out what I’m doing wrong. This is a pretty bad UI situation here, if you’re going to offer a TEST button, it’s probably better if it returns valid results.

I’d posit that returning invalid results is worse than not offering a test function at all.

1 Like

I just tried to create an automation to check every half hour if my temperature was 3 degrees higher than the thermostat is set (having breaker issues).

The template works fine in the template editor. When I put it in the automation, it always shows true and has the error when I test it.

I’ve noticed that when I switch to yaml, it adds extra characters after the “value_template:” section. (Same as in OP, it makes it “value_template: >-”)

This is my yaml entry (after editing):

condition: template
value_template: >-
  {{states.climate.main_thermostat.attributes['current_temperature'] >
  (states.climate.main_thermostat.attributes['temperature']+3)}}

When I edit it, I set it to:

condition: template
value_template:  
  {{states.climate.main_thermostat.attributes['current_temperature'] > (states.climate.main_thermostat.attributes['temperature']+3)}}

The automation always triggers.

Ok… Well, it seems to work when it triggers itself. When I hit “Run Action”, it reads the condition wrong (or else doesn’t even evaluate the condition?).

When you hit “Run Actions” it does what it says, runs the actions. Nothing to do with conditions or triggers.

If you want to test the automation including conditions go to Developer Tools → Services and use the Trigger Automation service. It has an option to skip conditions that you can turn off.

Maybe my experience with this will help others. I had the same problem: the “template value should be a string for dictionary value” error message obscured things but @pathia last tip helped: calling the trigger service without skipping conditions revealed the condition was in fact not working.

My previous condition template:

"{{ now().month >= 5 or now().month <= 9 }}"

My working one:

{{ now().month >= 5 or now().month <= 9 }}

So, removing the quotation marks was necessary because home assistant automatically adds single quotation marks .

2 Likes