"Coming home" triggered randomly when at home

Hi,

I’m using HA Companion App on my One Plus Nord2, Android 12.

I’ve got an an automation which triggers lights, when the app identifies my mobile at home. This is done by checking the wifi connection of my phone (“changing to home wifi”) and zone (“changing to home zone”) - connected via or-condition.

This automation runs quite okay, but sometimes it gets triggered even if I’m at home for hours, i.e. at night when I’m sleeping.

As I can see in the logs, the wifi of my mobile is temporarily “not connected” or the location could not be identified. So if the mobile gets connected to the wifi or the GPS location could be enumerated again, then the automation triggers.

Do you know this phenomenon? I assume, power management of the smartphone kicks in there?
What are your triggers to have a stable “coming home” routine?

Thanks for helping.

Do you know what state it is in before triggering? Is your automation doing a “from” → “to” state or just a “to” state?

1 Like

The automation is set to Trigger Type: Zone, Event: Enter (Geolocation) and Trigger Type: State, To: Home-WiFi (without a from), each of them with the appropriate entity.

This automation works fine in general, but sometimes it fires, even if I’m home.
Most of the issues are caused by the wifi status, which changed from <not connected> to Home-WiFi (which is the correct way to do, because when I’m off my home, I’m not connected to a WiFi).
Sometimes/Rarely the automation fires, when my zone status changes from not_home to home

Well I did some reading as this sort of thing doesn’t happen with my Pixel 6 - it looks like your phone is actually shutting down the WIFI during “sleep” mode. It shouldn’t but I guess you have looked at every available setting on the phone :frowning:

What I do to stop “odd automations” when I’m asleep is to set up an Input Boolean and set it to true when my goodnight automations run - then in the morning (in my case when I take my phone off the wireless charger) it sets it to false. Any lighting automations which may have triggered then have this extra condition. Works for me (basically I have a presence sensor which flicks between the bedroom/kitchen and keeps turning on the kitchen lights!)

So thinking on this - if you had it set to true when you get home, but when you leave just make sure it has a delay of say 30 seconds then set the Boolean to false. Should cover the odd blip. Or just make your state change have the extra “for” x seconds section.

So you want each of those things to trigger arrival at home but then not again until all of them have become false (you both left the home zone and disconnected from home wifi). Right?

Easiest way to do this is probably by making a template binary sensor and triggering off that instead. Like this:

template:
  - binary_sensor:
      - name: Phil is home
        state: >-
          {{ is_state('person.phil', 'home') or is_state('sensor.phils_phone_wifi', '<home wifi name>') }}

Then in your automation just do this:

trigger:
  - platform: state
    entity_id: binary_sensor.phil_is_home
    to: 'on'
    from: 'off'

A brief wifi disconnect won’t trigger this autoamtion as long as your phone is still in the home zone. And arriving home won’t trigger it twice (once when you get to the home zone and once when your phone connects to wifi).

If you really want to use the zone entered trigger can do that as well, just need a trigger template binary sensor:

template:
  - trigger:
      - platform: zone
        entity_id: zone.home
        event: enter
      - platform: state
        entity_id: sensor.phils_phone_wifi
    binary_sensor:
      name: Phil is home
      state: >-
          {{ is_state('person.phil', 'home') or is_state('sensor.phils_phone_wifi', '<home wifi name>') }}

Automation is the same.

That’s basically what I do. If you have an automation that wants to fire only when the first of n triggers is true and then not again until all of them have become false again easiest solution is usually template binary sensor.

EDIT: Actually realizing in this case if the first one works for you then you don’t need the binary sensor, just a template trigger:

trigger:
  - platform: template
    value_template: >-
      {{ is_state('person.phil', 'home') or is_state('sensor.phils_phone_wifi', '<home wifi name>') }}

Even better, no extra entities required.

1 Like

^^ A far more elegant solution than mine!

I know that your reply is 2 years old, but I’m new with HA and I’m interesting to implement this condition. Could you please share an example of how to implement it?

I’m looking for a solution that triggers when I connected to my WiFi (in the future I’ll use BLE to detect this), but not trigger again until I leave the zone, enter again to the zone and connect to the WiFi.

In your example, when I enter the zone the trigger will be fired, and I want to fire the trigger only when I connect to WiFi.

Your solution looks that do that, but I’m not sure how to implement it.
A template like the other examples that you shared would be awesome.

Thank you so much!

I solved following this tutorial

1 Like