Switching lights on after sunset when not at home

Hi,

I’m pretty sure I must be doing something silly or misunderstanding something simple! Anway…

I’m trying to make an automation that makes the lights come on if I’m not at home and it’s getting dark.

I made this in the gui hence the funny order and id but it should work as I see it:

- action:
  - data:
      entity_id: scene.not_home
    service: scene.turn_on
  alias: Lights on if not home
  condition:
  - condition: state
    entity_id: group.people
    state: 'not_home'
  id: '1514524652004'
  trigger:
  - event: sunset
    offset: '-00:45:00'
    platform: sun

However when I trigger it, it always fires the scene regardless of the status of group.people

How can I be sure that this is doing what I want? And how can I be sure it is triggering correctly?

It didn’t fire 45 minutes before sunset today, but I was in so it shouldn’t have done!

In an attempt to work it out, I have written the following:

- alias: Lights on if not at home
  id: 'lightsonnothome'
  trigger:
    platform: sun
    event: sunset
    offset: '-00:45:00'
  condition:
    condition: state
    entity_id: group.people
    state: 'not_home'
  action:
    service: scene.turn_on
    data:
      entity_id: scene.not_home

As I see it that should be exactly the same as above, but a little more human readable.

If you hit trigger it still turns the lights on even in I am in though!

Clicking trigger in the interface will just run the action, the conditions are only checked when the defined trigger event occurs.

Well that explains that then! I guess I’ll just have to wait and see what happens!

Should changing the state of the sun in dev.states change trigger the above action?

I can change the sun to above/below the horizon and that shows in the badges correctly yet still my automation does not trigger.

Should toggling the posistion of the sun trigger the above?

How do you know it doesn’t trigger, according to the automation your not supposed to be at home :wink:
Seriously… If you’re new to this start with a trigger, check if it works, next add a condition. To check the trigger works just change the offset to something close to the current time. I think you should remove the single quotes on the offset. I use no quotes, others use double quotes.

Changing the offset to make it a minute from now did the trick!

Thanks :slight_smile:

The sun controls just about everything in my house now!

Great! Thanks for confirming.Please set the topic to solved as it might help others.