Page 2 of 7
Re: Yet another presence detection method
Posted: Sunday 29 January 2017 9:58
by mayyam
Hi,
i'm on the Tomato firmware, and when i'm testing the script, i'm getting:
When i'm asking it for status ( wl -i eth1 status ):
Code: Select all
SSID: "XXXXX"
Mode: Managed RSSI: 0 dBm SNR: 0 dB noise: -90 dBm Channel: 5u
BSSID: AC:22:0B:xx:xx:xx Capability: ESS ShortSlot RRM
Supported Rates: [ 1(b) 2(b) 5.5(b) 6 9 11(b) 12 18 24 36 48 54 ]
HT Capable:
Chanspec: 2.4GHz channel 3 40MHz (0x1903)
Primary channel: 5
HT Capabilities:
Supported MCS : [ 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 2 1 22 23 32 ]
So i guess, that there is wl adapter, or.....i'm lost.
Re: Yet another presence detection method
Posted: Sunday 29 January 2017 10:14
by mayyam
Oh, i know, i have no 5Ghz network, so no 'wl -i eth2'. I disabled it:
Code: Select all
.....
# look in 2.4GHz (eth1) network for device
for x in `wl -i eth1 assoclist | awk '{print $2}'`; do
if [ $x = $mac ]; then
device_present=On
fi
done
# look in 5GHz (eth2) network for device
#for x in `wl -i eth2 assoclist | awk '{print $2}'`; do
# if [ $x = $mac ]; then
# device_present=On
# fi
#done
....
Anyway, i have no errors, but my status is not updated in Domoticz on ON/OFF switch.
-----
[SOLVED] - I had to unbreak 3 lines:
Code: Select all
...
domoticz_status=`curl -s "http://domoticzUser:domoticzPassword@domoticzIP:domoticzPort/json.htm?type=devices&rid=$idx" | grep Status | awk '{print $3}' | sed 's/[",]//g'`
...
curl -s "http://domoticzUser:domoticzPassword@domoticzIP:domoticzPort/json.htm?type=command¶m=switchlight&idx=$idx&switchcmd=On" > /dev/null
else
curl -s "http://domoticzUser:domoticzPassword@domoticzIP:domoticzPort/json.htm?type=command¶m=switchlight&idx=$idx&switchcmd=Off" > /dev/null
...
Because i don't believe that in Tomato /jffs/scripts/ are triggered automagically, i put:
Code: Select all
/jffs/scripts/presence_detection MAC-ADDRESS1 IDX1
/jffs/scripts/presence_detection MAC-ADDRESS2 IDX2
/jffs/scripts/presence_detection MAC-ADDRESS3 IDX3
/jffs/scripts/presence_detection MAC-ADDRESS4 IDX4
and so on...
in Administration/Scheduler first free Custom/every minute/Everyday
Now is working like a charm

Bless You Surroot!
Re: Yet another presence detection method
Posted: Sunday 29 January 2017 15:15
by sincze
nice.
I tried the script with my tomato router.
It does work... however...
I have a AP on every floor (range problems).
So if I am on the upper floor I am not getting noticed by the router that is running the script.
So it turns Domoticz switch off.
ah. damn
Re: Yet another presence detection method
Posted: Sunday 29 January 2017 15:26
by mayyam
sincze wrote:nice.
I tried the script with my tomato router.
It does work... however...
I have a AP on every floor (range problems).
So if I am on the upper floor I am not getting noticed by the router that is running the script.
So it turns Domoticz switch off.
ah. damn
I also have AP.
And i'm getting two MACs. One is real MAC, and second is virtual MAC:
AC:C1:EE:
12:39:24 - real one
02:0F:B5:
12:39:24 - virtual, from AP
You just have to treat it like another device and write another line for it:
Code: Select all
/jffs/scripts/presence_detection AC:C1:EE:12:39:24
/jffs/scripts/presence_detection 02:0F:B5:12:39:24
The advantage of this is that You know where You are, in which room/floor (at what AP)
I've made something like that -
viewtopic.php?f=23&t=31&start=100#p27521 - first blocky
Two of them, for my wife two MACs - Domoticz know my wife is home, and my two MACs - Domoticz know i'm home. Then third blocky, with both of them, to check if we are in home.
I know i could probably make it with one blocky, but now, as i said, i can also check where in home we are, and let say...turn lights off in area, where nobody is pesent

