Condition template in automation not working

i want to do an action if the value of a sensor equals an input_number. To acomplish this i tried in an automation the following code:

condition:
  condition: template
  value_template: "{{ (states('sensor.input_copy')) | int(0) == (states('input_number.awt_optimalisatie')) | int(0) }}"

It works in developers->template but in the automation i got the error “Error in describing condition: Cannot read properties of undefined (reading ‘includes’)”

Obviously i am doing something wrong, but what?

Template Rule #1

Hi. Please format your code by putting it in a code block </> in the editor menu. Indenting matters, and it gets destoyed by the forum this way. Plus I’m pretty sure this won’t work in the template tester:

First of all, templates need to be in quotes if you put them in a single line in yaml. Plus your template starts with three { instead of two.

Then:

It seems there is a space in there that should not be there. That means the states function does not return a number because the entity does not exits. The next problem is that

will error in an automation if what is left is not a number - developer tools is more forgiving. To prevent it, provide a default for int:

condition:
  condition: template
  value_template: "{{ (states(‘sensor.input_copy’)) | int(0) == (states(‘input_number.awt_optimalisatie’)) | int(0) }}"

I am very sorry for my formatting! I corrected my first post.

The code still gives an error: “Error in describing condition: e.includes is not a function”

The first condition: should be conditions:

Sorry does not work, but the error changes in: "
Error in describing condition: Cannot read properties of undefined (reading ‘includes’)"

I think the problem is outside what you show us. I suspect you are including your own yaml automations? My advice would be to write the automation in the automation editor and check the yaml from there to see how the yaml should look. When doing that, the outer quotes from the template must be removed.

But as said, the problem is most likely no longer in what you show us, but i. how you try to add it to your configuration.

It works by adding the code in the automation editor!