Fan automation with multiple triggers

Hi!

I would like to make an automation to a fan. I’d like to use 2 temperature sensors for triggering the fan. I have an outside and an inside sensor, and the goal is to make an automation, like this:

The fan is only turn on, when the outside temperature is lower than the inside temperature. It only run, if the inside temperature isn’t lower than 20°C. Can you help me please?

Thanks!

Here’s an example of an automation that does what you described (assuming I understood your requirements correctly):

- alias: 'temperature controlled fan'
  trigger:
    platform: template
    value_template: >
      {% set inside = states('sensor.inside_temperature') | float %}
      {% set outside = states('sensor.outside_temperature') | float %}      
      {{ inside > 20 and outside < inside }}
  action:
  - service: fan.turn_on
    entity_id: fan.my_fan
  • I’ve used variables in the value_template just to make it more legible.
  • It converts the inside and outside temperatures into floating point numbers (like 19.5 or 21.2 as opposed to integer numbers like 19 or 21) and then assigns the resulting values to variables (inside and outside).
  • The last line checks if the inside temperature is above 20 and the outside temperature is less than the inside temperature. If it is then it reports true which permits the automation to execute the action (which turns on the fan). If it is false, then the action is not executed.

EDIT
Implemented petro’s suggestion (see below) and changed variable originally named in to inside to prevent possible misinterpretation with Jinja’s existing in operator.

I think you should avoid using ‘in’ as a variable name. In in jinja is an operator.

1 Like

Thank you guys. Works better, than I wanted. It turns on the fan, when the outer temperature is lower, than the inner, and turns off, if the inner is lower.

Okay, I don’t know, what happened, but it looks the automation only turns on the fan and never turns off. May I do an automation what turns the fan off?

(Okay, I did a “reverse” automation, but have to wait to see if it works as I think)