[SOLVED] Need help automating a shed fan

The goal

I want to reduce the humidity inside my shed as much as possible. To acheive that, I have a fan and 2 sensors, one inside the shed and the other one outside.

I want the fan to turn on when the humidity is lower outside than outside and turn off otherwise.

My automation

I built an automation in HA, which is working when manually triggered, but for some reason it’s not triggering automatically. I can’t find what is missing and there’s nothing in the logs.

automations.yaml (auto-on script… the auto-off is very similar)

- id: shed_vent_on
  alias: VENT Shed auto-ON
  trigger:
  - above: '0'
    below: '100'
    entity_id: sensor.0x00158d00022cd579_humidity
    platform: numeric_state
  - above: '0'
    below: '100'
    entity_id: sensor.0x00158d000202992f_humidity
    platform: numeric_state
  condition:
  - condition: template
    value_template: '{{ (state_attr(''sensor.0x00158d00022cd579_humidity'', humidity)|float)
      > (state_attr(''sensor.0x00158d000202992f_humidity'', humidity)|float) + 0.75
      }}'
  action:
  - data:
      entity_id: switch.shed_vent_switch
    service: switch.turn_on

Anybody here can help me spot what is missing?

I guess you got the “trigger” part wrong. Since humidity will be always between 0 and 100 it will not trigger because they are already at that state. Try to put the condition as a trigger (it will trigger when inside > outside). Another option is to use a time trigger and let it trigger, for example, each 5 minutes interval.

Your double quotes were just two single quotes and your attributes weren’t quoted in the condition template.

Also to trigger on any change of state of the humidity sensors this should work:

- id: shed_vent_on
  alias: VENT Shed auto-ON
  trigger:
  - platform: state
    entity_id: sensor.0x00158d00022cd579_humidity
  - platform: state
    entity_id: sensor.0x00158d000202992f_humidity
  condition:
  - condition: template
    value_template: "{{ state_attr('sensor.0x00158d00022cd579_humidity', 'humidity') | float
      > ( state_attr('sensor.0x00158d000202992f_humidity', 'humidity') | float + 0.75 ) }}"
  action:
  - data:
      entity_id: switch.shed_vent_switch
    service: switch.turn_on
3 Likes

Thanks you very much, @tom_l, it’s solving my problem. It’s working great now.

1 Like