Re: Yet another presence detection method
Posted: Sunday 29 January 2017 15:40
by sincze

well you are absolutely right. "GEO" Location in the house. and indeed it should be considered a new device.
otherwise ground floor will switch it off every minute... upper floor ... on .

and top floor ... off again. pfff
Re: Yet another presence detection method
Posted: Monday 30 January 2017 20:07
by mikl10
Hello, thank you for sharing your script.
Did someone has already testing that with iPhone?did it work when iPhone is sleeping?
Re: Yet another presence detection method
Posted: Monday 30 January 2017 21:03
by Surroot
mikl10 wrote:Hello, thank you for sharing your script.
Did someone has already testing that with iPhone?did it work when iPhone is sleeping?
Hello!
Yes it also works when the iPhone is sleeping!
Re: Yet another presence detection method
Posted: Sunday 12 February 2017 1:36
by BaliBiker
Hi all,
When I test by typing
./presence_detection 60:F1:89:87:68:FD 1316
I get the next result
-sh: ./presence_detection: Permission denied
Does some has any idea how I can solve this issue??
Many thanks in advance!!
Re: Yet another presence detection method
Posted: Sunday 12 February 2017 9:01
by Surroot
BaliBiker wrote:
I get the next result
-sh: ./presence_detection: Permission denied
Hey BaliBiker!
Try: chmod +x presence_detection
Then again ./presence_detection 60:F1:89:87:68:FD 1316
Best regards!
Re: Yet another presence detection method
Posted: Sunday 12 February 2017 11:36
by BaliBiker
Surroot wrote:BaliBiker wrote:
I get the next result
-sh: ./presence_detection: Permission denied
Hey BaliBiker!
Try: chmod +x presence_detection
Then again ./presence_detection 60:F1:89:87:68:FD 1316
Best regards!
Thanks so much Surroot! That was a step forward

