Automation does not trigger when arriving home

So I created two automations that make use of my phone device tracker. The phone status goes from ‘home’ to ‘not_home’.

One automation turns of all lights when I leave the home, works perfectly.

The other I want to turn on livingroom lights when I get home in the dark. And this will not trigger. and I can’t find out why. Any help is appreciated.

alias: Thuiskomen Donker
description: Bewoner komt in het donker Thuis
  - platform: state
    entity_id: device_tracker.huawei_p30_pro_bf0c5938d7
    from: not_home
    to: home
  - condition: sun
    before: sunrise
    after: sunset
    after_offset: '-15'
  - service: homeassistant.turn_on
    data: {}
    entity_id: light.woonkamer
mode: single

Hi, i think your condition might be messed up, I don’t think you can use both before and after in the same condition. Also the time format is invalid.

Try this …

  - condition: or
    - after: sunset
      after_offset: -00:15:00
      condition: sun
    - before: sunrise
      before_offset: 00:15:00
      condition: sun
1 Like

Your condition (before sunrise and after sunset will never be met)… Let’s say we are at 2 am, “before sunrise” is met (between 00:00 and sunrise) but “after sunset” is not met (between sunset and 00:00) so you have to split that condition using “OR” as explained by @Jonah1970 or use “below_horizon” for the “sun” condition… but in this case not sure how offset will be interpreted…

See “sunset/sunrise” in the following for more details:

1 Like

Thanks. I created the automation with the interface so I assumed the format would be OK. I will change the condition today and test tonight.

Hi there im getting the same problem wondering if you got this working.
funny enough mine doesnt seem to trigger if only on mobile data 4G as soon as i connect to wifi the automation triggers.

any ideas?

1 Like

Hey Marcel,

I just got the notification so sorry for the wait.

I did get this working perfectly. The thing you mention about the event only triggering when you are on wifi seems to me by design. The moment my phone leaves the network, my ‘person’ within home assistant gets the away status.

I added my phone to HA with an NMAP tracker. I added this phone to my person as a track device. I scan for this device ON WIFI every 10 seconds.

Now that is done, I can use my person status as a trigger, when my phone is on wifi I am home, otherwise I am away. I live alone but when you have multiple people in the home, you can add all their phones to HA, add the phones as track device to their person within HA. Then put all the people in a group and use the group as a trigger.

when 1 of the phones is on wifi the group status will change to home and then automations will run.

Hope this helps in any way and if you have other questions I am glad to help.

edit: make sure your phone always gets the same IP adres, you can do this in your router by DHCP reservations or just set a static IP address on the phone itself.

Having Wifi on is probably fastest in detecting home. Hovever provided the home GPS location is set right, 4G should eventually also work as you enter the zone for your home.

Having said that: I would not use the OP trigger condition from: not_home. The reason for this is, that if you at some point start defining zones, it might happen that your location changes from e.g. “Shop” to “home” which would prevent the automation from triggering. to: home (and no from:) is all you need.

1 Like

For me the wifi worked best. I did not want location tracking enabled on my phone and I have a really simple setup with just a few lights, so for me it is fine when it triggers when I arrive.

but I forgot about the whole gps tracking feature in my earlier reply, hence I was a bit wondered about the wifi / 4g issue. :slight_smile: