Yet another presence detection method

Moderator: leecollings

Melotron
Posts: 62
Joined: Tuesday 22 November 2016 21:04
Target OS: Linux
Domoticz version: 2020.2
Location: Gothenburg
Contact:

Re: Yet another presence detection method

Post by Melotron »

Surroot wrote: Sunday 05 August 2018 10:57

Try running

Code: Select all

curl -s "http://192.168.0.141:8080/json.htm?type=devices&rid=625 | grep Status | awk '{print $3}' | sed 's/[",]//g'
manually. What does the output say?

Code: Select all

root@unknown:/jffs/scripts# curl -s "http://192.168.0.141:8080/json.htm?type=dev
ices&rid=625" | grep Status | awk '{print $3}' | sed 's/[",]//g'
Off
root@unknown:/jffs/scripts#
It is working as it should.
Its the main scripts that's not behaving as it should "I think"
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 »

Melotron wrote: Sunday 05 August 2018 10:50

Code: Select all

#! /bin/sh
cru a PRESENCE "*/1 * * * * /jffs/presence_detection C4:9F:4C:EE:F1:B7 623"
cru a PRESENCE "*/1 * * * * /jffs/presence_detection C4:9F:4C:EF:E9:8A 624"
cru a PRESENCE "*/1 * * * * /jffs/presence_detection 58:48:22:A4:4E:D2 625"
Besides: I think the path in your cru script is wrong. The "scripts" folder is missing above.

To your initial problem: You could try to debug the script by adding

Code: Select all

echo "here"
or similar to the script. For example starting after the first "done". Then run the script

Code: Select all

./presence_detection 58:48:22:A4:4E:D2 625
and watch if "here" is written to the screen. Then tell me where it stops working. Maybe we can work it out.
Melotron
Posts: 62
Joined: Tuesday 22 November 2016 21:04
Target OS: Linux
Domoticz version: 2020.2
Location: Gothenburg
Contact:

Re: Yet another presence detection method

Post by Melotron »

Surroot wrote: Sunday 05 August 2018 12:07
To your initial problem: You could try to debug the script by adding

Code: Select all

echo "here"
or similar to the script. For example starting after the first "done". Then run the script

Code: Select all

./presence_detection 58:48:22:A4:4E:D2 625
and watch if "here" is written to the screen. Then tell me where it stops working. Maybe we can work it out.
I've edited my init script.
Here are my new script with a few echo. Thanks for the idea =)

Code: Select all

#!/bin/sh

mac=$1
idx=$2
device_present=Off
domoticz_status=`curl -s "http://192.168.0.141:8080/json.htm?type=devices&rid=$idx" | grep Status | awk '{print $3}' | sed 's/[",]//g'`

echo "device_present"

# 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

echo "2.4GHz"

# 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

echo "5GHz"

# tell domoticz the new device status
if [ $domoticz_status != $device_present ]; then
		echo "$domoticz_status"
 if [ $device_present = "On" ]; then
 		echo "$domoticz_present2"
        curl -s "http://192.168.0.141:8080/json.htm?type=command&param=switchlight&idx=$idx&switchcmd=On" > /dev/null
		echo "Send On"
 else
        curl -s "http://192.168.0.141:8080/json.htm?type=command&param=switchlight&idx=$idx&switchcmd=Off" > /dev/null
		echo "Send Off"
 fi
fi
It stops right after 5ghz check.

Code: Select all

root@unknown:/jffs/scripts# ./presence_detection 58:48:22:A4:4E:D2 625
device_present
2.4GHz
5GHz
root@unknown:/jffs/scripts#
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 »

Which state does device_present have?
When it stops there, it means, that it has no update to send to the server.

Can you run

Code: Select all

wl -i eth2 assoclist | awk '{print $2}'
without issues?
And does it list your MAC address when you connect to one of your networks?
Melotron
Posts: 62
Joined: Tuesday 22 November 2016 21:04
Target OS: Linux
Domoticz version: 2020.2
Location: Gothenburg
Contact:

Re: Yet another presence detection method

Post by Melotron »

Surroot wrote: Wednesday 08 August 2018 7:18 Which state does device_present have?
When it stops there, it means, that it has no update to send to the server.

Can you run

Code: Select all

