Automating my porch light

Hey there,

I hope I have posted this in the correct place.

I’m trying to automate my front porch light based on time. I have used the Automations section of the Hass.io GUI but the light doesno’t seem to come on. It works fine if used with the switch in Hass.io. I wanted the light to turn on and suset -30 min and turn off at 11pm

Here is my automtatinos.yaml

  • action:
    • data:
      entity_id: light.yeelight_white_f0b429a93ec5
      service: light.turn_on
      alias: Front Light On
      condition: []
      id: ‘1517352677724’
      trigger:
    • event: sunset
      offset: -00:30:00
      platform: sun
  • action:
    • data:
      entity_id: light.yeelight_white_f0b429a92f5f
      service: light.turn_off
      alias: Front Light off
      condition: []
      id: ‘1517352731520’
      trigger:
    • at: ‘23:00:00’
      platform: time

What have I done wrong?

Many thanks

you have 2 different entity ids?

Ahh. Thanks. It as the ‘off’ that was incorrect and is now fixed. Any idea why its not turning on?

I would try posting your automations.yaml in the code brackets, so we can see if it is just formatted incorrectly

but here is my automation that is similar.

- alias: "Dusk"
  trigger:
    platform: sun
    event: sunset
    offset: "-00:15:00"
  action:
    - service: switch.turn_on
      entity_id: group.outfront

I use switches, and not ‘lights’ but the gist is the same.

Apologies.

- action:
  - data:
      entity_id: light.yeelight_white_f0b429a93ec5
    service: light.turn_on
  alias: Front Light On
  condition: []
  id: '1517352677724'
  trigger:
  - event: sunset
    offset: -00:30:00
    platform: sun
- action:
  - data:
      entity_id: light.yeelight_white_f0b429a93ec5
    service: light.turn_off
  alias: Front Light off
  condition: []
  id: '1517352731520'
  trigger:
  - at: '23:00:00'
    platform: time

the only oddity I can see is that your offset is not formatted with quotation marks. Not sure if that matters.

Thanks, I’ll add them and see what happens.

actually looking at it a little closer, I don’t understand the - data: section of the - action:

Who understands the code from the automation editor? :joy:

Isn’t that the truth…

I found it was easier to write them out in YAML than to try and rely on that thing.

1 Like

So do you think I’d be better off just doing that? I must admit, I’m a total novice when it comes to yaml…

lol. it’s not that difficult really. the code I posted earlier, is my entire ‘Dusk’ automation.

1 Like

Likewise, it’s not used as a basic example of an automation in the docs for no reason.

Here is mine. It turns on 15 minutes after sunset then turns off at 1 am. Then I add one more step such that if someone turns the light back on manually after 1 am then it stays on until sunrise then is automatically shut off.

- id: deck_light_on_at Dusk
  alias: Deck Light On at Dusk
  trigger:
    platform: sun
    event: sunset
    offset: "+00:15:00"
  action:
    service: homeassistant.turn_on
    entity_id: light.sengled_e11g13_03070a4c_1

- id: deck_light_off_at_x_time
  alias: Deck Light Off at 1am
  trigger:
    platform: time
    hours: 01
    minutes: 00
    seconds: 00
  action:
    service: homeassistant.turn_off
    entity_id: light.sengled_e11g13_03070a4c_1

- id: deck_light_off_at_sunrise
  alias: Deck Light Off at Sunrise
  trigger:
    platform: sun
    event: sunrise
  action:
    service: homeassistant.turn_off
    entity_id: light.sengled_e11g13_03070a4c_1

Quotes are needed for time.

I think the automation maker is doing that to the data section. I agree with you that it looks odd. He doesn’t need the data section. Just:

- service:  light.turn_on
  entity_id: light.yeelight_white_f0b429a93ec5
1 Like

I wanted to do something similar porch lights + garage outside lights automation.

turn on dusk-20 minutes, turn off 11pm. by default 20% of brightness.
if there is events(see below), increase brightness to 100%, change back to 20% after 30 seconds of no event.

from 11pm to dawn+20 minutes, by default off. if there is events, turn on lights to 100%, turn off after 30 seconds of no events.

events includes: motion by ring doorbell, someone ring the doorbell, front door open, or garage door open.

is this over complicated?

Not overly complicated but you will likely need to do a lot of that in multiple automation. Otherwise the templates will indeed get very complicated if even at all possible.

yes. I am definitely doing it in node-red, not in yaml file. :joy:

I don’t use node-red and I would have no issues with writing those automations in yaml. At least I don’t think I would… :slightly_smiling_face: