frontend icon indicating copy to clipboard operation
frontend copied to clipboard

UI Testing of Automation Conditions Does Not Work with Template Conditions

Open marlemion opened this issue 2 years ago • 63 comments

The problem

In order to implement a somewhat more complex template condition, I came across the problem that (at least testing) templates conditions do not work (anymore).

What I did:

Create a simple automation having a template condition:

  - condition: template
    value_template: "{{ 1 > 2 }}"

So, this is extremely simplifed. The expression should return False, but instead I get the following error when testing this expression in the condition frontend (under automatisations):

Error handling message: template value should be a string for dictionary value @ data['value_template']. Got None (invalid_format)

If I enter the same snippet of code in the templates section un der developer tools, it prints false.

Either there is a problem in the code just adding the template condition in the automatisation frontend or something is completely borked.

What version of Home Assistant Core has the issue?

2022.4.1

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant Container

Integration causing the issue

Automation

Link to integration documentation on our website

No response

Diagnostics information

No response

Example YAML snippet

- condition: template
    value_template: "{{ 1 > 2 }}"

Anything in the logs that might be useful for us?

2022-04-08 14:40:54 ERROR (MainThread) [homeassistant.components.websocket_api.http.connection] [140209354674720] Error handling message: template value should belue_template']. Got None (invalid_format)

Additional information

No response

marlemion avatar Apr 08 '22 13:04 marlemion

Same issue here!

Egglestron avatar Apr 08 '22 21:04 Egglestron

Just to be clear, in my experience it's only the actual test button that doesn't show the correct result, the template itself and the automation condition still work as expected.

Plawasan avatar Apr 11 '22 06:04 Plawasan

I am new to Home Assistant, but I am having what I believe to be the same issue. I am attempting to trigger off the following value_template “{{ is_state_attr('fan.fanlinc_51_d1_37_fan', 'percentage', 33) }}” . The trigger never runs. But it returns the correct true or false in the developer tools, and it gets this error message from test if I try to use it as a condition instead of a trigger: "template value should be a string for dictionary value @ data['value_template']. Got None". So the difference for me from what Plawasan commented is that the automation does not trigger as I would expect it to when using the value_template as a trigger, and if I trigger on the device state change, and add the template as a condition, it appears that the condition is not satisfied and the automation doesn't trigger. This is 2022.4.5 running in a VM using VMWare Player 16.

wwsmithobut avatar Apr 20 '22 18:04 wwsmithobut

I am having exactly this issue with automations that worked in earlier versions (although I cannot tell you what version this started showing up). These automations show up in the log file as an Error evaluating condition, same with using the test buttons although conditions are satisfied with developer mode.

The conditions take the form of:

{{ ( as_timestamp(now()) - as_timestamp(states.automation.automation_name.attributes.last_triggered) |int(0) ) > 86400 }}

let me know if there is anything useful I can add.

analogmonster avatar Apr 21 '22 02:04 analogmonster

I have the same issue:

condition: template value_template: '{{is_state (''input_boolean.watering'',''on'')}}'

JayRHa avatar Apr 22 '22 09:04 JayRHa

Same here, was thinking that my template doesn't work but it seems like it's a bug in UI

ernst77 avatar Apr 28 '22 07:04 ernst77

Same

pickonedev avatar Apr 28 '22 21:04 pickonedev

I'm getting that same error on this condition:

{{ (states.sensor.wk_temperatuur_vloerverwarming_cv_in|float(999.0) - states.sensor.wk_temperatuur_vloerverwarming_vloer_uit|float(0.0)) <= 1.0 }}

Bert-R avatar Apr 29 '22 17:04 Bert-R

Don't use the test "feature", go to Template and test it there, better this way, till they will fix it...

pickonedev avatar Apr 29 '22 17:04 pickonedev

I have the same issue

ha 2022.4.5 on Ubuntu 20.04.2 LTS

kjt407 avatar Apr 30 '22 09:04 kjt407

I have the same issue

ha 2022.4.5 on Ubuntu 20.04.2 LTS

I have the same issue

ha 2022.4.5 on Ubuntu 20.04.2 LTS

Currently updated to 2022.4.7 the problem is still

kjt407 avatar Apr 30 '22 09:04 kjt407

Same issue 2022.4.7 on Hyper-V

encor50 avatar May 04 '22 06:05 encor50

I'm having the same issue

image

Stefan-OJ avatar May 04 '22 08:05 Stefan-OJ

Same here, in my case the error blocks the condition of the automation, so the automation does not start when it should. It was working fine in previous HA versions, so I can confirm it's a bug introduced in the last couple of months maybe.

gfrancesco avatar May 10 '22 12:05 gfrancesco

Oh my gosh I've been wracking my brains over this for past hour until I stumbled upon this bug report - didn't realise but YES what I've been dong IS working, it's just the editor that's popping up the error.

Tillsy avatar May 22 '22 01:05 Tillsy

Same problem here this template in developer tools works good, but in automation return an error: {{ states.sensor.uptime_raspberry_tv.state | float < 30 }} The error is template value should be a string for dictionary value @ data['value_template']. Got None

antoweb avatar May 22 '22 06:05 antoweb

Same here, in my case the error blocks the condition of the automation, so the automation does not start when it should. It was working fine in previous HA versions, so I can confirm it's a bug introduced in the last couple of months maybe.

That will be something else, because the templates regarding this issue will work fine in the automation. It is just the test button which throws an error. Put your template in developer tools > templates and check if it works there

TheFes avatar May 22 '22 17:05 TheFes

I have this problem too. Is there anything being done about it?

Nick4-1 avatar May 30 '22 18:05 Nick4-1

I have also experienced this problem with well-formed templates that work in the Developer Tools section and in actual automations.

WayneManion avatar Jun 01 '22 21:06 WayneManion

Same problem on 2022.6.1

lorenzo-deluca avatar Jun 04 '22 08:06 lorenzo-deluca

Same Problem! Home Assistant Core 2022.6.1 Home Assistant Supervisor 2022.05.3 Home Assistant OS 8.1

Guenni75 avatar Jun 04 '22 13:06 Guenni75

Same Problem, unfortunately. Home Assistant Core 2022.6.4

struikc avatar Jun 09 '22 10:06 struikc

I am having the same issue however my automation does not run. The template statement works in Dev tools but not in the automation

petebanham avatar Jun 10 '22 19:06 petebanham

@petebanham: my automation also stopped working. Have a look at https://community.home-assistant.io/t/automation-template-value-should-be-a-string-for-dictionary-value-data-value-template-got-none/419519

Can anyone explain why nothing is being done about this as I don't understand how this works/when/how it gets addressed.

Nick4-1 avatar Jun 10 '22 21:06 Nick4-1

Having same issue still on 2022.6.5. My automation does not trigger, but the template checks out fine in dev tools.

markdepalma avatar Jun 12 '22 18:06 markdepalma

I have a simple template to evaluate the battery level of my Shark vacuum.

{{state_attr('vacuum.vicky', 'battery_level') > 85 }}

In the Dev tools -> Template I get a true or false response as expected. In an automation window get the error:

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

isewise avatar Jun 12 '22 21:06 isewise

I too ran into the same issue (HA 2022.6.3), and have made an observation which may be useful to those with the necessary insight into the inner workings of the automation function. I have a temperature sensor on my water heater, and control over the element, and I also set up an input_number slider to control the target temperature. Switching off uses the following template in the trigger section:

{{
  states('sensor.geyser_temperature')|float >=
  states('input_number.geyser_target_temp')|float
}}

I.e. trigger when the actual temperature equals or exceeds the target. And this works just fine, both simulated in Dev Tools, and in operational practice.

HOWEVER

The element is switched on at a specific time (and/or when the solar panels are producing nicely), but we need to check that the water is actually cold before doing so: hence we take that very same code above, just changing the comparison to a less-than <, and put it in the Conditions section, instead of in Triggers, and immediately we get the same error:

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

So it seems to work as a Trigger, but not as a Condition. (Also, less importantly, the Test function is available right in the Automation UI editor for template code added under Conditions, but not under Triggers. To this untrained eye the two seem rather similar, so it was natural to wonder if there is maybe some structural variation under the hood necessitating this difference, and if this perhaps also pertains to the difference in behaviour that is observed.)

With much respect and gratitude to those who labour on behalf of us unwashed masses, to make the world a better, or at least more automated and entertaining place.

JohanViljoen avatar Jun 13 '22 05:06 JohanViljoen

@JohanViljoen it will also work as a condition, it is just the check button which will display the error, the condition will actually work fine.

For testing triggers in the GUI it works different, as a trigger is just a moment where something turns from false to true it makes no sense to have a similar button as on a condition. When the trigger occurs, the GUI will show a green bar which you can click to show the details.

TheFes avatar Jun 13 '22 08:06 TheFes

Wow, I was debugging some automatisation code for over an hour what appears to be OK code all along! Damn! HASS OS 2022.6.4

sammyke007 avatar Jun 13 '22 19:06 sammyke007

Same problem here: core version 2022.6.6

tomkennedy513 avatar Jun 15 '22 02:06 tomkennedy513