Turn on and off fan based on tempurature

Tags: #<Tag:0x00007f464bf9c6d8>

so I have a window fan and a thermometer

I want to turn the fan on when the thermometer reads higher than 70F

I want it to turn off when the thermometer goes below 70F

but if I turn on the fan manually i dont want the second one to turn it off again

so how do I make that?

  • Is it a smart fan, or a dumb fan plugged into a smart switch/outlet?
  • Is the thermometer connected to an ESP8266 or ESP32 microprocessor? To an RPi?

To summarize, are the inputs and outputs available to Home Assistant already?

the thermometer is: sensor.bedroom_temperature

the fan is: switch.workshop_window_fan

the fan is a basic window fan with a hardware switch I leave on then
I cut the power cord in half and put the sonoff relay in the middle and reflashed it with ESPHome

the temp sensor is an esp8266 esp-01 with a dht-11 connected to it also flashed with ESPHome

I can see the temp in my overview
I have a switch that works to turn the fan on and off in my overview

I have the devices working I need help with the automation

Have you got the basic automation working by following the basic example for turning the fan on based on the temp sensor like mentioned here:

I would have the temp control (use hysteresis on the switch point) set a bit.
Have your manual control set another bit.
If either bit is on the fan is on

I would probably use generic thermostat for that. You just specify your sensor and switch in the config then you can adjust for what temperature you like. You may need to put it cooling mode.

You can get it to stay on by setting a really low temperature on the thermostat control.

@cTurtle98

I am guessing you probably don’t have an automation at all?
Ignoring your comment about “but if I turn on the fan manually i dont want the second one to turn it off again” for now a basic approach would be:

- alias: Turn Fan On
  trigger:
    platform: numeric_state
    entity_id: sensor.bedroom_temperature
    value_template: '{{ state.attributes.current_temperature }}'
    above: 70
  action:
    service: homeassistant.turn_on
    entity_id: switch.workshop_window_fan

- alias: Turn Fan Off
  trigger:
    platform: numeric_state
    entity_id: sensor.bedroom_temperature
    value_template: '{{ state.attributes.current_temperature }}'
    below: 70
  action:
    service: homeassistant.turn_off
    entity_id: switch.workshop_window_fan

Once you have a basic automation working then look at improving and refining it.
You could replace the hard coded 70 with an input_number so you can adjust your set-point on the front end.

Or have a Condition, that if a heater is turned on, don’t run the fan etc as you will be dumping hot air outside.

I agree with @Crhass that it might be best to use the Generic Thermostat component.

But if you want to go the automation route, then @wills106’s suggestion is close. (I.e., I don’t think the value_template lines are needed or appropriate.)

And regarding your requirement “if I turn on the fan manually i dont want the second one to turn it off again”, that shouldn’t be an issue. If the temp goes above 70 it will already be on, so you won’t be turning in on manually. If it’s below 70, then the automation won’t turn it off until the temp first goes above 70 and then back below 70. Think of it this way: the triggers are “events”. I.e., the action will only run when the temp sensor crosses the threshold in the specified direction.

so I need to add this to my configuration.yaml?

climate:
  - platform: generic_thermostat
    name: Window_Fan
    heater: switch.workshop_window_fan
    target_sensor: sensor.bedroom_temperature
    max_temp: 70
    ac_mode: true
    min_cycle_duration:
      seconds: 5

Looks like a good start, may need to add initial start mode, maybe initial temp. See how it goes.