Trigger template works on template editor but log gives error anyway

As title, i cannot figure out what’s the problem, this is the relevant portion of code:

    trigger:
      - platform: template
        value_template: {{ (state_attr('binary_sensor.foo', 'battery_level') < 10 |int) or # line 28
                           (state_attr('binary_sensor.foo2', 'battery_level') < 10 |int) or
                           (state_attr('binary_sensor.foo3', 'battery_level') < 10 |int) or
                           (state_attr('binary_sensor.foo4', 'battery_level') < 10 |int) or
                           (state_attr('binary_sensor.foo5', 'battery_level') < 10 |int) or
                           (state_attr('binary_sensor.foo6', 'battery_level') < 10 |int) or
                           (state_attr('binary_sensor.foo7', 'battery_level') < 10 |int) or
                           (state_attr('binary_sensor.foo8', 'battery_level') < 10 |int) or
                           (state_attr('binary_sensor.foo9', 'battery_level') < 10 |int) or
                           (state_attr('sensor.foo10', 'battery_level') < 10 |int) or
                           (state_attr('sensor.foo11', 'battery_level') < 10 |int) }}

but i got this error in the log:

  in "bla.yaml", line 28, column 26
expected ',' or '}', but got '<scalar>'
  in "bla.yaml", line 28, column 99
2020-01-18 17:43:56 ERROR (MainThread) [homeassistant.components.automation] while parsing a flow mapping
  in "bla.yaml", line 28, column 26
expected ',' or '}', but got '<scalar>'
  in "bla.yaml", line 28, column 99

any clue?
Thanks

Why are you casting 10 to int ?

I’m very surprised if this actually works in the template editor.

I think you want : -
(state_attr(‘binary_sensor.foo’, ‘battery_level’) | int < 10 )

Though the construction of the template as a single trigger means that you will never get a second trigger for another battery falling below 10
Thats okay if you then check all your levels and sort your batteries out

How do you have battery level as a binary_sensor attribute ? (the others make sense)

1 Like

thanks for the int head up mate, just addressed it (though there was no error in template editor even before)

yeah, i will address the battery as soon as i get the notification so no problem for now (maybe i’ll split it in multiple triggers in the future)

i got that attribute on binary sensors because they come with it by default

but i still can’t get my head around that error

As well as the |int thing you have a multi line template starting on the first line like a single line template - that would require it to be enclosed in quotes. Try using the multi line format:

value_template: >
  {{ (state_attr('binary_sensor.foo', 'battery_level')|int < 10 ) or
  (state_attr('binary_sensor.foo2', 'battery_level')|int < 10 ) or
  (state_attr('binary_sensor.foo3', 'battery_level')|int < 10 ) or
  (state_attr('binary_sensor.foo4', 'battery_level')|int < 10 ) or
  (state_attr('binary_sensor.foo5', 'battery_level')|int < 10 ) or
  (state_attr('binary_sensor.foo6', 'battery_level')|int < 10 ) or
  (state_attr('binary_sensor.foo7', 'battery_level')|int < 10 ) or
  (state_attr('binary_sensor.foo8', 'battery_level')|int < 10 ) or
  (state_attr('binary_sensor.foo9', 'battery_level')|int < 10 ) or
  (state_attr('sensor.foo10', 'battery_level')|int < 10 ) or
  (state_attr('sensor.foo11', 'battery_level')|int < 10 ) }}

2 Likes

Error descriptions are notoriously vague but it looks from your 3 errors that you are comparing a text field with a number (you were) and the second one suggests that you are using node red ??? Though I’m guessing on that.

Good catch ! :+1:

goddamn you’re right mate, i wasn’t paying attention to that, i think i need to rest a bit =D
thanks again you all guys, awesome community