Automation for humidity with conditions

Hi there,

I am using HA for years now and most of the things I was able to figure out.
Now I want an automation to run but I can’t figure out why it won’t run correct.

I want my dehumidifier to switch on and of on a certain humidity percentage.
This part works fine.

The thing is that if the Garage door is open for a while I want the dehumidifier to turn off.
This part I can’t seem to get working.

My automations look like below.

  #####
- id: Ontvochtiger aan
  alias: Ontvochtiger aan
  trigger:
    - above: 67
      entity_id: sensor.temp_hum_garage_wp_humidity
      for:
        minutes: 10
      platform: numeric_state   
  conditions:
    alias: "garagedeur dicht"
    and:
      - condition: state
        entity_id: binary_sensor.garagedeur_hoofd_contact
        state: on
  action:
    - entity_id: switch.ontvochtiger
      service: homeassistant.turn_on
  initial_state: "on"

  #####
- id: Ontvochtiger uit
  alias: Ontvochtiger uit
  trigger:
    - below: 65
      entity_id: sensor.temp_hum_garage_wp_humidity
      for:
        minutes: 10
      platform: numeric_state
  Conditions:
    alias: "garagedeur dicht"
    or:
      - condition: state
        entity_id: binary_sensor.garagedeur_hoofd_contact
        state: off
  action:
    - entity_id: switch.ontvochtiger
      service: homeassistant.turn_off
  initial_state: "on"

I hope someone can point me in the right direction.

Myself, I would create a “threshold sensor” and use the upper and lower limits of humidity that you desire.
Then you can use this as a binary sensor to turn on and off the dehumidifier.

I would then create on automation that deals with turning the dehumidifier on and off based on the binary sensor state, with the condition to only turn the dehumidifier on if the door is closed:

trigger:
  - platform: state
    entity_id:
      - binary_sensor.YOUR_THRESHOLD SENSOR
    from: "off"
    to: "on"
    id: "on"
    for:
      hours: 0
      minutes: 10
      seconds: 0
  - platform: state
    entity_id:
      - binary_sensor.YOUR_THRESHOLD SENSOR
    from: "on"
    to: "off"
    id: "off"
    for:
      hours: 0
      minutes: 10
      seconds: 0
condition: []
action:
  - choose:
      - conditions:
          - condition: trigger
            id:
              - "on"
          - condition: state
            entity_id: binary_sensor.YOUR_GARAGE_DOOR_SENSOR
            state: "off"
        sequence:
          - service: switch.turn_on
            data: {}
            target:
              entity_id: switch.YOUR_DEHUMIDIFIER 
      - conditions:
          - condition: trigger
            id:
              - "off"
        sequence:
          - service: switch.turn_off
            data: {}
            target:
              entity_id: switch.YOUR_DEHUMIDIFIER 

I would then create a 2nd automation the turns the dehumidifier off if the door is opened and the dehumidifier is on, and if the door becomes closed and threshold sensor is on then turn dehumidifier on. Something like:

trigger:
  - platform: state
    entity_id:
      - binary_sensor.YOUR_GARAGE_DOOR_SENSOR
    from: "off"
    to: "on"
    id: open
    for:
      hours: 0
      minutes: 1
      seconds: 0
  - platform: state
    entity_id:
      - binary_sensor.YOUR_GARAGE_DOOR_SENSOR
    from: "on"
    to: "off"
    id: closed
    for:
      hours: 0
      minutes: 1
      seconds: 0
condition: []
action:
  - choose:
      - conditions:
          - condition: trigger
            id:
              - open
          - condition: state
            entity_id: switch.YOUR_DEHUMIDIFIER
            state: "on"
        sequence:
          - service: switch.turn_off
            data: {}
            target:
              entity_id: switch.YOUR_DEHUMIDIFIER
      - conditions:
          - condition: trigger
            id:
              - closed
          - condition: state
            entity_id: binary_sensor.YOUR_THRESHOLD SENSOR
            state: "on"
        sequence:
          - service: switch.turn_on
            data: {}
            target:
              entity_id: switch.YOUR_DEHUMIDIFIER

There are 101 ways of doing this and could achieve the whole thing in one automation particularly if using template’s etc - but for simplicity the above should work.

Thanks, I used your suggestion and so far it seems to work.
Now I can finetune it so that it does not unnecessary when I open the door just to get in and out.