Presence-based lights feature

I have tried to create a automation to turn on my lights when I arrive after sunset and to turn on the lights when I am at home. It also should turn off all lights when I leave home. This shouldn’t be too hard but after reading many posts, trying many blueprints I just can’t get it to work.

I found out there is a feature called presence based lights. It does what I want it to do, sometimes that is. When I am at home my presence gets detected and 2 of my 6 lights in the hue group get switched on.

When I arrive at home however, all 6 lights get switched on with the right profile. No idea why there is a difference, group is the same, lights are the same, when I give the command manually all lights switch on perfectly.

The other thing I am missing is giving it an offset. Now it switches at sundown immediately and I would like to offset that by 25 minutes.

If someone can help me with that then please :slight_smile:

Welcome!

In any kind of software-based solution; especially one driven by volunteers it is always best to offer what you have done to meet us half way.

If you tried so many solutions, you should have at least one with an error message or one that can be reliably reproduced (even if wrong)?

Have a read through Automation Basics to get your head around what you need to do to get your solution.

Have a look at Automation Triggers which specify most of what you want. The basis of your automation to turn on at sunrise/sunset with an offset.

Have a look at Automation Conditions to check if you are home or not first.

So if you do that, you should end up with something similar to:

automation:
  trigger:
    - platform: sun
      # Possible values: sunset, sunrise
      event: sunset
      # Optional time offset. This example will trigger 45 minutes before sunset.
      offset: "-00:45:00"
  conditions:
    - condition: state
      entity_id: "device_tracker.paulus"
      state: "home"
  action:
    - service: light.turn_on
      target:
        entity_id: light.office_lights
2 Likes

Thanks for your reply. I already tried to build a automation for it in a different post and I was not able to get it working. So instead of bothering more people with my stupidity I switched to the option I was able to figure out.

I really have a hard time finding out which option I can use in automations, where to get the entity id, where to get al the states a entity can have. I need to put more time in learning HA but i’m just too busy atm. I used to use openhab and switched to HA. The complex stuff that I did not get to work in openhab was one of the first things that just worked out of the box with home assistant. That why it annoys me so much that I am unable to get this simple thing not working.

I will try once more with the automation settings you provided and let you know how it went.

The documentation is really good. Definitely requires a couple of glances but it’s worth it.

There’s heaps of YouTube videos that help get your head around practical examples :slight_smile:

I definitely empathise and if you can post some information about your current automations/blueprints I’m sure people will be willing to help.

Also, consider hopping on the Home Assistant Discord so you can chat through solutions instead of a “thread” style Q&A

1 Like

Well, I used the code from your example. Got a message mallformed error about the ". I removed those and the lights turn on with home and away. I added the sun elevation condition I will see if it works tonight. Thanks for your time and I will read into HA, absolutely love it but it takes a bit of time to get used to.

1 Like

Well. That was easy. Everything works as intended. Looking back at the other code I was mixing up entities and conditions making it so it never fires.

anyway, it works now. Thanks for your time.

Hey Fanuch, I have my problem again. I updated the container to the newest version and now my automatic light automation does not trigger anymore. I changed nothing in the automation, my trigger is still triggering, entity names have not changed, only a new hoemassistant version.

when I choose ‘run actions’ the lights turn on but my trigger just does not work anymore. I tried using the person tied to the device tracker but that makes no difference.

alias: Arriveren - Woonkamerverlichting inschakelen bij thuiskomst DONKER
description: Schakelt de woonkamer verlichting in wanneer je in het donker thuis komt.
trigger:
  - platform: state
    entity_id: device_tracker.huawei_p30_pro_bf0c5938d7
    from: not_home
    to: home
condition:
  - condition: template
    value_template: '{{ state_attr(''sun.sun'', ''elevation'') < 5 }}'
action:
  - service: light.turn_on
    target:
      area_id: living_room
      entity_id: light.allewoonkamerverlichting
    data:
      brightness_pct: 70
      profile: Palm Beach
mode: single

These quotes seem odd to me.
Can you just do:

"{{ state_attr('sun.sun', 'elevation') < 5 }}"

As per the documentation?

Thanks for the help again. I checked my nmap device and saw that there is a new nmap device with a different name. So the trigger was not working simply because the device used was wrong.

Always good to double check on the input parameters!

That happens to me too sometimes