Automation not working, binary_sensor state change to modbus.write_register

Hi,

can someone spot the error? It doesn’t pass the output it should.
It’s my first automation, so there is probably something that I have misunderstood.

- id: Heat Pump On Off
  alias: Heat Pump On Off
  trigger:
    platform: state
    entity_id: binary_sensor.heating_allowed
  action:
    service: modbus.write_register
    data:
      hub: hub1
      unit: 1
      address: 25 
      value: >-
          {% if is_state('binary_sensor.heating_allowed', 'On') %}
            1
          {% else %}
            0
          {% endif %}

You forgot the first rule of templating :wink:

You also have an error in the state check. If you look in States under Developer tools you’ll see the actual state is on not On. Home Assistant is case sensitive.

Thank you! It works.