Triggering a fan based on temperature

I am trying to figure out why a fan in my laundry room is not always triggered when the temperature in the room reaches a certain point.

Some days it works as expected and others it will not trigger for hours and the temperature rises will above the threshold.

The temperature sensor is off an ESPHome device, a Dallas sensor. The switch is an Aqara double switch. One runs the room light and the other the exhaust fan in the cieling (laundry room).

Fan on

- id: '1689215707989'
  alias: Laundry room fan on
  description: ''
  trigger:
  - platform: numeric_state
    entity_id: sensor.laundry_room
    for:
      hours: 0
      minutes: 0
      seconds: 0
    above: 83
  condition: []
  action:
  - type: turn_on
    device_id: 27ca9d3e3eb6b2b31f5ed66c23c32f68
    entity_id: 40d2494e7239dc0f523b9426ea8e5887
    domain: switch
  mode: single

Fan Off

- id: '1689215796687'
  alias: Laundry room fan off
  description: ''
  trigger:
  - platform: device
    type: turned_on
    device_id: 27ca9d3e3eb6b2b31f5ed66c23c32f68
    entity_id: 40d2494e7239dc0f523b9426ea8e5887
    domain: switch
    for:
      hours: 0
      minutes: 25
      seconds: 0
  condition: []
  action:
  - type: turn_off
    device_id: 27ca9d3e3eb6b2b31f5ed66c23c32f68
    entity_id: 40d2494e7239dc0f523b9426ea8e5887
    domain: switch
  mode: single

Most likely it’s because the temperature isn’t passing the threshold from a lower temp.
So if it’s 84 and it lowers to 83, it won’t trigger, it has to come from below 83 to trigger.

Have you checked the temp graph of the sensor when it doesn’t trigger?

Hmmm… I do have a chart showing the temps. Here is a screenshot, where yesterday it triggered a couple times and then nothing. It looks as though it was below 83 for some time and then it went above 83 and didn’t trigger.

Maybe it’s not below 83 long enough?


The run on the far right was me manually turning on the fan.

Ok I see what you are saying and now that I know to search for that, I can see there are numerous posts about it that it only triggers when crossing the temp threshold from below the threshold and not if it never goes back below that threshold.

I haven’t yet found how to fix that though. I think in my case I have it set to be on for 25 minutes, but I guess I need to just leave it on until the temp drops below something like 81 degrees.

Have you considered triggering on a change in temperature and then put in a condition for being above the target temp. You can also make it reboot proof by checking for change in temp and condition below target temp to turn off fan.

Maybe you can use something like this?

# will switch state on above 25.6 °C and switch state off below 25.0 °C

binary_sensor:
  - platform: threshold
    name: 'Laundry fan'
    entity_id: sensor.laundry_room
    upper: 25.3
    hysteresis: 0.3 # sensor


automation:
  - alias: Laundry fan
    trigger:
      - platform: state
        entity_id: binary_sensor.laundry_fan
        to: null
    action:
      - service: switch.turn_{{ states("binary_sensor.laundry_fan") }}
        target:
          entity_id: switch.laundry_fan

AllHailJ, complex1, thanks for these suggestions. I will try them both and see how they perform.

Why not have the fan run as long as needed to get the temperature below the on threshold?
So something like this:

- id: '1689215707989'
  alias: Laundry room fan toggle
  description: ''
  trigger:
  - platform: numeric_state
    id: "On"
    entity_id: sensor.laundry_room
    above: 83
  - platform: numeric_state
    id: "Off"
    entity_id: sensor.laundry_room
    for:
      hours: 0
      minutes: 5
      seconds: 0
    below: 83
  condition: []
  action:
    - choose:
        - conditions:
            - condition: trigger
              id:
                - "On"
          sequence:
            - type: turn_on
              device_id: 27ca9d3e3eb6b2b31f5ed66c23c32f68
              entity_id: 40d2494e7239dc0f523b9426ea8e5887
              domain: switch
        - conditions:
            - condition: trigger
              id:
                - "Off"
          sequence:
            - type: turn_off
              device_id: 27ca9d3e3eb6b2b31f5ed66c23c32f68
              entity_id: 40d2494e7239dc0f523b9426ea8e5887
              domain: switch
  mode: single

I’ve used Choose instead of if so you can easily add more scenario’s in the future.
Disclaimer, I write this without testing, since I do not have your switches and sensors :wink:

If you don’t want the fan to run forever you can of course add your Fan off trigger and give it the id: Off.
The fan will be turned off. but if the temp never goes below 83, it will not be turned on again based on that trigger. You could add a trigger at fan x minutes off and give it an id of its own, i.e. ‘id: Timed_on’.

Then just add a choose option that has the condition:

  • temp above 83
  • triggered by ‘Timed_on’
    and copy the same action as turn on. Of course one could combine both conditions in the first choose, but I think adding another choose option is easier to understand and trouble shoot for you.

Given that you didn’t test it, it was very close to working code. Just a couple typos. It looks to be working well for the past 24 hours. It has been very hot here so I expect it to stay on most of the day, and this automation does just that.

1 Like

Been running this way for some time now, working very well.