Trigger between two times

I did this before somehow and then rebuilt everything and lost it. I need to turn the lights in my stairway on red (night light) from 10:00 PM to 5:00 AM. Apparently before is not a valid term.

alias: 'Turn on stairway lights at night'
trigger:
  platform: time
  before: "05:00"
  after: "22:00"
action:
  service: homeassistant.turn_on
  entity_id: group.stairs
  data:
    brightness: 64
    color_name: red

Try single quotes.

Or

trigger:
  platform: numeric_state
  entity_id: sensor.time
  before: '05:00:00'
  after: '22:00:00'

If that wont work then try using it as a condition and find something else for trigger.

- condition: time
  before: '05:00:00'
  after: '22:00:00'

Perhaps use sun elevation as trigger?

  trigger:
    platform: numeric_state
    entity_id: sun.sun
    value_template: '{{ state.attributes.elevation }}'
    below: 3.5

Did that solution end up fixing the issue?

I am struggling with the same thing and would love to know how you tackled it.

I switched to using Appdaemon. :slight_smile: I’m a programmer so it just makes more sense to me than YAML. Still use HA for simple automations and screen display. But AD is just so much more intuitive for me.

Just reading up on this now… it looks like a good solution but I’m no programmer… so it will be a challenge… I might graduate to it once I get the basic automations down…

I know you’ve solved it with AppDaemon, but for anyone who needs it…

I think you need to use only “after” as a trigger, and then add a condition with “before” and “after”.

the problem with before and after triggers in HA and part of the reason I moved to AD was that at midnight things switch. So If I have a trigger that fires when someone comes home after 22:00 and before 5:00, at midnight HA sees the current time as being Before 22:00 so it stops firing.

Sorry for necro-bumping this, but if anyone else comes across this issue, I found the easiest way is to create a helper entity between two times and create an automation with that entity as the trigger

1 Like