Newbie, trying a new script, and a little overwhelmed..(detect iPhone on wireless network)

Hi,

I’ve installed HA (not the OS, dockerized) two hours ago, and it looks like an exciting platform that I’d be happy using (and contributing to). My first foray with adding a script is a little less successful though.

I am trying to use this script available on Github to make HA recognize my iPhone is connected to my home’s wireless network.

A bit about my set-up: I have a TP LINK modem-router, and a Kasda router with DHCP off (acting only as an extension point). The iPhone is connecting to the Kasda wireless network.

My first question is: When adding a new device_tracker to configuration.yml, which platform should I be using? I know there’s no tplink one, but I don’t know if I should attempt kasda instead. Right now my Kasda router admin panel is unreachable because of the way I have set it up.

Second question: why does HA not automatically create known_devices.yaml for me when I specify the above (configuration#device_tracker)? The docs seem to indicate that it will.

And most puzzling of all, when I put the above script’s device_tracker.py in custom_components/iphonedetect, I am getting this in the logs:

Invalid config for [script]: expected a dictionary. Got OrderedDict([('default_config', {}), ('group', {}), ('automation', {}), ('script', OrderedDict([('device_tracker', [OrderedDict([('platform', 'iphonedetect'), ('consider_home', 60), ('scan_interval', 12), ('new_device_defaults', OrderedDict([('track_new_devices', True)])), ('hosts', [OrderedDict([('my_iphone', '192.168.1.1')])])])])])), ('scene', {})]). (See /config/configuration.yaml, line 7).

I am also putting the script code in scripts.yaml with the correct info from my TP-Link:

device_tracker:
  - platform: iphonedetect
    consider_home: 60
    scan_interval: 12
    new_device_defaults:
      track_new_devices: true
    hosts:
      - my_iphone: 192.168.1.1

Can anyone please explain to me what are the pre-requists for using the above script? As I understand it it’s:

  1. Make it recognize the router integration
  2. Verify known_devices.yaml exists (or create manually if it doesn’t?)
  3. Add plugin python code to custom_components/iphonedetect/device_tracker.py
  4. Add yaml code to scripts.yaml

Am I in the right direction? what am I missing?

I think the error you’re getting is because you’re adding your device tracker to your scripts.yaml.

It definitely doesn’t say to do that, so you kinda made up the last step yourself, and that’s why it doesn’t work :man_shrugging:

In fact actually you made up steps 1 and 2 too.

All you have to do is add the custom component and dump the device tracker code in your configuration.yaml

The instructions are pretty clear, not sure where you got all the extra steps from.

1 Like

@anon43302295 - thanks for replying. So you are telling me I don’t have to have my router integrated/recognized in order to know which devices are connected to it? How is that even possible? I will definitely try what you said

…But then what if I want to add a router after that, I would have two device_tracker keys in my configuration.yml file, which is invalid. What am I missing now?

Because you’re telling it the ip address to check in the last line of the configuration, nothing to do with the router at all.

You can add multiple platforms per integration, so if you wanted to track you and the wife on the iphonedetect, and your son and the dog on ping…

device_tracker:
  - platform: iphonedetect
    consider_home: 60
    scan_interval: 12
    new_device_defaults:
      track_new_devices: true
    hosts:
      - my_iphone: 192.168.1.1
      - wife_iphone: 192.168.1.200

  - platform: ping
    hosts:
      - sons_android: 192.168.2.10
      - dogs_computer: 192.168.1.25
1 Like

@anon43302295 - I am telling it to recognize that the my iPhone (assigned the IP 192.168.1.101) had connected to my WiFi router. How can 192.168.1.101 be enough here? I mean, it definitely has to do something with the router.

Thanks for the explanation on multiple-keys.

It’s basic networking. All the devices have an ip address.

When you buy a new phone, computer, tablet, whatever you don’t have to ‘install’ the router on it, you just connect to it via WiFi or ethernet.

Your phone is connected by WiFi, your homeassistant is connected by WiFi/ethernet. They can talk to each other.

The custom component you’re using knows which device to look for because you’re telling it the ip address.

The only way that the your router is involved in the transaction is because that’s what is providing you with a network in the first place.

If you felt like you needed to let homeassistant know about your router, and you haven’t done it yet, how did you think it was accessing the internet now? Or how did you think you were accessing the interface?

@anon43302295 - thanks! you were right. The script did “work” - meaning it didn’t give any errors, but unfortunately it won’t locate my iPhone even though I have assigned it a static IP address within my local network. Is there not a simpler way to detect presence by iOS device?

I’ve also tried the mobile app, but it won’t find my HA. I guess it’s because I’m running it dockerized and it’s not automatically exposed?

Just add the address manually. That it’s not automatically detected has something to do with the network, not because you run it “dockerized”. All installation methods except for Home Assistant Core (installation in a virtualenv) run docker. You are running Home Assistant Container.

1 Like

Thanks for your help. Which address would that be? On my Mac running the dockerized HA, I can access the service at either localhost:8123 or 1.127.0.1:8123. My subnet is 192.168.1.x, which address I should give the app?

Edit: nvm, I got it. It should be the address of the host machine running HA. Thanks @Burningstone and @anon43302295

2 Likes