Automation not triggered with condition time

I have this automation that is correctly checked in config file, but it’s NOT triggered. If i put off the “condition: time” condition it works, but i want this works only between 19h and 00h.

Where i am wrong?

- alias: Regola 1 - Luci alla sera
  initial_state: true
  trigger:
  - event: sunset
    offset: '+03:00:00'
    platform: sun
#  - entity_id:
#    - device_tracker.galaxy_s8
#    platform: state
#    to: home
  condition:
  - condition: state
    entity_id: device_tracker.galaxy_s8
    state: home
  - after: '19:30:00'
    before: '00:00:00'
    condition: time
  action:
  - data:
      brightness: 150
      rgb_color:
      - 0
      - 255
      - 0
      transition: 1000
    entity_id: light.gateway_light_7811dcb25b7c
    service: homeassistant.turn_on

I think the culprit is probably before: '00:00:00'
Can you try to remove it? (anything after 19:30 will be before midnight)

1 Like

Ok, i’ll try it… tomorrow i will let you know if it works… :smile:

1 Like

Your condition is wrong, you need to have an and:

change:

  condition:
  - condition: state
    entity_id: device_tracker.galaxy_s8
    state: home
  - after: '19:30:00'
    before: '00:00:00'
    condition: time

to

  condition:
    condition: and
    conditions:
      - condition: state
        entity_id: device_tracker.galaxy_s8
        state: home
      - condition: time
        after: '19:30:00'
        before: '00:00:00'

Not really sure what you are trying to achieve with the second condition.

This reads to me like you want the light to come on 3h after sunset, but only if your phone is home AND if it’s after 19:30h.

There might not be many cases in the year where 3h after sunset it earlier than 19:30h, i.e. the sun sets before 4:30pm.
Unless, of course, my assumption that you live in Italy is completely off :wink:

actually the sun here goes down at 19:20 so i want that automation triggered not before 19:30 and not after midnight. In this case i want my light will be up at 22:20 and finish at 00:00…

There is no time in a day that is before midnight. That condition will always be false.

So how to correct that?

Remove the line before: 00:00:00 completely.

1 Like

@petro, the AND is superfluous there, both the examples in your post do exactly the same thing, but the second has 2 extra lines that aren’t required.

Maurizio. 00:00:00 is the beginning of that day so it won’t work as it has already passed and there are no whole seconds before that. Try ‘23:59:59’ instead.
I have one like that :sunglasses:

Oh really? That is news to me. I don’t think I’ll ever use that but I’ll keep that in mind for future posts.

Yeah, if you just list the conditions they’re AND by default. You only really need AND for nesting purposes. :+1:

1 Like

In this way all is working, and if i go out of home, the light will accordingly shut off, but when i will be back at home why the automation is not triggered anymore? No light will be up… how to modify this automation to have the automation coming back when i come again at home? (sorry for my poor english)…

I think this is because of the trigger you used. This only will be triggered once because sunset +3 only happens once everyday.
If you want the light turn on when you back to home, you will need another trigger like device_tracker.galaxy_s8 from not_home to home.