Help with an automation (turn on fan based on temperature)

I would like to create an automation that will turn on a switch(fan) in HA when the temperature of a sensor drops below a certain degree but only when there are people home. The switch, sensor and location tracking are all setup but just don’t know how to create the automation.

I would also like to know if there is a way to test automations, scripts, switches and such when creating them or the only way is to restart HA and try?

Thanks!

Here is a basic framework. You will need to use your entity IDs and device tracker Ids. It triggers when below 68F (enter your desired temp here), checks if no ones is home and then turns on the switch.

automation:
  - alias: "Turn on Fan"
    trigger:
      platform: numeric_state
      entity_id: sensor.temp
      below: '68'
    condition:
      condition: or
      conditions:
        - condition: state
          entity_id: 'device_tracker.phone1'
          state: 'home'
        - condition: state
          entity_id: 'device_tracker.phone2'
          state: 'home'
    action:
      service: switch.turn_on
      entity_id: switch.switch1

Automation docs are here if you need some guidance tweaking automations

4 Likes

Wow this is perfect! Thank you so much!