Lights automation based on location HOME / NOT HOME

hello all,

I am trying to setup a couple of automatons based on location but so far with out any success. Here are the two issues that I have at the moment. By the way I am on an iPhone 11 and my wife is on an Android phone (Huawei P20 pro)

  1. Location does not update as it should on the Android device (my wife is not home at the moment and HA shows her as home. She is away for at least 3 hours) occationaly i have the same issue with my iPhone but that more rare

  2. I want to setup two location based automation for the light.

  • I want to turn off all the lights when both, me and my wife, we are not home / leave home. I have created a group for both users but is not working.
alias: Home Lights OFF - when not home
description: ''
trigger:
  - platform: state
    entity_id: group.person_grouped
    from: home
    to: away
condition: []
action:
  - type: turn_off
    device_id: d1d55af0f12f1af1e3f2f37a62978bb1
    entity_id: light.bedroom_lamp
    domain: light
  - type: turn_off
    device_id: xxxxxxxxxxxxxxxxxxxx
    entity_id: light.XXXXX
    domain: light
  • I want to create an automation when any of us arrives home the Living room lights turns on if SUN after sunset and before sunrise
alias: Turn the lights ON when ENTER home
description: ''
trigger:
  - platform: zone
    entity_id: person.antonis_kodj
    zone: zone.home
    event: enter
  - platform: zone
    entity_id: person.efi_mo
    zone: zone.home
    event: enter
condition:
  - condition: sun
    after: sunset
    before: sunrise
action:
  - domain: light
    entity_id: light.floor_lamp
    device_id: xxxxxxxxxxxxxxxxxxxxxxx
    type: turn_on
    brightness_pct: 40
  - type: turn_on
    device_id: xxxxxxxxxxxxxxxxxxxxxxx
    entity_id: light.dining_lamp
    domain: light
    brightness_pct: 40
mode: single

thank you in advance.

If you need any further details for the setup please let me know. thanks a lot

Use not_home instead of away

A person never has the state away, it’s either home, not_home or the name of the zone they are in. So you need to change your teigfer in the first automation to:

trigger:
  - platform: state
    entity_id: group.person_grouped
    from: home
    to: not_home

For your second automation, the condition is wrong, it’s never after sunset and before sunrise at the same time. The docs explicitly mention that you need to separate it into two conditions.

condition:
  condition: or
  conditions:
    - condition: sun
      after: sunset
    - condition: sun
      before: sunrise

thanks i will give it a try. Any chance to know why i have those strange issues with the location tracker?

What are you using to track presence from the phone? The official Home Assistant app?

yes, the Home Assistant app for both devices

And did you enable background location tracking etc. in the app? Has your wife GPS turned on all the time?

yep. all on