Automation action outside condition

I have an automation which turns off lights at night after one hour when they have manually been switched on.

However, my light always turns off after one hour, regardless the time.

I checked the system time. It is alright.

Do I miss the idea about conditions?

alias: TurnOffNightLamps
description: Turn Off Lamps after 1 hour when they are switch on after midnight

trigger:
  - platform: device
    type: turned_on
    device_id: 04dc9d59cc1f6883d44731d6fe83ca90
    entity_id: 90e800bf9f2d1455742fcdf11b5dcb17
    domain: light
condition:
  - condition: time
    after: "00:05:00"
    before: "09:00:00"
action:
  - delay:
      hours: 1
      minutes: 0
      seconds: 0
      milliseconds: 0
  - type: turn_off
    device_id: 04dc9d59cc1f6883d44731d6fe83ca90
    entity_id: 90e800bf9f2d1455742fcdf11b5dcb17
    domain: light
mode: single

So if you turn the light on at 10 then it still turns off? That doesn’t jive. What does a trace show when it happens unexpectedly?

One thing to note, this will still run even if the light is turned on at 8:59:59. If you want to prevent it from turning the light off after 9, then you’ll probably want a condition between your delay and turn off actions to recheck the time.

Don’t use long delays if it isn’t necessary.

trigger:
  - platform: device
    type: turned_on
    device_id: 04dc9d59cc1f6883d44731d6fe83ca90
    entity_id: 90e800bf9f2d1455742fcdf11b5dcb17
    domain: light
    for:
      hours: 1
condition:
  - condition: time
    after: "00:05:00"
    before: "09:00:00"
action:
  - type: turn_off
    device_id: 04dc9d59cc1f6883d44731d6fe83ca90
    entity_id: 90e800bf9f2d1455742fcdf11b5dcb17
    domain: light
mode: single
1 Like

Thanks. I am coming from Domoticz and I am now finding my way around in HA which, for me, is more complex. Thanks for pointing me in the direction of traces. I just learned something new :slight_smile: The traces showed that it should work? Strange.

Thanks for the new automation. I will give it a try.
Also you just showed me what the duration in a trigger is for. There is still so much documentation to be read :slight_smile:
I did not know another way to get this automation working but during strolling the forum I saw several people saying: “do not use delays for long times”.
If people are not supposed to do that, why not offer delays with a maximum mm:ss instead of hh:mm:ss? Or are there other scenarios in which a long delay could be valid?

I think the problem is that my condition should be formulated differently.
0:05 is the next day

How can I say it the other way around?
It should NOT run between 9 am an 12 midnight.

Just flip your before/after times.