@mwittig agreed, additionally if your home network is connected by VPN with work network, then pinging Mac address would be useless because I could be at work and pimatic would think I am home.
-
Ping plugin used with computer name
Pimatic, smart home made by smart folks, for the rest of us!
-
@sebastienvg
Depends on how the router handles VPN connections. Sometimes the MAC address gets lost, also hostnames can get lost in a VPN scenario.
IP is the most likely one to find it’s way to ping’s approach. Even then the VPN settings affect (Assigned local network ip by the VPN).I would take a second look at the DHCP reservation lists. It’s highly unlikely it would not be in the settings of the router, even with custom firmwares of your operator.
https://telekomhilft.telekom.de/riokc95758/attachments/riokc95758/Fragen/309528/1/Screenshot+2014-02-13+21.45.40.png This came up with Google, I’m not fluent with German, so my help might be limited.
-
Hi,
It’s not that difficult.
Please note that I only installed pimatic last night and that I only registered to this forum last night, so I can’t give a full-fledged solution. I just know a little about linux/debian and networks.Install required software
Install arp-scan:sudo apt-get install arp-scan
Finding the mac address:
arp-scan can find the active devices on your network by mac address and ip-address. If your MAC address is something like AA:BB:CC:DD:EE:FF, you can give the following command:
sudo arp-scan --localnet | grep -i AA:BB:CC:DD:EE:FF
If your device is “online” you will get something like: 192.168.1.100 aacc:dd:ee:ff
finetuning this with:
sudo arp-scan --localnet | grep -i aa:bb:cc:dd:ee:ff | awk {'print $1'}
would give 192.168.144.1.100
or with:
sudo arp-scan --localnet | grep -i aa:bb:cc:dd:ee:ff | awk {'print $2'}
would give aacc:dd:ee:ffUsing a ShellSensor device with variables and rules you should always be able to detect whether the phone is “in house” or not (unless it is in deep sleep with WiFi off)
Edit: First posts did not contain block quotes. First had to find the synstax
-
sounds interesting, I will try this when I find the time.
-
I dived into it and now have the following script:
#!/bin/bash detect=$(arp-scan --localnet | grep -i $1 | awk {'print $1'}) # check if detect is unset or empty if [ -z "$detect" ]; then echo "not home" else echo "home" fi
and as device I have (for a person called Barak):
{ "id": "phone-1", "name": "phone-barak", "class": "ShellSensor", "attributeName": "mobile Barak", "attributeType": "string", "attributeUnit": "", "command": "sudo /opt/pimatic/scripts/find_phone.sh AA:BB:CC:DD:EE:FF", "interval": 60000 }
In my screen I now get a simple:
mobile Barak home
or
mobile Barak not home
And eventually you could add a sensor to detect the color of his house
-
Hi @Harry-van-der-Wolf ,
I tried arp-scan which looks really good. But I failed at a very simple thing… where to place the sh script. I’m used to my windows machine and am not very familiar with the linux path references. I didn’t want to use the /opt/ dir but my home dir to be able to modify the script via network. At the moment the script is at /Scripte/find_phone.sh. How to add this to the shellsensor?
-
Hi,
Did you also do a
chmod a+x find_phone.sh
on the linux command line for your script?
On windows it needs to have extension .bat, .cmd, .com, .exe and it is “automatically” executable.
On linux/unix you need to make a file executable, and then any file can be executed regardless the extension.Assuming you put your scripts in a scripts folder, you can create a scripts folder in your home folder or in your home/pimatic folder.
Then you can call the script using “command” in the device something like:"sudo /home/<username>/scripts/find_home.sh <mac-address>"
or
"sudo /home/<username>/pimatic-app/scripts/find_home.sh <mac-address>"
I personally keep scripts and “other stuff” one layer higher then my pimatic-app install (which is in /opt/pimatic/pimatic-app), to make sure that with updates, clean ups or stupid mistakes by myself, i do not remove those scripts and “other stuff”
-
Thank you very much, works like a charm now. You were right, I forgot the chmod…
-
Just a short update: I modified your idea to create a ShellPresenceSensor. The script needs to be changed to echo 1 for home and 0 for not home.
With that you get a history of presence (which a ShellSensor does not have) and you get the nice filled or empty dot in the gui.
Again thank you very much for your script idea. -
Nice addition. Thanks. I’m now using that as well.
-
Not tried myself, but this might work as well without external bash script in a ShellPresenceSensor device:
{ "id": "phone-1", "name": "phone-barak", "class": "ShellPresenceSensor", "command": " sudo arp-scan --localnet | grep AA:BB:CC:DD:EE:FF && echo 1 || echo 0", "interval": 60000 }
-
Very clean and almost correct
in your command when grep finds the string it will output something like “AA:BB:CC:DD:EE:FF 192.168.1.1” which will interfere with our check, so we need to “quiet” the output with “-q”. Next to that: some implementations give the mac-address in upper-case characters and some in lowercase characters, so we need the “-i” option to make it case-insensitive.
So a working command is:"sudo arp-scan --localnet | grep -iq AA:BB:CC:DD:EE:FF && echo 1 || echo 0"
Thanks for giving this hint!
-
You are right. I supressed the output with >/dev/null but forgot it when writing my post. Thanks for the correction!
-
I feel that this is a nice workaround. Finally the feature should be implemented in the ping plugin.
-
Something to remember when it comes to a plugin.
arp-scan defaults to eth0 as the interface to scan.
If you want to scan via a wireless device like wlan0 (or another interface) you need to use:"sudo arp-scan --interface=wlan0 --localnet | grep -iq AA:BB:CC:DD:EE:FF && echo 1 || echo 0"
I had completely forgotten this until I had to use it today on my wireless Ubuntu laptop
-
Regarding pinging a host by its hostname, I have implemented a solution for the case where DNS returns multiple IPs. If at least one IP can be pinged the host is flagged ro “present”. https://github.com/pimatic/pimatic-ping/pull/3
"It always takes longer than you expect, even when you take into account Hofstadter's Law.", Hofstadter's Law
-
Since last ping plugin update I get this error:
19:14:50.833 [pimatic-ping] Error on ip lookup of 192.168.66.66: Error: queryA ENOTFOUND
-
@Barny said:
Since last ping plugin update I get this error
OK, I’ll have a look at this, but I think it should work though. Can you confirm the presence behavious of the PingPresence device works as expected?
"It always takes longer than you expect, even when you take into account Hofstadter's Law.", Hofstadter's Law
-
No, they aren´t working. Did you changed config-options? Here´s a sample-device from my config:
{ "host": "192.168.66.95", "interval": 5000, "timeout": 2000, "retries": 4, "xLink": "", "xPresentLabel": "", "xAbsentLabel": "", "id": "LGTV", "name": "TV Schlafzimmer", "class": "PingPresence" },
-
@Barny said:
Did you changed config-options?
No, I didn’t. Btw, your config example is for a different device than the one you had in the error message. I also noticed the error message you posted is missing the log level. It is a warning message and should be similar to teh following
12:00:12.687 [pimatic-ping] warn: Error on ip lookup of 192.168.66.66: Error: queryA ENOTFOUND
"It always takes longer than you expect, even when you take into account Hofstadter's Law.", Hofstadter's Law