Bit of help with a trigger template

Hi all

Newbie here looking for a hand with triggering automation.
Have been using HA for about a year and loving it, primary reason for regulating the nursery room environment during the cold winters.

Would like to expand on my current automations, to control my heater:

- id: heatoff
  alias: heater off when above 22.8C
  trigger:
  - above: '22.8'
    entity_id: sensor.room_temperature
    platform: numeric_state
  - above: '23.2'
    entity_id: sensor.room_temperature
    platform: numeric_state
  condition: []
  action:
  - data:
      entity_id: switch.heaterplug
    service: switch.turn_off
  - delay:
      minutes: 2
  - data:
      entity_id: switch.heaterplug
    service: switch.turn_off
  - delay:
      minutes: 1
  - data:
      entity_id: switch.heaterplug
    service: switch.turn_off

I have essentially the same for heateron automation.
The reason for redundant triggers/actions was because the wifi smart plug i was using kept dropping off the network, ive since fixed it at the wifi controller, turned out to be a setting, but still dont trust it yet.

Would like to add input_number option in lovelace to specify the temperature trigger, and also create another trigger at +/- 0.4c of the same input_number as the backup trigger.

So far i have:
(in configuration.yaml)

Input_number:
  heater_max:
    name: heater_max
    initial: '22.8'
    min: '20'
    max: '25'
    step: '0.1'
    mode: box

I did have a play around and got a working trigger template similar to something like this(apologies, lost the actual code, might be missing a " | int" somewhere too ):

- id: heatermax
  alias: heater_max
  trigger:
  - platform: template
    value_template: '{{ state('sensor.room_temperature') > 'state.input_number.heater_max.state' }}'

was looking to duplicate the trigger adding in a second entry:

   - platform: template
     value_template: '{{ state('sensor.room_temperature') > 'state.input_number.heater_max.state' | int + 0.4  }}'

but the results i was getting out of the template editor wasnt calcuating the +/- operator, instead only gauging the greater/less than only.

Cheers,
Jinneth.

Try this:

   - platform: template
     value_template: "{{ states('sensor.room_temperature')|float > ( states('input_number.heater_max')|float + 0.4 ) }}"
  1. Use double quotes outside the single line template and single quotes inside otherwise you get this enclosed in the quotes:
    value_template: '{{ state('
  1. Use |float if you expect the value to have decimal places or unless you are happy with truncating to an integer.

  2. Try not to use this format: states.input_number.heater_max.state use states('input_number.heater_max') instead. It will not generate errors if the state is unavailable.

  3. Various other syntax errors, quotes in the wrong place, missing s on states etc…

2 Likes

Thanks Tom, legend. Will give that a try.

No worries. I just edited the template as some parentheses are required due to order of operations.