Yet another presence detection method

Moderator: leecollings

vulbas
Posts: 37
Joined: Tuesday 20 February 2018 17:59
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Yet another presence detection method

Post by vulbas »

vulbas wrote: Tuesday 06 March 2018 19:48 hello,
finaly that work for my phone !!! :D :D

but i whant put an another phone, and that don't work :(

Code: Select all

cru a PRESENCE "*/1 * * * * /jffs/scripts/presence_detection 74:23:44:F7:2C:9B 3701"
cru a PRESENCE "*/1 * * * * /jffs/scripts/presence_detection D4:A3:3D:20:51:69 3705"
how to add a second phone on the code ?
the IDX is only 3701 on this code :(

Code: Select all

#!/bin/sh

mac=$1
idx=$2
device_present=Off
domoticz_status=`curl -s "xxxxxxxxxxxxxxx/json.htm?type=devices&rid=3701" | 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 "xxxxxxxxxxxxxxxxxx/json.htm?type=command&param=switchlight&idx=3701&switchcmd=On" > /dev/null
 else
        curl -s "xxxxxxxxxxxxxxxxxxxxx/json.htm?type=command&param=switchlight&idx=3701&switchcmd=Off" > /dev/null
 fi
fi
Nobody can help me ? :( :( :( :( :)
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 »

@vulbas

Please delete your script and create it again - and don't edit it!
rrozema
Posts: 470
Joined: Thursday 26 October 2017 13:37
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Delft
Contact:

Re: Yet another presence detection method

Post by rrozema »

vulbas wrote: Tuesday 06 March 2018 20:21 ho thank you.
it worked without the "
but i do not know how to have two phone :(
You have to assign each schedule a unique name. i.e. change PRESENCE into something unique, simply numbering them or adding the name of the owner will do:

Code: Select all

cru a PRESENCE_PHONE1 "*/1 * * * * /jffs/scripts/presence_detection 74:23:44:F7:2C:9B 3701
cru a PRESENCE_PHONE2 "*/1 * * * * /jffs/scripts/presence_detection D4:A3:3D:20:51:69 3705
vulbas
Posts: 37
Joined: Tuesday 20 February 2018 17:59
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Yet another presence detection method

Post by vulbas »

thank you for your help,
I change the two lines, it's the same.
I think the problem comes from nano presence_detection.
in nano presence_detection it points to device 3701

Image
rrozema
Posts: 470
Joined: Thursday 26 October 2017 13:37
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Delft
Contact:

Re: Yet another presence detection method

Post by rrozema »

As surroot said: go back and use the original script content. All of the ', ", spaces and so on in there are important... Also, don't put in additional line breaks or such. Only change the ip address of your domoticz machine plus login details as per the original instructions (I can't read the details in your image as it is to small, so i can't give you any specific details on what is wrong)


edit: the 3701 read $idx in the original file. This is probably something you edited yourself at some point.
Last edited by rrozema on Friday 09 March 2018 18:12, edited 1 time in total.
vulbas
Posts: 37
Joined: Tuesday 20 February 2018 17:59
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Yet another presence detection method

Post by vulbas »

I will try again.
here is the link of the image :)

https://i62.servimg.com/u/f62/17/98/85/70/putty_10.png

it works very well, but with only one phone
timop
Posts: 57
Joined: Sunday 03 January 2016 17:10
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Yet another presence detection method

Post by timop »

Dont add idx number to script.
Just leave as is in original ($idx)
In cru command you set right idx number with one idx per line to so many phone that you want.
vulbas
Posts: 37
Joined: Tuesday 20 February 2018 17:59
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Yet another presence detection method

Post by vulbas »

je ne comprends pas,
j'ai tout essayé.
je suis désésperé.

I do not understand,
I have tried everything.
I am desperate. :cry: :cry: :cry: :cry:

clic on thumbail

Image

Image

Image

can you send me your nano presence_detection?
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 »

vulbas wrote: Saturday 10 March 2018 14:18 je ne comprends pas,
j'ai tout essayé.
je suis désésperé.

I do not understand,
I have tried everything.
I am desperate. :cry: :cry: :cry: :cry:

clic on thumbail

Image

Image

Image

can you send me your nano presence_detection?
Take the code from the first picture.
Set your cursor after each \ and press the "Enter" key to create a new line. Save the file with Ctrl+O and exit with Ctrl+X.
See if its working then.
vulbas
Posts: 37
Joined: Tuesday 20 February 2018 17:59
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Yet another presence detection method

Post by vulbas »

i the code from the first picture.
it does not work automatically, I do not understand
I made a video

[youtube]https://www.youtube.com/watch?v=fgJLP3Y ... e=youtu.be[/youtube]

when i put ./presence_detection 74:23:44:F7:2C:9B 3989 i have no

[: Off: unknown operand
or
[: On: unknown operand
rrozema
Posts: 470
Joined: Thursday 26 October 2017 13:37
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Delft
Contact:

Re: Yet another presence detection method

Post by rrozema »

Some hints (or things that I've done wrong):
  • The \-sign in the script is a line-continuation character: the command was to long to fit on a single line and was split over multiple lines by the author of the script. At the end of each line he/she added a \-character to indicate the command goes on at the next line. Editing such lines in nano can be cumbersome. I think it is easier to have long lines, so what I do, is to remove the \-characters and put the multiple lines back into one long line again.
  • If something in the script doesn't work, try executing that line from the bash command line to see what is going on.
  • Each phone needs to have a unique switch assigned to it in domoticz, so for each phone you must specify a unique value for idx. The actual value to use can be found in domoticz in the devices list, it is the number under the label "Idx".
  • Each phone has a unique mac address, so for each phone you must specify a unique value for the mac address.
    Depending on the program your script uses -for those that didn't notice yet: there a multiple methods presented in this thread-, you must specify the mac address either in all capitals or in all small caps. If your script uses the wl-command, you need to specify the mac address in capitals. A script that uses the arp-command needs the mac address in small caps.
  • The name of each schedule must be unique. Use a unique name for each cru -entry. In the following example the names are PRESENCE_PHONE1 and PRESENCE_PHONE2:

    Code: Select all

    cru a PRESENCE_PHONE1 "*/1 * * * * /jffs/scripts/presence_detection 74:23:44:F7:2C:9B 3701
    cru a PRESENCE_PHONE2 "*/1 * * * * /jffs/scripts/presence_detection D4:A3:3D:20:51:69 3705
    If you're not sure what tasks you've got scheduled already, enter

    Code: Select all

    cru l
    (the last letter is a small L, for list)
  • The scheduled tasks list gets cleared when the router is restarted. For this reason you must add the cru-commands in a script that gets executed after the router is restarted. This script is called "init-start" and it is located in the /jffs/scripts/ folder in your router. The init-start script must contain the same lines that you've issued before:

    Code: Select all

    cru a PRESENCE_PHONE1 "*/1 * * * * /jffs/scripts/presence_detection 74:23:44:F7:2C:9B 3701
    cru a PRESENCE_PHONE2 "*/1 * * * * /jffs/scripts/presence_detection D4:A3:3D:20:51:69 3705
vulbas
Posts: 37
Joined: Tuesday 20 February 2018 17:59
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Yet another presence detection method

Post by vulbas »

thx for your help rrozema

when i put "cru l" i have =

*/1 * * * * /jffs/scripts/presence_detection 74:23:44:F7:2C:9B IDX3701
cru a PRESENCE */1 bin cifs1 cifs2 dev etc home jffs lib media mmc mnt opt proc rom root sbin sys sysroot tmp usr var www bin cifs1 cifs2 dev etc home jffs lib media mmc mnt opt proc rom root sbin sys sysroot tmp usr var www bin cifs1 cifs2 dev etc home jffs lib media mmc mnt opt proc rom root sbin sys sysroot tmp usr var www bin cifs1 cifs2 dev etc home jffs lib media mmc mnt opt proc rom root sbin sys sysroot tmp usr var www /jffs/scripts/presence_detection D4:A3:3D:20:51:69 IDX3705 #PRESENCE#
11 2 */7 * * service restart_letsencrypt #LetsEncrypt#

do you think it is correct ?
how to access init-star ?

but the same problem, it does not work automatically where is the problem, i don't understand.

[youtube]https://www.youtube.com/watch?v=YqAlbyN ... e=youtu.be[/youtube]

Image
rrozema
Posts: 470
Joined: Thursday 26 October 2017 13:37
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Delft
Contact:

Re: Yet another presence detection method

Post by rrozema »

No. Not correct. Use

Code: Select all

cru --help
to find how to remove those entries.

Check that you have no more entries with cru l.
Then add new entries with just the number of the switch. No idx in front of it, only the 3701 or whatever number your switch for that phone has.

First test your presence script by manually executing it with the mac address and idx number. If it doesn't work, get that fixed first. Once have the command working, copy it, write it down or take a photo so you can keep it. Only when it works for the first phone, do the same thing for another phone.

After you've got the script working for both phones, you can go ahead and create schedule for one of the phones: Just copy one of the lines, starting with "cru a" from my earlier posts. I'm pretty sure they are correct already, but in case the script call you've found above is different, put that in and then paste it into your bash window and press enter to execute it. Now test if it works for the one phone. Be patient, it may take up to some minutes before the status gets automatically updated.

Then copy the other "cru a"-command, put your other phone's script call in there, paste it and press enter to execute this too. Now check if the 2nd phone's status updates.

You can use "cru l" to list the scheduled tasks at any time. Make sure you have 1 task per phone and make sure each task has the proper script call you tested before. Is it different? Start over.

After all that is done come back and ask for instructions how to edit init-start to make your not forget your scripts after a restart.
vulbas
Posts: 37
Joined: Tuesday 20 February 2018 17:59
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Yet another presence detection method

Post by vulbas »

I do not have "idx" in front of my idx.


#! /bin/sh

cru a PRESENCE_SEB "*/1 * * * * /jffs/scripts/presence_detection 74:23:44:F7:2C:9B 3701"


I think the problem is in the script.
with this sript it works very well and automatically. but only for one phone of course
Image

with this script it does not work automatically
Image

hhhhhhheeeeeeeeeeeeeeellllllllllpppppppppppppp me please :cry: :cry: :cry: :cry: :cry: :cry: :D
rrozema
Posts: 470
Joined: Thursday 26 October 2017 13:37
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Delft
Contact:

Re: Yet another presence detection method

Post by rrozema »

vulbas wrote: Monday 12 March 2018 17:52 I do not have "idx" in front of my idx.
Yes, you do:
vulbas wrote: Monday 12 March 2018 16:07 when i put "cru l" i have =

*/1 * * * * /jffs/scripts/presence_detection 74:23:44:F7:2C:9B IDX3701
cru a PRESENCE */1 bin cifs1 cifs2 dev etc home jffs lib media mmc mnt opt proc rom root sbin sys sysroot tmp usr var www bin cifs1 cifs2 dev etc home jffs lib media mmc mnt opt proc rom root sbin sys sysroot tmp usr var www bin cifs1 cifs2 dev etc home jffs lib media mmc mnt opt proc rom root sbin sys sysroot tmp usr var www bin cifs1 cifs2 dev etc home jffs lib media mmc mnt opt proc rom root sbin sys sysroot tmp usr var www /jffs/scripts/presence_detection D4:A3:3D:20:51:69 IDX3705 #PRESENCE#
11 2 */7 * * service restart_letsencrypt #LetsEncrypt#
You need to clean up the mess that you've made with earlier attempts and start fresh: Lookup the help for the cru-command and see how to delete the existing entries from there (I'm not in the opportunity to look it up right now). There may very well be other problems in your scripts as well, but you should only work on one problem at a time, as you don't understand yet what you're doing...
vulbas
Posts: 37
Joined: Tuesday 20 February 2018 17:59
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Yet another presence detection method

Post by vulbas »

I formatted my jffs. I redo tests.

ASUSWRT-Merlin RT-AC88U 384.3-0 Tue Feb 13 21:09:45 UTC 2018
admin@RT-AC88U-2648:/tmp/home/root# cd /jffs/scripts/
admin@RT-AC88U-2648:/jffs/scripts# cru l
*/5 * * * * service restart_letsencrypt #LetsEncrypt#

edit :

I reinstalled everything, same problem.
it works if I do "./presence_detection 74:23:44:F7:2C:9B 3701"
but it does not work automatically.
I am desperate

EDIT 2

I am very very happy. it works !!!!!!!
I reinstalled the script, restarted the router and it worked for 2 phone
a thousand thanks rrozema for your help (cru l)

:) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :)
quack3d
Posts: 86
Joined: Sunday 26 March 2017 17:03
Target OS: -
Domoticz version:
Contact:

Re: Yet another presence detection method

Post by quack3d »

Just wanted to thank you for this great script. Works nicely.
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 »

quack3d wrote: Thursday 02 August 2018 9:31 Just wanted to thank you for this great script. Works nicely.
Can only state the same i used it first only for presence detection so that lights would only be switched on when home but worked it a bit out.
System has now a Pir that checks with a Blockly of the "Anyone present" is on or off when off then it sets a virtual switch to arm Alarm system and active some led's. When pir detects motion it will send via a script an Http command to my iSpy server to start recording for 30 minutes and sends an image via Telegram to me.

So actually i build a whole alarm system around it :)
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 »

Hiya.
I've got almost everything working as it should.
Besides sending to Domoticz.

The router are :
AdvancedTomato
Version: 3.5-140
Router Model: Asus RT-AC68R/U

I have the default scripts in the /jffs/scripts

Code: Select all

root@unknown:/jffs/scripts# ll
-rwxr-xr-x    1 root     root           239 Aug  5 10:03 init-start*
-rwxr-xr-x    1 root     root           870 Aug  5 10:10 presence_detection*

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"

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'`

# 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://192.168.0.141:8080/json.htm?type=command&param=switchlight&idx=$idx&switchcmd=On" > /dev/null
 else
        curl -s "http://192.168.0.141:8080/json.htm?type=command&param=switchlight&idx=$idx&switchcmd=Off" > /dev/null
 fi
fi
But noting happens.

When I run ./presence_detection 58:48:22:A4:4E:D2 625
The output are

Code: Select all

root@unknown:/jffs/scripts# ./presence_detection 58:48:22:A4:4E:D2 625
[: On: unknown operand
root@unknown:/jffs/scripts#
But it wont send the status to Domoticz

Its working when I send the string manual.

Code: Select all

root@unknown:/jffs/scripts# curl -s "http://192.168.0.141:8080/json.htm?type=command&param=switchlight&idx=625&switchcmd=On"
{
   "status" : "OK",
   "title" : "SwitchLight"
}
.

Will it work on AdvanceTomato or do I have the change the firmware.


Regards Magnus Svensson
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

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'`


When I run ./presence_detection 58:48:22:A4:4E:D2 625
The output are 
[code]root@unknown:/jffs/scripts# ./presence_detection 58:48:22:A4:4E:D2 625
[: On: unknown operand
root@unknown:/jffs/scripts#
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?
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest