Automation Help (probably a beginner logic issue)

Hello, relatively new to HA and having a little “logic” problem with one of my automations…

I have a fan in the bedroom in front of a window with a open/close & temp sensor.

I want the fan to turn on when the window is open, the house “mode” is night, and the temperature of the window is above a certain temp (i.e., when it is hot and the window is open and it is nighttime, turn on the fan to help cool the bedroom). This automation seems to be working.

The issue is with the second automation used to turn off the fan. It is kind of the mirror of the turn on: turn off the fan if the window is closed, if the house “mode” is daytime, or if the temp at the window is below a certain temp. I can’t seem to get that last piece to work.

Here’s the YAML for the automation:

alias: Turn Oscillating Fan Off Based on Temperature
description: ''
trigger:
  - type: temperature
    platform: device
    device_id: e198441a20e4aa9376ed1b231afdf27b
    entity_id: sensor.mb_sensor_pauls_window_temperature
    domain: sensor
    above: 0
    for:
      hours: 0
      minutes: 5
      seconds: 0
      milliseconds: 0
    below: 73
  - type: turned_off
    platform: device
    device_id: e198441a20e4aa9376ed1b231afdf27b
    entity_id: binary_sensor.mb_sensor_pauls_window_ias_zone
    domain: binary_sensor
  - platform: state
    entity_id: input_select.house_mode
    to: Day
condition:
  - condition: device
    type: is_on
    device_id: b6d84c53a6407ec7b0682f347127e381
    entity_id: switch.mb_plug_fan_on_off
    domain: switch
action:
  - type: turn_off
    device_id: b6d84c53a6407ec7b0682f347127e381
    entity_id: switch.mb_plug_fan_on_off
    domain: switch
mode: single

When the temperature at the window is below 73 degrees for more than 5 minutes (according to HA), it does not turn off the fan. It does turn off when the house_mode becomes Day, and I think (not 100% sure) that it turns off if I close the window, just not when the temp goes below a certain threshold.

I feel like I must be missing something basic. Any ideas what I’m doing wrong?

Thanks,
paul

I’m not really familiar with device triggers but I think you should be able to accomplish what you want with a numeric_state trigger, something like:

- platform: numeric_state
  entity_id: sensor.mb_sensor_pauls_window_temperature
  below: 73
  for:
      minutes: 5
trigger:
  - type: temperature
    platform: device
    device_id: e198441a20e4aa9376ed1b231afdf27b
    entity_id: sensor.mb_sensor_pauls_window_temperature
    domain: sensor
    above: 0
    for:
      hours: 0
      minutes: 5
      seconds: 0
      milliseconds: 0
    below: 73

This only triggers the automation if it starts above the threshold e.g 75 then go below the threshold e.g 70 and stays for more than 5 minutes below the threshold.

It will not trigger the automation if since the beginning its already under 73.

Ardy,

So for the “turn off”, the temperature when mode becomes (not) “day” (sunset) is usually well above the 73 degree threshold and then some time during the night goes below the threshold of 73, so that seems like it shouldn’t be the problem, but since I have three “triggers”, could that be a problem where one or more should be “conditions”?

The way I was thinking, is:

  1. If the temperature goes below 73 degrees for 5 minutes (a trigger), the automation will be executed (assuming the fan is “on” (condition) and regardless of whether the window is open or the time of day).
  2. If I close the window (a trigger), the automation will be executed (again, assuming the fan is “on” and regardless of temp and time of day)
  3. If the mode becomes “day” (dawn), the automation will be executed (again, assuming the fan is “on” and regardless of temperature and whether the window is open).

Does that work or am I missing something (I’m assuming any one trigger being “true” executes the automation, not all three)?

So now I’m wondering if my thinking about triggers vs conditions in these instances is incorrect. Or if I should simplify and create several different automations, each with a single trigger (for turning off as listed above).

Thoughts?

Thanks,
Paul

You are correct regarding triggers. Trigger(s) are always OR. You can verify it from Automation Trigger.

The thing with numeric_state-

trigger:
  - type: temperature
    platform: device
    device_id: e198441a20e4aa9376ed1b231afdf27b
    entity_id: sensor.mb_sensor_pauls_window_temperature
    domain: sensor
    above: 0
    for:
      hours: 0
      minutes: 5
      seconds: 0
      milliseconds: 0
    below: 73

OR - I suggest using state trigger rather than device_id - in case you need to replace the device, you just need to change the new entity_id to sensor.mb_sensor_pauls_window_temperature.

trigger:
  - platform: numeric_state
    entity_id: sensor.mb_sensor_pauls_window_temperature
    above: '0'
    below: '73'
    for: '00:05:00'

… is that it the state at the beginning must be evaluated as FALSE, then changed and evaluated as TRUE - for the automation to be triggered. The only exception of this is if the trigger calculates numeric_value instead of boolean_value.

In your case, the temperature needs to be above your threshold (e.g 75) - which is evaluated as FALSE, then go below your threshold (e.g 70 for more than 5 minutes) - which evaluates as TRUE.

To make your automation more compact, you can use-

alias: Turn Oscillating Fan Off Based on Temperature
description: ''
mode: single
trigger:
  - platform: numeric_state
    entity_id: sensor.mb_sensor_pauls_window_temperature
    below: '73'
    above: '0'
    for: '00:05:00'
  - platform: state
    entity_id: binary_sensor.mb_sensor_pauls_window_ias_zone
    to: 'off'
  - platform: state
    entity_id: input_select.house_mode
    to: 'Day' ## VERIFY the actual state of `input_select.house_mode` from Developer Tools
condition:
  - condition: state
    entity_id: switch.mb_plug_fan_on_off
    state: 'on'
action:
  - service: switch.turn_off
    target:
      entity_id: switch.mb_plug_fan_on_off