Need Help with a Value Statement

I’ve installed a vent fan in my garage and am trying to automate it turning on and off. I have a couple Switchbot temperature sensors, one in the garage and the other outside and currently the fan will not come on until the outside temperature is lower than the garage. What I’m having trouble with is creating a 5 or so degree delta in the logic for the fan turn on script. I’ve tried using " {( sensor.indoor_outdoor_meter_5c97 | int) - 5 }" in the Value Template field but it fails. I’ve included a screenshot with a working version with out the delta. If I use the Value Temple code I get: Error: In ‘numeric_state’ condition: entity sensor.indoor_outdoor_meter_5c97 state ‘{( sensor.indoor_outdoor_meter_5c97 | int) - 5 }’ cannot be processed as a number. Any help greatly appreciated.

Please post the YAML version, not a screenshot of the UI.

References:
FAQ - Format it properly
FAQ - Screenshots

I have a similar situation but I created a template sensor (in configuration.yaml) that I use to keep track of the difference between my room temperature and the set temperature on the heater. You can then do all the stuff you want.

code below - that you will need to update of course. Hope this is helpful.

template:
  - sensor:
      name: "Gas Heater Thermostat Delta"
      unique_id: gas_heater_thermostat_delta
      device_class: temperature
      unit_of_measurement: "°C"
      icon: "mdi:thermostat"
      state: >
        {% set set_temp = state_attr('climate.gas_heater_thermostat', 'temperature') | float %}
        {% set room_temp = states('sensor.living_room_sensor_temperature') | float %}
        {{ ( room_temp - set_temp ) | round (1) }}        
      attributes:
        heater_switch: "{{ states('switch.gas_heater') }}"
        temp_room: "{{ states('sensor.living_room_sensor_temperature') | float(1) }}"
        temp_set: "{{ state_attr('climate.gas_heater_thermostat', 'temperature') | float(1) }}"
        temp_status: >
          {% if this.state | float(1) > 1 %}
            high
          {% elif this.state | float(1) < -1 %}
            low
          {% else %}
            normal
          {% endif %}

Thank you Jata, I will give this a try. I’m just starting with Home Assistant so still learning the low level details.

Sorry, here is the YAML listing:

You need to share the entire automation configuration including the triggers.

At the top right of the page in the Automation editor click the 3-dot expansion menu, select “Edit in YAML”, copy the whole thing and paste it into a thread post using 3 backticks before and after the code block.

In regard to the error:

The error tells you where you need to direct your attention…

{( sensor.indoor_outdoor_meter_5c97 | int) - 5 } is not a valid template and does not produce a numeric value.

  1. Template expressions need to be encapsulated by {{ }}… yours is using {( }
  2. sensor.indoor_outdoor_meter_5c97 is just an entity id string… it is not a method or function that will return a state value. Nor are you using the available state variable as shown in the Numeric State condition docs (2nd Example).

That’s a screenshot of a partial YAML listing.

Look at jata’s post above. It contains a YAML listing.

So does the FAQ link I posted above, for your convenience, so that you can see what’s expected of users when they ask for assistance.

Thanks for your help. I’m definitely a noob here. This code worked:

 alias: Garage Exhaust Fan On
sequence:
  - condition: numeric_state
    entity_id: sensor.indoor_outdoor_meter_5c97
    above: 85
    enabled: true
  - condition: numeric_state
    entity_id: sensor.indoor_outdoor_meter_5c97
    above: sensor.indoor_outdoor_meter_6d30
    value_template: "{{ int (state.state) - 5 }}"
  - type: turn_on
    device_id: 039450be5545779d4caef42410313f52
    entity_id: 2b540e3f7355cdef814a671c2aa7abb9
    domain: switch
mode: single
icon: mdi:fan