wl -i eth2 assoclist | awk '{print $2}'
without issues?
And does it list your MAC address when you connect to one of your networks?
It might work, but the router dosent like this script at all.
Image
https://imgur.com/a/csW7oLu
Now I cant access the routers web gui.

Even when I remove the scripts the same web gui problem are there.
Are there any way to turn off jffs on console?

Im going to try a few things but if that dosent work I need to reset the router.
So it might take me a few days to continue to get this script to work.

Or is there any way to have a rasp ping the mac adress instead the router ?
Prutsium
Posts: 92
Joined: Monday 18 June 2018 11:31
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Germany / Netherlands
Contact:

Re: Yet another presence detection method

Post by Prutsium »

If your router has SSH option you can try the alternative way: Python script look at this one: http://www.domoticz.com/forum/viewtopic ... 65&t=20467

This is a bit less complicated to use and works flawless.
Melotron
Posts: 62
Joined: Tuesday 22 November 2016 21:04
Target OS: Linux
Domoticz version: 2020.2
Location: Gothenburg
Contact:

Re: Yet another presence detection method

Post by Melotron »

Prutsium wrote: Wednesday 08 August 2018 9:44 If your router has SSH option you can try the alternative way: Python script look at this one: http://www.domoticz.com/forum/viewtopic ... 65&t=20467

This is a bit less complicated to use and works flawless.
Thanks I'll look in to that.
I am atm rebuiding my network.

After a reflash of the router so are the web gui still dead at 192.168.0.X but its working with 192.168.1.X
So I am in the middle of configuring 11 jails on my server and the rest of the phones and pads. Oh the joy!
Good thing that I have little over 1 more week of vacation LOL

A good advice, STAY away from huawei P20 pro. They are just the same as iPhones on net work presence.
Good battery life, ok camera but crappy crappy network that goes over to be unreachable even when the screen are on and your watching youtube =)
Prutsium
Posts: 92
Joined: Monday 18 June 2018 11:31
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Germany / Netherlands
Contact:

Re: Yet another presence detection method

Post by Prutsium »

Melotron wrote: Wednesday 08 August 2018 23:18 A good advice, STAY away from huawei P20 pro. They are just the same as iPhones on net work presence.
Good battery life, ok camera but crappy crappy network that goes over to be unreachable even when the screen are on and your watching youtube =)
With the suggested presence detection i just gave you i have no issues with iPhones.
Actually also with the one you used i had no issues. I just switched to the other script as it's easier to setup and add phones.
hendryman
Posts: 9
Joined: Sunday 22 October 2017 16:20
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Yet another presence detection method

Post by hendryman »

on executing this command:

Code: Select all

wl -i eth1 assoclist
i get this error:

Code: Select all

wl: wl driver adapter not found
i searched the forums but did not find a solution.
my router is an rc-86u with merlin firmware 384.9.
can anybody please tell me how to tweak the syntax to get the presence script working?
zicht
Posts: 251
Joined: Sunday 11 May 2014 11:09
Target OS: Windows
Domoticz version: 2023.1+
Location: NL
Contact:

Re: Yet another presence detection method

Post by zicht »

Prutsium wrote: Thursday 09 August 2018 9:45
Melotron wrote: Wednesday 08 August 2018 23:18 A good advice, STAY away from huawei P20 pro. They are just the same as iPhones on net work presence.
Good battery life, ok camera but crappy crappy network that goes over to be unreachable even when the screen are on and your watching youtube =)
With the suggested presence detection i just gave you i have no issues with iPhones.
Actually also with the one you used i had no issues. I just switched to the other script as it's easier to setup and add phones.
for the pro (all android >v6) you need to turn of smart switching if you have weakspots as they will use 4G in weakspots. Choose a good 2.4gHz channel in bussy surroundings like mine, or use 5gHz networking.

I use mainly arp detection at the moment, all Iphones and P20 pro behave like they should (network wise) and stay visible,
There is no problem for precence detection if they stay on the wifi. Using arp turned out to be very reliable for me with only a small delay.
Rpi & Win x64. Using : cam's,RFXCom, LaCrosse, RFY, HuE, google, standard Lua, Tasker, Waze traveltime, NLAlert&grip2+,curtains, vacuum, audioreceiver, smart-heating&cooling + many more (= automate all repetitive simple tasks)
dbgnu76
Posts: 2
Joined: Wednesday 06 December 2017 21:59
Target OS: Windows
Domoticz version:
Contact:

Re: Yet another presence detection method

