Trigger based on value_template - condition for X minutes then trigger

Following trigger below is working. However I like to add a waiting / sampling period of X minutes before it triggers.

Background: In the living there is floor heating and a radiator can deliver supplemental heating.
The MDT heating actuator can be setup (in ETS) with a block object. When block object is “1” then the radiator heating controller is disabled. The condition to disable the radiator heating is when delta temperature between actual living room and the controller setpoint is <= 0,5 degrees C. In that case the living room continues to be heated with the floor heating, without the radiator. There is another trigger to switch the radiator back on (block = “0”) when the delta temp is > 0.5 degrees. The action is that a knx.send telegram is sended. The triggers are working. However on the moments where the delta temperature is close to 0.5 degrees there is a lot of switching. The HA triggers do fire frequently (setting the block disabled and re-enabled quite a few times) until the living room temperature withing <0,4 degrees of the setpoint. Then the temperature climbs gradually on the floor heating only.

I like to trigger when a state is constant for 5 minutes.

  • condition: template
    value_template: “{{ (states(‘sensor.knx_living_room_setpoint’) | float -\n states(‘sensor.living_temp’)
    | float) > 0.5 }}\n”

I have tried to add following tow lines to the trigger script. But this will cause an error in the script.

for:
  minutes: 5
- id: '1636642946012'
  alias: LivingRoomRadiator_Off
  description: ''
  trigger:
  - platform: state
    entity_id:
    - sensor.knx_living_room_setpoint
    - sensor.living_temp
  condition:
  - condition: template
    value_template: "{{ (states('sensor.knx_living_room_setpoint') | float -\n    states('sensor.living_temp')
      | float) <= 0.5 }}\n"
  action:
  - action: knx.send
    metadata: {}
    data:
      response: false
      address: 1/2/36
      payload: 1
  mode: single   

You’ve copied in the escaped newline characters: the \n into the template. That won’t work: it should be:

    value_template: >
      {{ (states('sensor.knx_living_room_setpoint') | float(0) -
          states('sensor.living_temp') | float(0)) <= 0.5 }}

It’s an automation not a trigger script.

A template condition doesn’t support the for: parameter. A state condition does, though.

So you could create a Template Binary Sensor Helper with the same state template as the condition you’ve used:

then use that as a trigger, with no need for conditions:

triggers:
  - trigger: state
    entity_id: binary_sensor.living_room_warm
    to: 'on'
    for:
      minutes: 5

Alternatively, have you considered the Generic Thermostat to manage all this?

Thanks for input Troon.
The new line characters \n are not put in the script by my self. These appeared after I was creating a new triggers (other functionality) and after deleting one of them. HA code cleaning up ?

Okay I could indeed setup a binary sensor. Will give that a try.

The Generic Thermostat is not having the functionality to switch a secondary heating actuator. No option.