Simple automation not triggering with time condition

Hi all.

Still very new to HomeAssistant. Could do with some help on below, i must be misunderstanding how this works.

Trigger works fine without time conditions. When i below time conditions it doesn’t seem to fire after 17:30, or even on the weekends. What am i doing wrong ?

type: opened
platform: device
device_id: a2bb65cc0fc6287344766be0466b0b05
entity_id: binary_sensor.lumi_lumi_sensor_magnet_aq2_ae1df106_on_off
domain: binary_sensor
for:
  hours: 0
  minutes: 1
  seconds: 0
  milliseconds: 0

1 Conditions for weekday time:

condition: time
after: '17:30'
before: '09:00'
weekday:
  - mon
  - tue
  - wed
  - thu
  - fri

And one for weekend:

condition: or
conditions:
  - condition: time
    weekday:
      - sat
      - sun

Please be so kind as to show the full automation, in one piece. Thanks

Here you go:

- id: '1634245214765'
  alias: Fridge open too long
  description: ''
  trigger:
  - type: opened
    platform: device
    device_id: a2bb65cc0fc6287344766be0466b0b05
    entity_id: binary_sensor.lumi_lumi_sensor_magnet_aq2_ae1df106_on_off
    domain: binary_sensor
    for:
      hours: 0
      minutes: 1
      seconds: 0
      milliseconds: 0
  condition:
  - condition: time
    after: '17:30'
    before: 09:00
    weekday:
    - mon
    - tue
    - wed
    - thu
    - fri
  - condition: or
    conditions:
    - condition: time
      weekday:
      - sat
      - sun
  action:
  - service: notify.alexa_media_everywhere
    data:
      data:
        type: announce
        method: all
      message: Please close the fridge door
  mode: single

You didn’t code your “or” quite right, so the conditions are actually “weekday” and “weekend” :wink:

  condition:
  - condition: or
    conditions:
    - condition: time
      after: '17:30'
      before: '09:00'
      weekday:
      - mon
      - tue
      - wed
      - thu
      - fri
    - condition: time
      weekday:
      - sat
      - sun

I think the time condition could be also a problem, from 9 to 17:30 works, but a time cannot be before 9 and after 17:30 at the same time if i remember right.
Simple way could be 2 automations for this, one before 09:00 and one after 17:30, that should work.

@madface i thought it might work as time resets at 00:00 or so i understood. I’ll try with 2 automations, although i’d rather not get to many automations like this, it will soon fill up :slight_smile:

@koying Thank you, i’ll try this. I just used the gui to create this, as 2 separate conditions, where the 2th condition was a OR with time.

Did i do it wrong in the gui ?

The way it’s done is correct. It’s meant specifically for the cases where we cross a day boundary.

Likely

Maybe reversing the logic could solve the problem. Try:

  condition:
  - condition: not
    conditions:
    - condition: time
      after: '09:00'
      before: '17:30'
      weekday:
      - mon
      - tue
      - wed
      - thu
      - fri

This one should fire if its not between 9-17.30 under the week.

1 Like

fyi: your yaml code worked. many thanks, i was struggling with this!

So i compared your screenshot with what i did, so you have one condition (OR) in which you OR 2 conditions (condition 1 and 2). So where did you define the time ? Do you have 3 (or 4) conditions in total?

nm. it didn’t occur to me i can look at the gui automation now that i have the correct yaml code :slight_smile: i get it now, 1 OR condition and 2 condition types underneath.

out of interest, as you said the outcome would be both week and weekend. but why did it not run as it’s weekend now? or is time+OR just not a valid combo.

I meant it would have to be both at the same time (“and”), which is obviously not possible.

1 Like

Got it, thanks again.