Automation with Time Condition

I’d like to turn on my dehumidifier if the sensor detects humidity over 65% with different time conditions.
I set everything up. But when I try the automation, the device gets started everytime I run the automation manually, even the conditions are false. I tried with OR.

This config handles the working days:

id: '1655642734967'
alias: Keller entfeuchten Woche ein
description: ''
trigger:
  - type: humidity
    platform: device
    device_id: f98636b2b6a926874c0ed36923761c04
    entity_id: sensor.keller_h_t_humidity
    domain: sensor
    above: 65
    for:
      hours: 0
      minutes: 15
      seconds: 0
condition:
  - condition: time
    after: '21:00:00'
    before: '06:00:00'
    weekday:
      - mon
      - tue
      - wed
      - thu
      - fri
action:
  - type: turn_on
    device_id: 6b86059efb64549c17bdfa136a6416de
    entity_id: light.keller
    domain: light
mode: single

and this config handles weekends:

id: '1655666511491'
alias: Keller entfeuchten WE ein
description: ''
trigger:
  - type: humidity
    platform: device
    device_id: f98636b2b6a926874c0ed36923761c04
    entity_id: sensor.keller_h_t_humidity
    domain: sensor
    above: 65
condition:
  - condition: or
    conditions:
      - condition: time
        after: '12:00:00'
        before: '23:59:00'
        weekday:
          - sat
      - condition: time
        after: '00:01:00'
        before: '23:59:00'
        weekday:
          - sun
      - condition: time
        after: '00:01:00'
        before: '06:00:00'
        weekday:
          - mon
action:
  - type: turn_on
    device_id: 6b86059efb64549c17bdfa136a6416de
    entity_id: light.keller
    domain: light
mode: single

Could anyone please check my config? :smiley:

If you run the automation manually, the trigger and condition blocks are ignored.

1 Like

Thank you for your answer. Could you check, if the configuration is correct in your point of view?

As far as I can see, yes, it looks OK.

Personal preference, but I’d always use entities rather than the more complex domain / device IDs, just for brevity, simplicity and to remove an additional potential problem (in case a device ID changes), so:

trigger:
  - platform: numeric_state
    entity_id: sensor.keller_h_t_humidity
    above: 65
    for:
      minutes: 15

and

action:
  - service: light.turn_on
    entity_id: light.keller

Also, if the “humid for 15 minutes” bit can be common between the two automations, you could just copy the condition block from the Woche code into the WE automation — leaving you with just a single automation to cover all situations. Untested, but this should work, and has two additional triggers and one additional condition to handle HA restarts:

id: '1655642734967'
alias: Keller entfeuchten
description: ''

trigger:
  - platform: numeric_state
    entity_id: sensor.keller_h_t_humidity
    above: 65
    for:
      minutes: 15
  - platform: homeassistant
    event: start
  - platform: event
    event_type: automation_reloaded

condition:
  - condition: numeric_state
    entity_id: sensor.keller_h_t_humidity
    above: 65
  - condition: or
    conditions:
      # Monday morning
      - condition: time
        after: '00:01:00'
        before: '06:00:00'
        weekday:
          - mon
      # Monday-Friday evening into following morning
      - condition: time
        after: '21:00:00'
        before: '06:00:00'
        weekday:
          - mon
          - tue
          - wed
          - thu
          - fri
      - condition: time
        after: '12:00:00'
        before: '23:59:00'
        weekday:
          - sat
      - condition: time
        after: '00:01:00'
        before: '23:59:00'
        weekday:
          - sun

action:
  - service: light.turn_on
    entity_id: light.keller

EDIT: updated as I originally thought there was duplication on Monday morning, but there isn’t (see comments in code).