i obtain it using arp-scan
you have to create:
a virtual switch for every device to poll;
a variable (PRESENCE_LIST) in this format: MAC_Address1;IDX1|MAC2;IDX2 ....
if you have only 1 device it's like 11:22:33:44:55:66;100
i have a time script that launch a bash script to poll the device and send json command to domoticz to switch on or off the assigned virtual switch.
it's perfect and very quick (~2 seconds in my lan with 15 devices connected) and it's IP independent...
this is the script_time_Presence.lua
Code: Select all
function splitString(str, delim, maxNb)
-- Eliminate bad cases...
if string.find(str, delim) == nil then
return { str }
end
if maxNb == nil or maxNb < 1 then
maxNb = 0 -- No limit
end
local result = {}
local pat = "(.-)" .. delim .. "()"
local nb = 0
local lastPos
for part, pos in string.gmatch(str, pat) do
nb = nb + 1
result[nb] = part
lastPos = pos
if nb == maxNb then break end
end
-- Handle the last field
if nb ~= maxNb then
result[nb + 1] = string.sub(str, lastPos)
end
return result
end
commandArray = {}
maclist= uservariables['PRESENCE_LIST']
Lines=splitString(maclist,"|")
for i,line in pairs(Lines) do
--print (i.." "..line)
macs=splitString(line,";")
print ("MAC Address to Poll: "..macs[1].." On IDX:"..macs[2])
execcommand="sudo /home/pi/domoticz/scripts/bash/Check_MAC.sh "..macs[1].." "..macs[2].." &"
os.execute(execcommand)
end
Code: Select all
#!/bin/bash
MAC=$1
IDX=$2
sudo arp-scan --localnet | grep -e $MAC
if [ $? -eq 1 ]
then
echo "Device $MAC Not in LOCAL LAN"
curl "http://127.0.0.1:8080/json.htm?type=command¶m=switchlight&idx=$IDX&switchcmd=Off"
else
echo "Device $MAC in LOCAL LAN"
curl "http://127.0.0.1:8080/json.htm?type=command¶m=switchlight&idx=$IDX&switchcmd=On"
fi