Humid automation

Hope everyone is well. I a trying to set up a automation to turn on a smart plug when the humidity reaches a certain point and turn off after it reaches a certain point. I used the automation tab in HA. But it doesn’t work. If i execute it it it turns on but not automatically. Any help will be great.

alias: Humidity check
description: ''
trigger:
  - type: value
    platform: device
    device_id: 3bd608a658894dba80494f14b28219f5
    entity_id: sensor.bedroom_humidity
    domain: sensor
    above: 58
condition: []
action:
  - type: turn_on
    device_id: c89a784481ec8399ec05a17fc038549b
    entity_id: switch.dehumid
    domain: switch
  - wait_for_trigger:
      - type: value
        platform: device
        device_id: 3bd608a658894dba80494f14b28219f5
        entity_id: sensor.bedroom_humidity
        domain: sensor
        below: 53
  - type: turn_off
    device_id: c89a784481ec8399ec05a17fc038549b
    entity_id: switch.dehumid
    domain: switch
mode: single

Hi, it is difficult to diagnose a problem when the code & indenting is not formatted correctly. I think it would be much appreciated if you could edit your post and insert ``` before and after the code segment.

Certainily the last four lines of your automation look a bit odd as you have “mode” duplicated as parallel when it is already defined above as single. The fact that it works when you manually execute it would indicate that there is something wrong with your Trigger definition.

For comparision this is my dehumidifer automation however it differs from yours in that I have a sensor that activates on a sharpe rise in humidity (which means someone is using the shower) and it only runs between certain times of the day:

alias: Bed1 Dehumidifier On-Off
description: Control based on high increase in EnSuite humidity
trigger:
  - platform: state
    entity_id: binary_sensor.ensuite_shower_occupancy
    to: 'on'
condition:
  - condition: state
    entity_id: switch.gosund01
    state: 'off'
  - condition: time
    after: input_datetime.dehumidifer_on_time
    before: input_datetime.dehumidifer_off_time
action:
  - service: switch.turn_on
    entity_id: switch.gosund01
    data:
      entity_id: switch.gosund01
  - wait_for_trigger:
      - type: humidity
        platform: device
        device_id: 43c5cd70ad3249a1bdda6e9be91dfd80
        entity_id: sensor.ensuite_humidity
        domain: sensor
        below: 55
    timeout: '01:00:00'
  - service: switch.turn_off
    data:
      entity_id: switch.gosund01
    entity_id: switch.gosund01
initial_state: 'on'
mode: single

The shower occupancy sensor:

- platform: trend
  sensors:
    ensuite_shower_occupancy:
      entity_id: sensor.ensuite_humidity
      device_class: moisture
      max_samples: 10
      sample_duration: 300
      min_gradient: 0.01667
1 Like

Think i have formatted it. Thanks

OK, I don’t know why this is not working but I suggest as a test you try a Numeric State as the Trigger rather than a Device. If that works then consider using a Numeric State in the wait_for_trigger as well.

If I look at my config I tend to use Numeric States in the Triggers and Devices (where available) in the Actions.

EDIT: I have justice noticed that the Type for my wait_for_trigger is “humidity” whereas yours is “value”. What options do you get in the UI editor for this (mine is shown below for an Aqara Zigbee sensor):

The automation’s trigger is designed to trigger when the humidity increases and crosses the threshold value of 58. If the humidity is already above the threshold, the automation will not be triggered.

After the trigger occurs, further increases in humidity do not re-trigger the automation. The humidity must first decrease below the threshold and then rise above it in order to re-trigger it.

2 Likes

Hi. Thank you for the reply. That seems to be what I needed to change it to. It has been along time between using hassio due to a house move and I have forgotten nearly all of the little knowledge I had!

It’s now called Home Assistant OS. It was renamed last June.

In the end I used numeric state after help on Facebook this seems to have sorted it out so my configuration looks like

alias: Humidity check
description: ‘’
trigger:

  • platform: numeric_state
    entity_id: climate.bedroom
    attribute: current_humidity
    above: ‘58’
    condition: null
    action:
  • type: turn_on
    device_id: c89a784481ec8399ec05a17fc038549b
    entity_id: switch.dehumid
    domain: switch
  • wait_for_trigger:
    • platform: numeric_state
      entity_id: climate.bedroom
      attribute: current_humidity
      below: ‘53’
  • type: turn_off
    device_id: c89a784481ec8399ec05a17fc038549b
    entity_id: switch.dehumid
    domain: switch
    mode: single

For future reference, there’s no difference in the behaviour between the first example’s trigger and the second one (Numeric State Trigger). They both trigger at the moment the humidity increases above the threshold value of 58. They will not trigger when the humidity is already above the threshold. They will re-trigger only when the humidity first decreases below 58 and then rises above it.

2 Likes

When you triggered the automation manually, it skipped the automation’s trigger and executed its action. You said that part worked because it turned on the switch.

What didn’t happen was that the Automation didn’t trigger automatically. Do you remember what was the humidity level when you created the automation and waited for it to trigger automatically?

You should also know that restarting Home Assistant will ‘reset’ a Numeric State Trigger.

HI, this is the code I use and I posted it just as an example, the automation is for a heater (smart plug) which is turned on when temp is below X and turns off when is above Y for Z time.

Also I have a Boolean input to skip this automation when it is OFF (For example when we’re out)


- id: HeaterOn
  alias: Heater On
  trigger:
  - platform: numeric_state
    entity_id: sensor.hue_motion_sensor_1_temperature
    below: 19
  condition:
    - condition: state
      entity_id: input_boolean.heater
      state: 'on'
  action:
  - service: switch.turn_on
    entity_id: switch.on_off_outlet_4b_f8_aa_bottom

- id: HeaterOff
  alias: Heater Off
  trigger:
  - platform: numeric_state
    entity_id: sensor.hue_motion_sensor_1_temperature
    above: 20
    for: '00:30:00'
  condition:
    - condition: state
      entity_id: input_boolean.heater
      state: 'on'
  action:
  - service: switch.turn_off
    entity_id: switch.on_off_outlet_4b_f8_aa_bottom

That’s how long it has been!

It is possible to avoid automation duplication for on/off and using input variables by using ‘choose’ in action:

alias: Bathroom humidity
description: ''
trigger:
  - type: humidity
    platform: device
    device_id: 1695ef2c4cf0f5d6a259173bea2d4cbf
    entity_id: sensor.thermometer_humidity
    domain: sensor
    above: 0
    below: 100
condition: []
action:
  - choose:
      - conditions:
          - type: is_humidity
            condition: device
            device_id: 1695ef2c4cf0f5d6a259173bea2d4cbf
            entity_id: sensor.thermometer_humidity
            domain: sensor
            above: 50
        sequence:
          - type: turn_on
            device_id: e25b281d94a74b16bb90e36c6260fecf
            entity_id: switch.bathroom_light_right
            domain: switch
      - conditions:
          - type: is_humidity
            condition: device
            device_id: 1695ef2c4cf0f5d6a259173bea2d4cbf
            entity_id: sensor.thermometer_humidity
            domain: sensor
            below: 35
        sequence:
          - type: turn_off
            device_id: e25b281d94a74b16bb90e36c6260fecf
            entity_id: switch.bathroom_light_right
            domain: switch
    default: []
mode: single

1 Like

@akrigator -

  1. what is mode being used for in the automation?
  2. how do you find the device_id?

Thanks for the help!

Actually i don’t have this automation any more, but those fields were auto-filled by selecting in UI. By the way, mode was default and device_id is optional if entity_id is specified

Can this be done dynamicly, because the humidity changes a lot between summer and winter
so for instant if the humidity increases with 10% within 1 min turn on the fan and if it increases 10% within 30 min turn off the fan

Look at the second post of this thread, the trend plateform.
Edit: I actually changed for the statistic sensor, the trend plateform was reset on every restart… so not very practical !