Added delays, now automation not firing

I have my ras pi 3 with aeon stick turn on two sets of lights i’ve grouped called “downstairs” at sunrise.
What I don’t really want is another section showing on home assistant, right now i have a section called “Automation” showing my sunrise and sunset timers. What i can’t find or figure out, can i put a second action within these to turn the lights off? OR does it have to be another “automation” section?
See my script:

group:
  down_stairs:
    - light.kitchen_table_level_2_0
    - light.living_room_ligh_level_3_0

automation:
  alias: Sunset
  trigger:
    - platform: sun
      event: sunset
      offset: "-01:00:00"
  action:
    service: light.turn_on
    entity_id: light.kitchen_table_level_2_0
    data:
      brightness: 255

automation 2:
  alias: Sunrise
  trigger:
    - platform: sun
      event: sunrise
      offset: "-00:30:00"
  action:
      service: light.turn_on
      entity_id: group.down_stairs
      data:
        brightness: 255

You could add further actions (such as a delay followed by a light.turn_off. It’s likely to be better however to use further automations to turn the lights off, so that if you restart HA during that time window, the lights still turn off.

2 Likes

That would be my approach.

If you don’t want to see the new autmation look at the hidden option in customize or create a default view and only add what you want to see. (note everything will go away unless you add it to a view)

FWIW, you can have multiple aliases under the same automation section:

- alias: Turn Porch Light On At Sunset
  hide_entity: True
  trigger:
    platform: sun
    event: sunset
  action:
    service: homeassistant.turn_on
    entity_id: switch.ge_12722_onoff_relay_switch_front_porch_light_switch 
    
- alias: Turn Porch Light Off At Sunrise
  hide_entity: True
  trigger:
    platform: sun
    event: sunrise
  action:
    service: homeassistant.turn_off
    entity_id: switch.ge_12722_onoff_relay_switch_front_porch_light_switch

Thank you all for the answers/suggestions. I actually figured it out from piecing together a few other snippets I found throughout the forums. Then my indention was apparently off and that was a learning experiencing figuring out how I broke that LOL. Glad I did as I understand the syntax better now.

Here is what I ended up with:

automation:
  alias: Sunset
  trigger:
    - platform: sun
      event: sunset
      offset: "-01:00:00"
  action:
   - service: light.turn_on
     entity_id: light.kitchen_table_level_2_0
     data:
       brightness: 205
       transition: 3600
   - delay: "03:45:00"
   - service: light.turn_off
     entity_id: light.kitchen_table_level_2_0

automation 2:
  alias: Sunrise
  trigger:
    - platform: sun
      event: sunrise
      offset: "-00:30:00"
  action:
    - service: light.turn_on
      entity_id: group.down_stairs
      data:
        brightness: 255
        transition: 45
    - delay: "02:45:00"
    - service: light.turn_off
      entity_id: group.down_stairs

Ok. So the code I posted above, Sunrise isn’t working. Is it my delay?

Bump. Anyone spot anything wrong with the automation 2? I added the delay and turn_off because obviously if we’re not home i don’t want the lights on all day. automation 1 is working. automation 2 did work, until I added the delay and second service entry. It was also set to a time, instead of sunset.

I was trying to turn them on 30 minutes prior to sunrise. Leave them on for 2 hours 45min’s and turn them off.
Here’s the latest version. I don’t see anything wrong… but then I’m a php developer not a python developer :slight_smile:

automation:
  alias: Sunset
  trigger:
    - platform: sun
      event: sunset
      offset: "-01:00:00"
  action:
   - service: light.turn_on
     entity_id: group.down_stairs
     data:
       brightness: 205
       transition: 3600
   - delay: "03:45:00"
   - service: light.turn_off
     entity_id: group.down_stairs

automation 2:
  alias: Sunrise
  trigger:
    - platform: sun
      event: sunrise
      offset: "-00:30:00"
  action:
    - service: light.turn_on
      entity_id: group.down_stairs
      data:
        brightness: 255
        transition: 450
    - delay: "02:45:00"
    - service: light.turn_off
      entity_id: group.down_stairs

can you take a look at my last post with code, see if i’ve done something wrong? I can’t figure out why the sunrise event isn’t firing.

The only obvious thing is that you’re missing a leading space in the action lines of the working automation.

If you manually trigger the automation, does it work?

It does, manually triggered.

I got up at 7am this morning. Turning on 30 min before sunrise, delayed 2:45 to turn off, I’d think itd still be on when I got up.

Have you checked the logbook to see if the lights are being turned on? Have you checked the (console) log to see if there are any errors being logged?

There is an error about plex, but i have nothing in the configuration about plex? I do have a plex server running on my network.

the last entry in the home-assistant.log:

17-07-19 08:39:30 ERROR (Thread-10) [homeassistant.components.media_player.plex] Error listing plex devices
Traceback (most recent call last):
  File "/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/homeassistant/components/media_player/plex.py", line 156, in update_devices
    devices = plexserver.clients()
  File "/home/homeassistant/.homeassistant/deps/plexapi/server.py", line 64, in clients
    for elem in self.query('/clients'):
  File "/home/homeassistant/.homeassistant/deps/plexapi/server.py", line 110, in query
    raise BadRequest('(%s) %s' % (response.status_code, codename))
plexapi.exceptions.BadRequest: (404) not_found

Ok, i have the plex error fixed. Apparently when it creates the plex.conf, after discovering the plex server it incorrectly creates the parameters.
following the link below, the error disappeared. Guess I’ll see this evening if this causes the automation to work now.
Side note: the plex server had been off for a very long time. I recently just started using it again and thus why it makes sense that this only became a problem recently.

You’ll want to look at the time half an hour before sunrise for any relevant errors.

Have a look at my configuration there - Everything is under a single “automation:” section with each alias preceded by a “-” - Give that a try if nothing shows up in the log.

I’ll go look at that, I don’t mind the multiple automation sections. However, the original problem of the automation not working has been solved. After i sunrise stopped working, and then my tinkering, my other automation sunset stopped working. No errors, showing triggered, etc.

I upgraded from .43 to .49. I also changed my delay that triggers the lights off to a random generated sequence. code:
delay: '{{ (range(0, 2)|random|int) }}:{{ (range(1, 59)|random|int) }}:00'

In the end nothing really changed from the first post after I added the delays, with 1 exception. I lowered the transitions to 120 seconds. Previously they were 900 and 450

This morning I got up to the lights being on. Hoping to see that the lights go off soon and come back on this evening. we’re leaving tomorrow for vacation.

automation:
  alias: Sunset
  trigger:
    - platform: sun
      event: sunset
      offset: "-01:00:00"
  action:
   - service: light.turn_on
     entity_id: group.All        
     data:
       brightness: 205
       transition: 120
   - delay: '{{ ((range(2, 3) | random) | int) ~ ":" ~ ((range(5, 55) | random) | int)  ~ ":" ~  ((range(5, 55) | random) | int) }}'
   - service: light.turn_off
     entity_id: group.down_stairs

automation 2:
  alias: Sunrise
  trigger:
    - platform: sun
      event: sunrise
      offset: "-00:30:00"
  action:
    - service: light.turn_on
      entity_id: group.All        
      data:
        brightness: 205
        transition: 120
    - delay: '{{ ((range(0, 2) | random) | int) ~ ":" ~ ((range(5, 55) | random) | int)  ~ ":" ~  ((range(5, 55) | random) | int) }}'
    - service: light.turn_off
      entity_id: group.down_stairs