Trigger an automation when an entity attributes change to below another entity attributes

Hey all!

I’m totaly new with the HA and HA automations. I installed in the last weekend so pleas don’t hurt me if my questions is trivial.

I try to make an automation wich is turn on my gas heater and pump when my bedroom thermostat current temperature is changed to below the selected temperature.

I googled and searched a lot of in this community but don’t find the solution.

My automation is this (sorry I wrote the code in hungarian language, if you want I will translate just let me know):

alias: Felső szint fűtése
description: Ez indítja a kazánt és a szivattyút
trigger:
  - platform: numeric_state
    entity_id: climate.bedroom_mts100v3
    id: '1'
   value_template: {{state_attr('climate.bedroom_mts100v3', 'current_temperature') - 
state_attr('climate.bedroom_mts100v3', 'temperature')}}
    below: '0'
condition:
  - condition: not
    conditions:
      - condition: state
        entity_id: input_boolean.felso_futes_kikapcsolva
        state: 'true'
action:
  - type: turn_on
    device_id: 4fd58a97cdd145b60c8f0d32d5dd1aa6
    entity_id: switch.boiler_mss210_main_channel
    domain: switch
  - type: turn_on
    device_id: 4e93d65a895a5bce494f3b3235ac5bf3
    entity_id: switch.pump_mss210_main_channel
    domain: switch
mode: restart

I tried a lot but this trigger is never triggered when the temperature differetnion is move under zero.
What I do with a wrong way?

trigger:
  - platform: template
    id: '1'
    value_template: {{state_attr('climate.bedroom_mts100v3', 'current_temperature')|float(0) - state_attr('climate.bedroom_mts100v3', 'temperature')|float(0) < 0 }}

Thank you the explaining. But now I’m a litle confused:

The trigger is fired when the value_template returns with true.
The code wich is writed by tom_I without the syntactic is:

current_temperature - needed_temperature < 0

For example 18C° - 20C° = -2C° < 0 → the value is less like zero so the return value is true

In this case this trigger will be fired by the negative return value and not by the positive value.

I’m right?

Sorry. You are right I didn’t see the part at the end.
I thought he did a type cast template.
Which perhaps could also have worked.
But you are correct

Thank You very much, now it’s clear for me and also the code is working so now I’m free from pressure from my wife about the cold house :smiley: