Help needed with value_template: in automation (Heating related)

Hi, this is my 1st post so I’ll try my best to make it understandable.
My goal is to have an automation that triggers when it evaluates that the temperature read from a “Room stat” is 2 degrees lower than the “Set temperature” for the room, then to turn the heating on. I believe I need to use the “value_template:” but have had no luck in getting it working. I’ve tried the developer tools template tool but I get the error ‘input_number’ is undefined. I’m new to both HA and YAML so would appreciate some guidance.
Thanks.

This is the code generated by the visual automation editor.

trigger: numeric_state
entity_id:
  - sensor.0x282c02bfffe3b118_temperature
below: input_number.lvheat_max
value_template: "{{ input_number.lvheat_max - 2 }}"

value_template: "{{ states('input_number.lvheat_max')|float(0) - 2 }}"

The template is Jinja — read this:

Then consider using this instead:

Why would you automate this manually, instead of using a generic thermostat helper?

Thanks for this, I didn’t know that there was a generic thermostat so I tried it and failed. :frowning: where abouts do I put the yaml code for HA to use it? I set up a Thermostat card but not sure how to get it to use the following yaml settings.

  - platform: generic_thermostat
    name: Living_Room_Radiators
    heater: switch.smart_plug_for_testing
    target_sensor: sensor.0x282c02bfffe3b118_temperature
    min_temp: 8
    max_temp: 35
    ac_mode: false
    target_temp: 20
    cold_tolerance: 2.0
    hot_tolerance: 0
    min_cycle_duration:
      seconds: 5
    keep_alive:
      minutes: 3
    initial_hvac_mode: "off"
    away_temp: 16
    precision: 0.5

Unless your specific use-case goes beyond the normally expected options, you don’t need to set the thermostat up in YAML – you can do it in the UI:

Settings > Devices & services > Helpers > Create helper > Generic thermostat