Post by dbgnu76 »

Just wanna share with you that it also works fine with AC5300 And merlin ,,with lightly modify in code ,,,
Had to add eth3 also. :D

Code: Select all

#!/bin/sh

mac=$1
idx=$2
device_present=Off
domoticz_status=`curl -s "http://XXXX:[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 5G-1 (eth2) network for device
for x in `wl -i eth2 assoclist | awk '{print $2}'`; do
 if [ $x = $mac ]; then
        device_present=On
 fi
done

# look in 5G-2 (eth3) network for device
for x in `wl -i eth3 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://XXXX:[email protected]:8080/json.htm?type=command&param=switchlight&idx=$idx&switchcmd=On" > /dev/null
 else
        curl -s "http://XXXX:[email protected]:8080/json.htm?type=command&param=switchlight&idx=$idx&switchcmd=Off" > /dev/null
 fi
fi

And i also modified this: the original code is every second minut

Code: Select all

#! /bin/sh
cru a PRESENCE "*/1 * * * * /jffs/scripts/presence_detection MAC-ADDRESS IDX"
the shortest time in cron is 1 minut

Code: Select all

#! /bin/sh
cru a PRESENCE "1 * * * * /jffs/scripts/presence_detection MAC-ADDRESS IDX"




but i wanted a faster update than cron can provide, much faster respons now (15sec) and it works like a charm :D
keep in mind that i have no other scripts running in jffs

Code: Select all

#! /bin/sh

while [ true ]; do
 sleep 15
/jffs/scripts/presence_detection XX:XX:XX:XX:XX:XX 204

/jffs/scripts/presence_detection XX:XX:XX:XX:XX:XX 280
done
Last edited by dbgnu76 on Tuesday 14 January 2020 0:53, edited 1 time in total.
Calzor Suzay
Posts: 145
Joined: Tuesday 08 July 2014 15:10
Target OS: -
Domoticz version: 4.9700
Location: UK
Contact:

Re: Yet another presence detection method

Post by Calzor Suzay »

Has anyone ever 'tweaked' this script to email out via gmail?

I use it for mine and wifes phones which works great to update Domoticz.
Just need it to check a cabled device and if it can't see it then email me.
The cabled device is a Vero4k running Domoticz over a powerline adapter.

I guess it's a case of running a different script with...
if [ $device_present = "On" ]; then
curl -s "http://domoticzUser:domoticzPassword@domoticzIP:domoticzPort/json.htm?\
type=command&param=switchlight&idx=$idx&switchcmd=On" > /dev/null

emailing rather than running, curl.
Need to figure that bit out now :D
quack3d
Posts: 86
Joined: Sunday 26 March 2017 17:03
Target OS: -
Domoticz version:
Contact:

Re: Yet another presence detection method

Post by quack3d »

Why don't you just make a blockly in Domoticz that notifies you via e-mail when device is updated in Domoticz?
Calzor Suzay
Posts: 145
Joined: Tuesday 08 July 2014 15:10
Target OS: -
Domoticz version: 4.9700
Location: UK
Contact:

Re: Yet another presence detection method

Post by Calzor Suzay »

quack3d wrote: Friday 27 September 2019 15:52 Why don't you just make a blockly in Domoticz that notifies you via e-mail when device is updated in Domoticz?
Because I'm trying to ascertain if the box Domoticz runs on is still on the network :o
If it's off the network it won't be able to email anything :D
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 »

Maybe there is an exim4 package for the router? Then you could send emails.

Br
Surroot
Matthew
Posts: 1
Joined: Wednesday 09 November 2022 20:51
Target OS: -
Domoticz version:
Contact:

Re: Yet another presence detection method

Post by Matthew »

A very old thread and I'm using this script for years and years with various domotica controllers (Homey, Home Assistant, etc). I has proved to be a rock solid solution. Therefor I'm feeling obliged to create an account and post an update here for people that started using AImesh to extend their WiFi range. In that case the script will not work, because it will not show the devices connected to the mesh device/repeater.

I came here to post the solution for this. Instead of looking to 2.4Ghz and 5Ghz interfaces, use this single section as replacement:

Code: Select all

# look in network for device
for x in `ip neigh|  awk '{print $5}'`; do

 if [ $x = $mac ] ; then
        device_present=on
 fi
done
I hope at least I can help one person with this. Cheers!
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests