[Bash/Lua] Presence Detection via MAC Address

Moderator: leecollings

henkiev
Posts: 9
Joined: Wednesday 16 May 2018 11:27
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: [Bash/Lua] Presence Detection via MAC Address

Post by henkiev »

@ceedebee for me your script.works great
Thanks. I will try to adjust to more phones ..

I get no false positives anymore as I had with the ping versions
Piter1973
Posts: 2
Joined: Monday 21 January 2019 0:31
Target OS: Windows
Domoticz version:
Contact:

Re: [Bash/Lua] Presence Detection via MAC Address

Post by Piter1973 »

Hello
Nice script. But I have a problem with script_time_Presence.lua

My 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/domoticz/domoticz/scripts/Check_MAC.sh "..macs[1].." "..macs[2].." &"
        os.execute(execcommand)
end

Domoticz Log

Code: Select all

2019-12-07 16:04:00.300 Status: LUA: MAC Address to Poll: 90:2c:34:1f:12:4b On IDX:37
2019-12-07 16:04:00.316 Status: LUA: MAC Address to Poll: d0:f8:8c:10:3b:eb On IDX:41
2019-12-07 16:04:00.334 Status: LUA: MAC Address to Poll: d0:f8:6b:8c:57:bf On IDX:42
2019-12-07 16:04:00.359 Status: LUA: MAC Address to Poll: 90:10:34:1a:b5:03 On IDX:39
2019-12-07 16:05:00.296 Status: LUA: MAC Address to Poll: 4c:2b:34:1f:bb:4b On IDX:35

but how do I run it manually or from crontab
sudo /home/domoticz/domoticz/scripts/Check_MAC.sh d0:f8:6b:8c:57:bf 42

Domoticz log is:

Code: Select all

2019-12-07 16:33:25.577 (Czasy) Light/Switch (Ania telefon czas)
2019-12-07 16:33:25.570 Status: User: Admin initiated a switch command (42/Ania telefon czas/Off)
there is probably a problem with the LUA command
os.execute(execcommand)

I use Orange PI One with Armbian_19.11.3_Orangepione_buster_current_5.3.9
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest