Yet another presence detection method

Moderator: leecollings

mayyam
Posts: 47
Joined: Saturday 14 January 2017 11:29
Target OS: Linux
Domoticz version: 4.11333
Location: Poland
Contact:

Re: Yet another presence detection method

Post by mayyam »

Hi,

i'm on the Tomato firmware, and when i'm testing the script, i'm getting:

Code: Select all

wl: wl driver adapter not found
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.
_______________
- Dell FX-160 / Ubuntu 16.04
- RFLink 433Mhz / NRF 2.4GHz
- 2x Xiaomi Gateway
- different species of ESP8266
mayyam
Posts: 47
Joined: Saturday 14 January 2017 11:29
Target OS: Linux
Domoticz version: 4.11333
Location: Poland
Contact:

Re: Yet another presence detection method

Post 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&param=switchlight&idx=$idx&switchcmd=On" > /dev/null
 else
	curl -s "http://domoticzUser:domoticzPassword@domoticzIP:domoticzPort/json.htm?type=command&param=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!
_______________
- Dell FX-160 / Ubuntu 16.04
- RFLink 433Mhz / NRF 2.4GHz
- 2x Xiaomi Gateway
- different species of ESP8266
User avatar
sincze
Posts: 1299
Joined: Monday 02 June 2014 22:46
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.4
Location: Netherlands / Breda Area
Contact:

Re: Yet another presence detection method

Post by sincze »

nice. :D

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
Pass2php
LAN: RFLink, P1, OTGW, MySensors
USB: RFXCom, ZWave, Sonoff 3
MQTT: ZIgbee2MQTT,
ZWAVE: Zwave-JS-UI
WIFI: Mi-light, Tasmota, Xiaomi Shelly
Solar: Omnik, PVOutput
Video: Kodi, Harmony HUB, Chromecast
Sensors: You name it I got 1.
mayyam
Posts: 47
Joined: Saturday 14 January 2017 11:29
Target OS: Linux
Domoticz version: 4.11333
Location: Poland
Contact:

Re: Yet another presence detection method

Post by mayyam »

sincze wrote:nice. :D

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 ;)
_______________
- Dell FX-160 / Ubuntu 16.04
- RFLink 433Mhz / NRF 2.4GHz
- 2x Xiaomi Gateway
- different species of ESP8266
User avatar
sincze
Posts: 1299
Joined: Monday 02 June 2014 22:46
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.4
Location: Netherlands / Breda Area
Contact:

Re: Yet another presence detection method

Post by sincze »

:D :D 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 . :shock: and top floor ... off again. pfff
Pass2php
LAN: RFLink, P1, OTGW, MySensors
USB: RFXCom, ZWave, Sonoff 3
MQTT: ZIgbee2MQTT,
ZWAVE: Zwave-JS-UI
WIFI: Mi-light, Tasmota, Xiaomi Shelly
Solar: Omnik, PVOutput
Video: Kodi, Harmony HUB, Chromecast
Sensors: You name it I got 1.
mikl10
Posts: 5
Joined: Thursday 28 August 2014 18:56
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Yet another presence detection method

Post by mikl10 »

Hello, thank you for sharing your script.
Did someone has already testing that with iPhone?did it work when iPhone is sleeping?
User avatar
Surroot
Posts: 31
Joined: Wednesday 18 January 2017 11:28
Target OS: Linux
Domoticz version: beta
Location: Vienna
Contact:

Re: Yet another presence detection method

Post 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!
BaliBiker
Posts: 11
Joined: Saturday 30 January 2016 16:06
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Yet another presence detection method

Post 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!!
User avatar
Surroot
Posts: 31
Joined: Wednesday 18 January 2017 11:28
Target OS: Linux
Domoticz version: beta
Location: Vienna
Contact:

Re: Yet another presence detection method

Post 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!
BaliBiker
Posts: 11
Joined: Saturday 30 January 2016 16:06
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Yet another presence detection method

Post 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&param=switchlight&idx=$idx&switchcmd=On" > /dev/null
else
curl -s "http://XXX:[email protected]:8080/json.htm?\type=command&param=switchlight&idx=$idx&switchcmd=Off" > /dev/null
fi
fi
mayyam
Posts: 47
Joined: Saturday 14 January 2017 11:29
Target OS: Linux
Domoticz version: 4.11333
Location: Poland
Contact:

Re: Yet another presence detection method

Post by mayyam »

I also get:
[: Off: unknown operand
or
[: On: unknown operand

But it's working.
_______________
- Dell FX-160 / Ubuntu 16.04
- RFLink 433Mhz / NRF 2.4GHz
- 2x Xiaomi Gateway
- different species of ESP8266
User avatar
PeGe
Posts: 25
Joined: Tuesday 31 January 2017 14:21
Target OS: Raspberry Pi / ODroid
Domoticz version: V3.6328
Location: Sollentuna, Sweden
Contact:

Re: Yet another presence detection method

Post 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...". :o

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
User avatar
Surroot
Posts: 31
Joined: Wednesday 18 January 2017 11:28
Target OS: Linux
Domoticz version: beta
Location: Vienna
Contact:

Re: Yet another presence detection method

Post 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...". :o

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&param=switchlight&idx=$idx&switchcmd=On" > /dev/null
else
curl -s "http://XXX:[email protected]:8080/json.htm?\type=command&param=switchlight&idx=$idx&switchcmd=Off" > /dev/null
fi
fi
BaliBiker: You should correct these three lines in your script
Sudden81
Posts: 8
Joined: Wednesday 08 February 2017 8:21
Target OS: -
Domoticz version:
Contact:

Re: Yet another presence detection method

Post 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.
BaliBiker
Posts: 11
Joined: Saturday 30 January 2016 16:06
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Yet another presence detection method

Post by BaliBiker »

Many thanks Surroot. That did the job. Its all working fine now.

Verstuurd vanaf mijn SM-G935F met Tapatalk
User avatar
Surroot
Posts: 31
Joined: Wednesday 18 January 2017 11:28
Target OS: Linux
Domoticz version: beta
Location: Vienna
Contact:

Re: Yet another presence detection method

Post 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.
BaliBiker
Posts: 11
Joined: Saturday 30 January 2016 16:06
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: RE: Re: Yet another presence detection method

Post by BaliBiker »

mayyam wrote:
sincze wrote:nice. :D

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
mayyam
Posts: 47
Joined: Saturday 14 January 2017 11:29
Target OS: Linux
Domoticz version: 4.11333
Location: Poland
Contact:

Re: RE: Re: RE: Re: Yet another presence detection method

Post by mayyam »

BaliBiker wrote:
mayyam wrote:
sincze wrote:nice. :D

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
_______________
- Dell FX-160 / Ubuntu 16.04
- RFLink 433Mhz / NRF 2.4GHz
- 2x Xiaomi Gateway
- different species of ESP8266
Sudden81
Posts: 8
Joined: Wednesday 08 February 2017 8:21
Target OS: -
Domoticz version:
Contact:

Re: Yet another presence detection method

Post 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!
BaliBiker
Posts: 11
Joined: Saturday 30 January 2016 16:06
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: RE: Re: RE: Re: RE: Re: Yet another presence detection method

Post 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
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest