Cant get simple automation to trigger

Hello,

I’ve been using HA for a while but lately started using automations. I made simple automation with the UI tool but I cant get it to trigger. Running it manually will do the modbus write.

Sensor.x value will change and sensor.y is input_number that is manually set and if sensor.x value is less than sensor.y it should do the job…but doesnt. No errors regarding this in logs.

Thanks

alias: Test automation
description: Test automation
trigger:
  - platform: template
    value_template: >-
      "{{float(states('sensor.x'),0)|float<=float(states('sensor.y'),0)|float}}"
condition: []
action:
  - service: modbus.write_register
    data:
      address: 3
      value: 2
      hub: modbushub
mode: single
  - platform: template
    value_template: >-
      {{ states('sensor.x') | float(0) <= states('sensor.y') | float(0) }}

Well that was fast and did the trick. Seems that I got some reading to do…

Thanks

You’re welcome!

The main mistake in your template is that you wrapped it in double-quotes and used the line-continuation character.

If you put the template on the same line as the option then you need to wrap the template in quotes.

  - platform: template
    value_template: "{{ states('sensor.x') | float(0) <= states('sensor.y') | float(0) }}"

If you use a line-continuation character (>- or > or |) to indicate the template begins on the next line, then you should not wrap it in quotes.

  - platform: template
    value_template: >-
      {{ states('sensor.x') | float(0) <= states('sensor.y') | float(0) }}