How can I make an automation that triggers when my iPhone connects/disconnects from wifi

I want my HA to do things when I leave or arrive home. I have tried for far too long to get an automation based on my location. I give up. iPhones just dont seem to cooperate. I have tried doing it through the HA app and the iCloud integration. The icloud3 might do the job but the instructions are impenetrable.

How about this. An automation that goes off when my iPhone leaves the wifi shared by my HA? This makes such sense, but perhaps I dont understand how wifi works.

I dont believe a ping will work. As I understand it, the iPhone will not respond to pings when it has been undisturbed for a few hours. So when I am asleep at night HA might think I’ve left.

The problem seems to be that once my phone is off my wifi it cant send a message to my HA. Maybe there is some way to have the iPhone automate sending am message to my HA when it leaves my home wifi network?

If it makes any difference, my wifi is provided by a google box.

You need to install the companion app and activate the SSID sensor.
You can then make an automation that reacts to changes in that sensor.

1 Like

Thanks for the tip. I cant quite figure it out.

Home assistant does have a sensor for my phone for the ssid. But I cant seem to make an automation based on it as a trigger. Can you tell me anything more?

There are other sensors I can use as a trigger. For instance, I can use step count as a trigger. But I cant seem to see the SSID sensor as a trigger.

The Companion App is able to monitor many aspects of your phone and report their values via sensor entities. However, many of them are disabled by default. You need to enable the ones you want.

Settings > Companion App > Manage Sensors 

The list is categorized. Scroll down through the list to the “Network Sensors” category. Enable whichever sensors you want such as:

  • WiFi Connection (name of network the device is currently connected to)
  • WiFi Signal Strength (signal strength of the device to the WiFi network)
1 Like

I suggest you try out this integration. It is simple to set up and works better than any other WiFi-connection detection will.

2 Likes

Thanks for the tip. I was able to get into the setting son the iPhone app. (Not easy. You need to be disconnected from your HA). My ssid sensors are on. I can see them in HA. I just cant see them anywhere in the automation screen. I can, for instance, make an autimnatuon triggered by a certain step count. But I just cant see ssid when I try to set a trigger.

If you can see it in the HA developer tools on the States tab, then you can see the sensor name you need to react on.

Interesting. I think I was able to get this working. But again, I dont seem to seem to be able to use it as a trigger in an automation.

Is it hidden or disabled in HA?

Make sure you are using a “state” trigger and not a “device” trigger. In fact you should get in the habit of never using “device” for anything in an automation (neither triggers nor actions).

Never thought of that possibility, since I have learnt to avoid devices a long time ago, but a good and probably correct observation! :wink:

FWIW, this wasn’t a prerequisite for me. :man_shrugging:t3:

Create a Numeric State Trigger. Configure its target to use an entity_id then select your sensor from the displayed list. Then set a value for the trigger’s below option.

Big help. I’m getting closer.

In the automation builder, under trigger I can choose a state. Under state it asks me to select an entity and I can select my phone SSID. It then offers me a second entity which I leave blank. It then asks or an attribute which I leave blank. It then asks for From and To.

Here is what is weird. If I put the name of my wifi in the To field and leave from blank the automation fires when I turn wifi on. But then, if I put my wifi name in the From field with To blank, it does the same thing. It fires when I turn wifi on. I cant get the automation to trigger when I turn the wifi off.

This all sounds WAY complicated.

I just use network device trackers if all I want to know is connected/disconnected. Simple.

Can you describe what you do? How would I set up an automation to take an action when my iPhone disconnects from wifi?

If you set up the iPhone detect integration, you’ll have a device_tracker.phone_name_used_in_the_config entity. Use that entity with a state trigger and a state from home to away and it will trigger when you disconnect from WiFi. Use the same trigger but with the states reversed for when you connect.

2 Likes

That sounds terribly limiting. What if he wants to take action when something other than an iPhone disconnects from wifi?

There’s the device tracker docs.

I use ubiquiti gear, which has device trackers built in.

Have fun!

I want to use wifi connectivity status as an “at home” indicator to use to trigger different automations instead of GPS as I want to keep location always turned off on my phone.
When trying to use the wifi state options in the Home Assistant android app, it requires me to turn on location access for the app.
Are there any ways around this, or other apps I could use instead?

I had a very similar issue to yours where the automation would only trigger when jumping back on the WiFi rather than off. I’m pretty sure the automation logic is correct but believe there might be a bug preventing it from working correctly through the companion app. After several hours of banging my head against the table I used a router integration to instead detect if the smartphones had left the network. Can confirm it works like a charm using the same logic.

Hope this helps!

1 Like