Automation to turn on relay using helpers in the above and below section of temperature sesnor

Hey so I’m new to HA and I’[m trying to use helpers in the above and below section of a temperature sensor. I have a trigger if the temperature changes and a template condition.

Trigger

type: temperature
platform: device
device_id: ec58e236e3b54c310cd879f9ed0c7dd1
entity_id: sensor.inside_temp_temperature
domain: sensor
above: 0
below: 0

Template condition

trigger:
  - platform: template 
    value_template: "{{ states('sensor.inside_temp_temperature')|int > states('input_number.max_temperature')|int or states('inside_temp_temperature')|int < states('input_number.min_temperature')|int }}"

Then an action to turn on a relay. Every time I test the condition I get an error.

In 'template' condition: ValueError: Template error: int got invalid input 'unavailable' when rendering 
template 'trigger: - platform: template value_template: "{{ states('sensor.inside_temp_temperature')|int 
> states('input_number.max_temperature')|int or states('inside_temp_temperature')|int < 
states('input_number.min_temperature')|int }}"' but no default was specified

Any help would be great! Thanks!

You missed a ‘sensor.’ in your template, which gave an unavailable value that couldn’t be converted to an int because you hadn’t supplied a default.

Error and recommendation fixed here:

trigger:
  - platform: template 
    value_template: "{{ states('sensor.inside_temp_temperature')|int(0) > states('input_number.max_temperature')|int(0) or states('sensor.inside_temp_temperature')|int(0) < states('input_number.min_temperature')|int(0) }}"

I think you’re getting confused over triggers and conditions, though. You’ve posted a template trigger above, not a condition. Post the full YAML of the automation that you have, and explain carefully what you want it to do.

Oh shoot thanks I didn’t even notice that. This is my full YAML. I want the relay to turn on whenever the input min and max temperature is lower or higher than the sensor.

alias: Test
description: ""
trigger:
  - type: temperature
    platform: device
    device_id: ec58e236e3b54c310cd879f9ed0c7dd1
    entity_id: sensor.inside_temp_temperature
    domain: sensor
    above: 0
    below: 0
condition:
  - condition: template
    value_template: |-
      trigger:
        - platform: template 
          value_template: "{{ states('sensor.inside_temp_temperature')|int(0) > states('input_number.max_temperature')|int(0) or states('sensor.inside_temp_temperature')|int(0) < states('input_number.min_temperature')|int(0) }}"
action:
  - service: switch.turn_on
    data: {}
    target:
      entity_id: switch.fan_relay
mode: single

Here’s a simpler version to do the same thing — and I’m pretty sure your condition code is wrong with that trigger in there.

alias: Test
description: ""
trigger:
  - platform: numeric_state
    entity_id: sensor.inside_temp_temperature
    above: input_number.max_temperature
  - platform: numeric_state
    entity_id: sensor.inside_temp_temperature
    below: input_number.min_temperature

action:
  - service: switch.turn_on
    target:
      entity_id: switch.fan_relay

Or with the condition in shorthand form:

alias: Test
description: ""
trigger:
  - platform: state
    entity_id: sensor.inside_temp_temperature
condition:
  - "{{ states('sensor.inside_temp_temperature')|int(0) > states('input_number.max_temperature')|int(0) or states('sensor.inside_temp_temperature')|int(0) < states('input_number.min_temperature')|int(0) }}"
action:
  - service: switch.turn_on
    target:
      entity_id: switch.fan_relay

Dude thanks so much! It all makes sense now. I really appreciate the help!

1 Like