The script runs, but gives me:
Code: Select all
./presence_detection 60:F1:89:87:68:FD 1316
[: Off: unknown operand
I hope you can help me with the script. I looks like this..
Code: Select all
#!/bin/sh
mac=$1
idx=$2
device_present=Off
domoticz_status=`curl -s "http://XXX:[email protected]:8080/json.htm?\type=devices&rid=$idx" | grep Status | awk '{print $3}' | sed 's/[",]//g'`
# look in 2.4GHz (eth1) network for device
for x in `wl -i eth1 assoclist | awk '{print $2}'`; do
if [ $x = $mac ]; then
device_present=On
fi
done
# look in 5GHz (eth2) network for device
for x in `wl -i eth2 assoclist | awk '{print $2}'`; do
if [ $x = $mac ]; then
device_present=On
fi
done
# tell domoticz the new device status
if [ $domoticz_status != $device_present ]; then
if [ $device_present = "On" ]; then
curl -s "http://XXX:[email protected]:8080/json.htm?\type=command¶m=switchlight&idx=$idx&switchcmd=On" > /dev/null
else
curl -s "http://XXX:[email protected]:8080/json.htm?\type=command¶m=switchlight&idx=$idx&switchcmd=Off" > /dev/null
fi
fi
Re: Yet another presence detection method
Posted: Sunday 12 February 2017 11:58
by mayyam
I also get:
[: Off: unknown operand
or
[: On: unknown operand
But it's working.
Re: Yet another presence detection method
Posted: Sunday 12 February 2017 12:40
by PeGe
While reading this thread out of pure curiosity, not intending to test or implement the solution in my own environment (due to incompatoble router hardware), I immediately spotted a fundamental error occuring three (3) times in your script:
I assume that the original author intended to split the URL string of the 'curl' command into two separate lines, and therefore introduced a backslash (\) to escape the 'NewLine' character that followed. But you have now joined those into a single line, so the backslash character should no longer be there!
The 'curl' command is however a bit forgiving, so it will not give you a clear indication of that error. But the shell will actually interpret your current string
"...?\type..." as
"...?<TAB>ype...".
I'm not sure if that is the root cause of your problem, but it's still an error that should still be cleaned up...
/P-G
Re: Yet another presence detection method
Posted: Sunday 12 February 2017 13:18
by Surroot
PeGe wrote:While reading this thread out of pure curiosity, not intending to test or implement the solution in my own environment (due to incompatoble router hardware), I immediately spotted a fundamental error occuring three (3) times in your script:
I assume that the original author intended to split the URL string of the 'curl' command into two separate lines, and therefore introduced a backslash (\) to escape the 'NewLine' character that followed. But you have now joined those into a single line, so the backslash character should no longer be there!
The 'curl' command is however a bit forgiving, so it will not give you a clear indication of that error. But the shell will actually interpret your current string
"...?\type..." as
"...?<TAB>ype...".
I'm not sure if that is the root cause of your problem, but it's still an error that should still be cleaned up...
/P-G
Yes that's right PeGe, I intended to split the line. I thought that there should be less copy/paste errors if there is a line break. As I said in a post before, nano from busybox is a bit strange and sometimes just cuts long lines...
BaliBiker wrote:
I hope you can help me with the script. I looks like this..
Code: Select all
#!/bin/sh
mac=$1
idx=$2
device_present=Off
domoticz_status=`curl -s "http://XXX:[email protected]:8080/json.htm?\type=devices&rid=$idx" | grep Status | awk '{print $3}' | sed 's/[",]//g'`
# look in 2.4GHz (eth1) network for device
for x in `wl -i eth1 assoclist | awk '{print $2}'`; do
if [ $x = $mac ]; then
device_present=On
fi
done
# look in 5GHz (eth2) network for device
for x in `wl -i eth2 assoclist | awk '{print $2}'`; do
if [ $x = $mac ]; then
device_present=On
fi
done
# tell domoticz the new device status
if [ $domoticz_status != $device_present ]; then
if [ $device_present = "On" ]; then
curl -s "http://XXX:[email protected]:8080/json.htm?\type=command¶m=switchlight&idx=$idx&switchcmd=On" > /dev/null
else
curl -s "http://XXX:[email protected]:8080/json.htm?\type=command¶m=switchlight&idx=$idx&switchcmd=Off" > /dev/null
fi
fi
BaliBiker: You should correct these three lines in your script
Re: Yet another presence detection method
Posted: Sunday 12 February 2017 13:53
by Sudden81
Sorry I'm a beginner and have big problems with programming lua, but most copying and pasting.
My question is simply this, could this be implemented of Domoticz. Or is that too complicated?
You choose your router from a list, then downloading something _ which one can instalera on the router. It was called "Asus Merlin custom firmware" or something like that?
You choose what the user's mac address you want to use.
You choose which network to trigger the 2.5GHz or 5GHz.
You choose the name of virituel switch, and boom, you have a virituel presence switch.
The result will be the same as programming yourself but it gets super much easier for users.
Is this a stupid idea or this would be feasible.
Re: Yet another presence detection method
Posted: Sunday 12 February 2017 15:29
by BaliBiker
Many thanks Surroot. That did the job. Its all working fine now.
Verstuurd vanaf mijn SM-G935F met Tapatalk
Re: Yet another presence detection method
Posted: Sunday 12 February 2017 17:41
by Surroot
Sudden81 wrote:Sorry I'm a beginner and have big problems with programming lua, but most copying and pasting.
My question is simply this, could this be implemented of Domoticz. Or is that too complicated?
You choose your router from a list, then downloading something _ which one can instalera on the router. It was called "Asus Merlin custom firmware" or something like that?
You choose what the user's mac address you want to use.
You choose which network to trigger the 2.5GHz or 5GHz.
You choose the name of virituel switch, and boom, you have a virituel presence switch.
The result will be the same as programming yourself but it gets super much easier for users.
Is this a stupid idea or this would be feasible.
Yes I think it's possible to implement this.
Maybe I put all those steps from the presence detection setup in a script in the future, which would be a lot easier for new users to setup the presence detection. But you still have to flash the router firmware manually, I don't think thats a good idea to let another software handle the flash process.
Re: RE: Re: Yet another presence detection method
Posted: Tuesday 14 February 2017 16:57
by BaliBiker
mayyam wrote:sincze wrote:nice.
I tried the script with my tomato router.
It does work... however...
I have a AP on every floor (range problems).
So if I am on the upper floor I am not getting noticed by the router that is running the script.
So it turns Domoticz switch off.
ah. damn
I also have AP.
And i'm getting two MACs. One is real MAC, and second is virtual MAC:
AC:C1:EE:
12:39:24 - real one
02:0F:B5:
12:39:24 - virtual, from AP
You just have to treat it like another device and write another line for it:
Code: Select all
/jffs/scripts/presence_detection AC:C1:EE:12:39:24
/jffs/scripts/presence_detection 02:0F:B5:12:39:24
The advantage of this is that You know where You are, in which room/floor (at what AP)
I've made something like that -
viewtopic.php?f=23&t=31&start=100#p27521 - first blocky
Two of them, for my wife two MACs - Domoticz know my wife is home, and my two MACs - Domoticz know i'm home. Then third blocky, with both of them, to check if we are in home.
I know i could probably make it with one blocky, but now, as i said, i can also check where in home we are, and let say...turn lights off in area, where nobody is pesent

Ik have an AP as well. I like to ad the virtual MAC to the script. Any Idea where I can find the virtual MAC address?
Verstuurd vanaf mijn SM-G935F met Tapatalk
Re: RE: Re: RE: Re: Yet another presence detection method
Posted: Tuesday 14 February 2017 18:55
by mayyam
BaliBiker wrote:mayyam wrote:sincze wrote:nice.
I tried the script with my tomato router.
It does work... however...
I have a AP on every floor (range problems).
So if I am on the upper floor I am not getting noticed by the router that is running the script.
So it turns Domoticz switch off.
ah. damn
I also have AP.
And i'm getting two MACs. One is real MAC, and second is virtual MAC:
AC:C1:EE:
12:39:24 - real one
02:0F:B5:
12:39:24 - virtual, from AP
You just have to treat it like another device and write another line for it:
Code: Select all
/jffs/scripts/presence_detection AC:C1:EE:12:39:24
/jffs/scripts/presence_detection 02:0F:B5:12:39:24
The advantage of this is that You know where You are, in which room/floor (at what AP)
I've made something like that -
viewtopic.php?f=23&t=31&start=100#p27521 - first blocky
Two of them, for my wife two MACs - Domoticz know my wife is home, and my two MACs - Domoticz know i'm home. Then third blocky, with both of them, to check if we are in home.
I know i could probably make it with one blocky, but now, as i said, i can also check where in home we are, and let say...turn lights off in area, where nobody is pesent

Ik have an AP as well. I like to ad the virtual MAC to the script. Any Idea where I can find the virtual MAC address?
Verstuurd vanaf mijn SM-G935F met Tapatalk
On Your router, on device list.
____
may
Re: Yet another presence detection method
Posted: Tuesday 14 February 2017 20:01
by Sudden81
Surroot wrote:Sudden81 wrote:Sorry I'm a beginner and have big problems with programming lua, but most copying and pasting.
My question is simply this, could this be implemented of Domoticz. Or is that too complicated?
You choose your router from a list, then downloading something _ which one can instalera on the router. It was called "Asus Merlin custom firmware" or something like that?
You choose what the user's mac address you want to use.
You choose which network to trigger the 2.5GHz or 5GHz.
You choose the name of virituel switch, and boom, you have a virituel presence switch.
The result will be the same as programming yourself but it gets super much easier for users.
Is this a stupid idea or this would be feasible.
Yes I think it's possible to implement this.
Maybe I put all those steps from the presence detection setup in a script in the future, which would be a lot easier for new users to setup the presence detection. But you still have to flash the router firmware manually, I don't think thats a good idea to let another software handle the flash process.
Totally agree, not so good with a program that flashes someones router.
I welcome as script!
Thanks in advance!
Re: RE: Re: RE: Re: RE: Re: Yet another presence detection method
Posted: Tuesday 14 February 2017 22:34
by BaliBiker
mayyam wrote:BaliBiker wrote:mayyam wrote:
I also have AP.
And i'm getting two MACs. One is real MAC, and second is virtual MAC:
AC:C1:EE:12:39:24 - real one
02:0F:B5:12:39:24 - virtual, from AP
..............
Ik have an AP as well. I like to ad the virtual MAC to the script. Any Idea where I can find the virtual MAC address?
Verstuurd vanaf mijn SM-G935F met Tapatalk
On Your router, on device list.
____
may
Unfortunately my router doesn't show a virtual MAC address. It shows only one MAC address even when the phone is connected with the AP. Although my router shows my phone in the device list and it is connected via the AP the script reacts as if the phone is not connected. I understand that this logical as the phone is not directly connected with the wifi of the router.
Is the any way to work around this problem?
Verstuurd vanaf mijn SM-G935F met Tapatalk