Phone Home/Away trigger

I am struggling with an automation which will enable and disable the cloud connection automatically based on my phone being in a home/away state. Thought I may have got it cracked today but it still didn’t trigger when I left and so I am now stumped. Pretty sure it’s simple for you experts but I have run out of knowledge.

alias: "Zone: Cloud Connect"
description: ""
trigger:
  - platform: zone
    entity_id: device_tracker.sm_s918b
    zone: zone.home
    event: enter
    id: cloud-off
  - platform: state
    entity_id:
      - device_tracker.sm_s918b
    to: unavailable
    for:
      hours: 0
      minutes: 5
      seconds: 0
    id: cloud-on
condition: []
action:
  - choose:
      - conditions:
          - condition: trigger
            id:
              - cloud-on
        sequence:
          - service: cloud.remote_connect
            data: {}
          - delay:
              hours: 0
              minutes: 1
              seconds: 0
              milliseconds: 0
          - service: notify.mobile_app_name_s23u
            data:
              message: HA Cloud Enabled
              title: HA Cloud
      - conditions:
          - condition: trigger
            id:
              - cloud-off
        sequence:
          - service: cloud.remote_disconnect
            data: {}
          - delay:
              hours: 0
              minutes: 1
              seconds: 0
              milliseconds: 0
          - service: notify.mobile_app_name_s23u
            data:
              message: HA Cloud Disconnected
              title: HA Cloud
mode: single

I think I’d use person.me being home or away.

And, I am not familiar with the cloud service. Is this used with the Nabu Casa cloud service?

My app automatically changes between remote and local URLs.

I seem to be missing the need here.

Have you looked at the traces to see what is happening?

is it the trigger that isn’t occurring so the automation never triggers in the first place?

is it only one trigger that isn’t working? or both?

are the conditions failing? One or both?

1 Like

@jeffcrum - Thanks for the reply, the context is for Nabu Casa and their cloud/remote connection to my HA. The configuration page explains that you can automate the state of cloud connection based on a device location. In my case it makes sense to only have the cloud element enabled when I am not at home, and when at home it toggles it off. This site covers it a little more, https://www.nabucasa.com/config/remote/

@finity I have checked the traces yes, it skips to the end and fails. I believe its because my HA instance has the cloud component disabled, and my phone therefore cannot report back where is it, to trigger the automation, which is why I set the entity state to “unavailable” rather than “not_home” or “away”. If I leave the cloud service enabled, the zones and states of my phone are reported back correctly and I can view them in the history. Yesterday with the cloud connection disabled, when I got home from work the history for the phone said “Home” all day, so its definitely that the tracking breaks down when the cloud is disabled.

I guess what I need is a way for my HA when LAN only, to detect after five minutes of my phone being away/unavailable/work/etc to toggle on the cloud connection. But I am at a loss as how to do this from within the home network, and not from my phone sensors (as the remote connection is down anything on the phone used as a trigger doesn’t fire).

Hopefully this makes sense?

Ah, I get it now. Actually turning on and off the remote connection at the HA server.

Yes, everything you explained makes sense. Not sure how that can possibly work since your phone sensors are required and you disconnect from your home network before you leave your home zone.

The only thing I can think of is an NFC Tag near your exit door. Scan it before leaving and when getting home. Or, a button to toggle it off and on. But, of course, neither of those are ‘automated’ really.

I don’t think there is a way to navigate around the fact that your HA Instance is not internet accessible and so can’t receive the updated GPS location from your phone.

What you might do instead is use a Ping device_tracker entity. This was changed in 2023.12 and I haven’t fully familiarized myself with what is possible/not possible in the new version. However, you can configure that to ping your phone every X seconds and consider your device “away” if it stops responding to pings.

The crucial part that appears to be missing in the latest update is the consider_home setting which allows you to define how long a device must NOT respond to Ping before the device state is considered “away”. Setting this prevents accidental triggers when mobile phones go into sleep mode to save power. I have heard this may be coming in a January update, or you can use a template sensor with delay_off until then.