Check for iPhones connected to WiFi

Easy to use, 100% Lua-based event scripting framework.

Moderator: leecollings

Post Reply
MikeVanD
Posts: 23
Joined: Friday 09 September 2022 10:32
Target OS: -
Domoticz version:
Contact:

Check for iPhones connected to WiFi

Post by MikeVanD »

I want to check if anybody is at home and that seemed pretty straight forward, except with an iPhone.

After trying almost every script there is, I started at the beginning; pfSense.
After some time I've managed to get a CLI command to get the info if a certain iPhone is connected to the WiFi or not.

Code: Select all

sshpass -f <(printf '%s\\n' PASSWORD ssh USER@IP-PFSENSE nmap -p 62078 IP-IPHONE | grep '62078/tcp open'
This works like a charm.

But whatever script I use, there is no output at all or there is an error; "no such file or directory", but from the CLI it works fine. Even adding the path to sshpass and ssh it doesn't work

I am no programmer, so when it gets complicated I make use of AI and these scripts don't work either;

Code: Select all

return {
    on = {
        timer = { 'every minute' }
    },

    execute = function(domoticz)

        local bashCommand = [[
        /bin/bash -c 'sshpass -f <(printf "%s\n" PASSWORD) ssh USER@IP-PFSENSE nmap -p 62078 IP-IPHONE | grep "62078/tcp open"' 2>&1
        ]]

        local resultaat = io.popen(bashCommand)
        local output = resultaat:read("*a")
        resultaat:close()
        
        domoticz.log(resultaat)

    end
}
in the log it says:
2025-08-14 22:13:00.048 Status: dzVents: Info: ------ Start internal script: Script #1:, trigger: "every minute"
2025-08-14 22:13:00.052 Status: dzVents: Info: ------ Finished Script #1

While i would expect: 62078/tcp open

Is there a simple way to get this executed and the output stored in a variable?
User avatar
waltervl
Posts: 6028
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2025.1
Location: NL
Contact:

Re: Check for iPhones connected to WiFi

Post by waltervl »

Try the bash command to run it as root (sudo) to see what happens (that is what Domoticz probably will do, based on the installation method).

Also use the dzvents function executeShellCommand() to run the command, see wiki
https://wiki.domoticz.com/DzVents:_next ... tion_3.1.0
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
azonneveld
Posts: 162
Joined: Wednesday 02 October 2019 7:37
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.4
Location: Netherlands
Contact:

Re: Check for iPhones connected to WiFi

Post by azonneveld »

Another way to detect presence of iPhones is the use of Homebridge and shortcuts on the iphone.
This works better than scanning the wlan, because smartphones usually disconnect from wlan when idle.
rpi4 - zigbee2mqtt - roborock - espeasy - rfxcom - homewizard p1 - otgw - homebridge - surveillance station - egardia - goodwe - open weather map - wol - BBQ detection - rsync backup
MikeVanD
Posts: 23
Joined: Friday 09 September 2022 10:32
Target OS: -
Domoticz version:
Contact:

Re: Check for iPhones connected to WiFi

Post by MikeVanD »

waltervl wrote: Thursday 14 August 2025 23:04 Try the bash command to run it as root (sudo) to see what happens (that is what Domoticz probably will do, based on the installation method).
Well, that is odd...
When I issue the command without sudo, the result is:
62078 10.1.160.5 | grep '62078/tcp open'
When I issue the command with sudo, the result is:
(nothing)

I found that adding the path to sshpass might do the trick, but it doesn't. neither does adding the path to the environment.

I changed the script, but I think this sudo-problem is the culprit
MikeVanD
Posts: 23
Joined: Friday 09 September 2022 10:32
Target OS: -
Domoticz version:
Contact:

Re: Check for iPhones connected to WiFi

Post by MikeVanD »

azonneveld wrote: Friday 15 August 2025 9:10 Another way to detect presence of iPhones is the use of Homebridge and shortcuts on the iphone.
This works better than scanning the wlan, because smartphones usually disconnect from wlan when idle.
There are a lot of apps and hardware that does the trick, but the nmap command does it too but for free, without extra hard- or software. Just install nmap in pfsense and with this command it is pretty accurate.
User avatar
waltervl
Posts: 6028
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2025.1
Location: NL
Contact:

Re: Check for iPhones connected to WiFi

Post by waltervl »

What does the below commands display with or without sudo? And do both USER/PASSWORD combinations have ssh access?
printf "%s\n" PASSWORD
printf "%s\n" USER

Or are USER and PASSWORD changed into real values in your real command?

You can also run the command without "| grep" to see what is the result of the ssh, perhaps an error?
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
MikeVanD
Posts: 23
Joined: Friday 09 September 2022 10:32
Target OS: -
Domoticz version:
Contact:

Re: Check for iPhones connected to WiFi

Post by MikeVanD »

It seems that docker is causing problems with the ssh. A quick install (no docker/docker compose) of Domoticz on a temp-pc seems to workt, but I need to do it with a fresh install, because there is a lot of junk on that pc.

I do not know if I have the time for it this weekend, but when I've got it running, I'll report back here.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest