How to check presence of Beacon ?

Topics (not sure which fora)
when not sure where to post, post here and mods will move it to right forum.

Moderators: leecollings, remb0

woody4165
Posts: 476
Joined: Monday 14 March 2016 13:55
Target OS: Linux
Domoticz version: beta
Location: Rome, Italy
Contact:

Re: How to check presence of Beacon ?

Post by woody4165 »

VERY NICE!!!!! :D

It's working.
I need to launch with sudo (don't know why).
When the python script has been launched it remains running without exiting, right?
So it should not be launched by crontab, how can I launch it when the RPi boot (or reboot)?

Then the uservariable can be checked in a Lua Device script (better that time one?) ?

Thanks again for sharing!!!!!
Cubietruck - Linux cubietruck 4.13.16 (Debian GNU/Linux 8 (jessie)) + Domoticz + RFLink, Xiaomi Gateway, Owl USB, Yeelight Color and B/W, ESP8266, Broadlink RM2, Netatmo Thermostat
korniza
Posts: 157
Joined: Thursday 27 August 2015 18:12
Target OS: Raspberry Pi / ODroid
Domoticz version: V3.6028
Location: Greece
Contact:

Re: How to check presence of Beacon ?

Post by korniza »

I runned for some hours and I see that script random lose all BLE NUT (AWAY) for a while. Also if script restarted and beacons are labeled as HOME, but they moved away, script does not put them away. still it is unstable comparing to FHEM. Still it is a good start and promising to get a domoticz service for BLE presence. :)
>>>> Google Home <<<<<
SBC: Odroid XU4 * Raspberry Pi2 * banana Pi v1
Peripherals: rfxtrx433E, aeon z-stick gen5, bluetooth dongles
Extended Software packages: Xeoma (video NVR), FHEM (extra home automation software)
jmleglise
Posts: 192
Joined: Monday 12 January 2015 23:27
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.1
Location: FRANCE
Contact:

Re: How to check presence of Beacon ?

Post by jmleglise »

@korniza :

you need continuous update only for "presence" ? right ? (not for "absence")
Last edited by jmleglise on Saturday 07 May 2016 9:52, edited 1 time in total.
My script : https://github.com/jmleglise
RFXTRX433E: Blind Somfy RTS, Portal Somfy Evolvia, chacon IO, Oregon, PIR sensor PT2262
My Last project : Location de vacances a Ouistreham vue mer
KMTronic USB relay
Chinese Z-WAVE: Neo CoolCam
jmleglise
Posts: 192
Joined: Monday 12 January 2015 23:27
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.1
Location: FRANCE
Contact:

Re: How to check presence of Beacon ?

Post by jmleglise »

@woody :

For using user variables in Lua scripts, there are three tables available: uservariables, uservariables_lastupdate and uservariablechanged. The uservariablechanged table (with only the variable that triggered the event) is only available in your event scripts (script_variable_name.lua), the other two are always available. Reference your variable by name, e.g. if uservariables["MyVar"] = ...

Have a look here : https://www.domoticz.com/wiki/Events
My script : https://github.com/jmleglise
RFXTRX433E: Blind Somfy RTS, Portal Somfy Evolvia, chacon IO, Oregon, PIR sensor PT2262
My Last project : Location de vacances a Ouistreham vue mer
KMTronic USB relay
Chinese Z-WAVE: Neo CoolCam
jmleglise
Posts: 192
Joined: Monday 12 January 2015 23:27
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.1
Location: FRANCE
Contact:

Re: How to check presence of Beacon ?

Post by jmleglise »

@woody

My script is multi thread. No crontab , a service is better to start with raspberry. I will look after that later.

TODO :
- Transform this script in a linux service (/etc/init.d) ...
My script : https://github.com/jmleglise
RFXTRX433E: Blind Somfy RTS, Portal Somfy Evolvia, chacon IO, Oregon, PIR sensor PT2262
My Last project : Location de vacances a Ouistreham vue mer
KMTronic USB relay
Chinese Z-WAVE: Neo CoolCam
korniza
Posts: 157
Joined: Thursday 27 August 2015 18:12
Target OS: Raspberry Pi / ODroid
Domoticz version: V3.6028
Location: Greece
Contact:

Re: How to check presence of Beacon ?

Post by korniza »

jmleglise wrote:@korniza :

you need continuous update only for "presence" ? right ? (not for "absence")
not only for presence. I need also to arm security panel, so if a sensor in home activated (when i am away) to do some sttuff (send sms for example)
>>>> Google Home <<<<<
SBC: Odroid XU4 * Raspberry Pi2 * banana Pi v1
Peripherals: rfxtrx433E, aeon z-stick gen5, bluetooth dongles
Extended Software packages: Xeoma (video NVR), FHEM (extra home automation software)
jmleglise
Posts: 192
Joined: Monday 12 January 2015 23:27
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.1
Location: FRANCE
Contact:

Re: How to check presence of Beacon ?

Post by jmleglise »

korniza,

I'm not sure to understand you well. Could you precise your needs ?

For example :
- My tag broadcasts at different rate. Sometimes every 4 secondes and sometimes several times per secondes. Do you want that domoticz is updated at the same frequency ? (This will conduct to an issue : Several times per secondes can cause a saturation of the server)

- if the tag is away : how frequently should domoticz be updated ?
My script : https://github.com/jmleglise
RFXTRX433E: Blind Somfy RTS, Portal Somfy Evolvia, chacon IO, Oregon, PIR sensor PT2262
My Last project : Location de vacances a Ouistreham vue mer
KMTronic USB relay
Chinese Z-WAVE: Neo CoolCam
jmleglise
Posts: 192
Joined: Monday 12 January 2015 23:27
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.1
Location: FRANCE
Contact:

Re: How to check presence of Beacon ?

Post by jmleglise »

and get my update :
Version : 1.1 Log + Mac Adress case insensitive
https://github.com/jmleglise/mylittle-d ... resence.py

With the verbose log system, you may follow how does your beacon work.
Last edited by jmleglise on Saturday 07 May 2016 16:17, edited 1 time in total.
My script : https://github.com/jmleglise
RFXTRX433E: Blind Somfy RTS, Portal Somfy Evolvia, chacon IO, Oregon, PIR sensor PT2262
My Last project : Location de vacances a Ouistreham vue mer
KMTronic USB relay
Chinese Z-WAVE: Neo CoolCam
woody4165
Posts: 476
Joined: Monday 14 March 2016 13:55
Target OS: Linux
Domoticz version: beta
Location: Rome, Italy
Contact:

Re: How to check presence of Beacon ?

Post by woody4165 »

Is it normal that I get this CPU % from the python script, the only one that is running since I'm on an RPi3 where is located Domoticz, but not running since it's a test environment, and no other stuff?

Code: Select all

  PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND    
 xxxx root      20   0   43128  11796   6068 S 110,4  1,2   7:42.64 python     


Cpu temp also raised more than 60°C from normal 40°C.

Is it because I'm running (don't know why, but for me the only way) as "sudo python" ?
I launched it as

Code: Select all

sudo python check_beacon_presence &
Thanks


PS: After last update, now it seems normal CPU% use by python!!!
Cubietruck - Linux cubietruck 4.13.16 (Debian GNU/Linux 8 (jessie)) + Domoticz + RFLink, Xiaomi Gateway, Owl USB, Yeelight Color and B/W, ESP8266, Broadlink RM2, Netatmo Thermostat
jmleglise
Posts: 192
Joined: Monday 12 January 2015 23:27
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.1
Location: FRANCE
Contact:

Re: How to check presence of Beacon ?

Post by jmleglise »

korniza wrote:Also if script restarted and beacons are labeled as HOME, but they moved away, script does not put them away.
Fix in v1.2
https://raw.githubusercontent.com/jmleg ... resence.py

Could you confirm ?
My script : https://github.com/jmleglise
RFXTRX433E: Blind Somfy RTS, Portal Somfy Evolvia, chacon IO, Oregon, PIR sensor PT2262
My Last project : Location de vacances a Ouistreham vue mer
KMTronic USB relay
Chinese Z-WAVE: Neo CoolCam
jmleglise
Posts: 192
Joined: Monday 12 January 2015 23:27
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.1
Location: FRANCE
Contact:

Re: How to check presence of Beacon ?

Post by jmleglise »

woody4165 wrote: Cpu temp also raised more than 60°C from normal 40°C.
PS: After last update, now it seems normal CPU% use by python!!!

hi,

the summer is going to be hot :-)

I've fixed this in the v1.1
My script : https://github.com/jmleglise
RFXTRX433E: Blind Somfy RTS, Portal Somfy Evolvia, chacon IO, Oregon, PIR sensor PT2262
My Last project : Location de vacances a Ouistreham vue mer
KMTronic USB relay
Chinese Z-WAVE: Neo CoolCam
jmleglise
Posts: 192
Joined: Monday 12 January 2015 23:27
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.1
Location: FRANCE
Contact:

Re: How to check presence of Beacon ?

Post by jmleglise »

The script takes around 0,2% CPU now. And for you ?
My script : https://github.com/jmleglise
RFXTRX433E: Blind Somfy RTS, Portal Somfy Evolvia, chacon IO, Oregon, PIR sensor PT2262
My Last project : Location de vacances a Ouistreham vue mer
KMTronic USB relay
Chinese Z-WAVE: Neo CoolCam
jmleglise
Posts: 192
Joined: Monday 12 January 2015 23:27
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.1
Location: FRANCE
Contact:

Re: How to check presence of Beacon ?

Post by jmleglise »

And now the installation as a service (and auto run at start of the raspberryPi)

Copy the daemon file https://raw.githubusercontent.com/jmleg ... n_presence to /etc/init.d

Code: Select all

sudo cp check_beacon_presence /etc/init.d
sudo chmod 755 /etc/init.d/check_beacon_presence
Copy the python script https://raw.githubusercontent.com/jmleg ... resence.py to /usr/local/bin

Code: Select all

sudo cp check_beacon_presence.py /usr/local/bin
sudo chmod 755 /usr/local/bin/check_beacon_presence.py
To launch the script :

Code: Select all

sudo /etc/init.d/check_beacon_presence restart
And to run the script at each reboot of the server :

Code: Select all

sudo update-rc.d check_beacon_presence defaults
Last edited by jmleglise on Saturday 07 May 2016 17:23, edited 2 times in total.
My script : https://github.com/jmleglise
RFXTRX433E: Blind Somfy RTS, Portal Somfy Evolvia, chacon IO, Oregon, PIR sensor PT2262
My Last project : Location de vacances a Ouistreham vue mer
KMTronic USB relay
Chinese Z-WAVE: Neo CoolCam
woody4165
Posts: 476
Joined: Monday 14 March 2016 13:55
Target OS: Linux
Domoticz version: beta
Location: Rome, Italy
Contact:

Re: How to check presence of Beacon ?

Post by woody4165 »

I'm getting this error on service restart

Code: Select all

[....] Restarting check_beacon_presence (via systemctl): check_beacon_presence.serviceFailed to restart check_beacon_presence.service: Unit check_beacon_presence.service failed to load: No such file or directory.
 failed!
I have /usr/local/bin/check_beacon_presence.py and is set to 755 as well as the /etc/init.d/check_beacon_presence

what I can check?

Thanks
Cubietruck - Linux cubietruck 4.13.16 (Debian GNU/Linux 8 (jessie)) + Domoticz + RFLink, Xiaomi Gateway, Owl USB, Yeelight Color and B/W, ESP8266, Broadlink RM2, Netatmo Thermostat
jmleglise
Posts: 192
Joined: Monday 12 January 2015 23:27
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.1
Location: FRANCE
Contact:

Re: How to check presence of Beacon ?

Post by jmleglise »

woody4165 wrote:I'm getting this error on service restart

Code: Select all

check_beacon_presence.service failed to load: No such file or directory.
Thanks
Hi,

1/ Make sure that the both files are in UNIX format. (If DOS format, convert them. Check with nano :
sudo nano check_beacon_presence
Ctrl+o to save
Alt+d to alternate betwen DOS and Unix/Linux line-endings.
Press enter
Ctrl+x

2/ Dont' forget to modify check_beacon_presence.py to configure log to file :

Code: Select all

# choose between DEBUG (log every information) or CRITICAL (almost no log)
#logLevel=logging.DEBUG
logLevel=logging.CRITICAL
logOutFilename='/var/log/check_beacon_presence.log'
Then you have several command to test: start, stop, restart, status
sudo /etc/init.d/check_beacon_presence status

Does-it work ?
My script : https://github.com/jmleglise
RFXTRX433E: Blind Somfy RTS, Portal Somfy Evolvia, chacon IO, Oregon, PIR sensor PT2262
My Last project : Location de vacances a Ouistreham vue mer
KMTronic USB relay
Chinese Z-WAVE: Neo CoolCam
woody4165
Posts: 476
Joined: Monday 14 March 2016 13:55
Target OS: Linux
Domoticz version: beta
Location: Rome, Italy
Contact:

Re: How to check presence of Beacon ?

Post by woody4165 »

I have used the dos2unix command since I don't understand (in a Osx Terminal) which command should I do to convert after Ctrl-o
Shame on me!!! :roll:
Image

I get the same error.

I checked also the log stuff but I have it on CRITICAL

Code: Select all

# choose between DEBUG (log every information) or CRITICAL (almost no log)
#logLevel=logging.DEBUG
logLevel=logging.CRITICAL
logOutFilename='/var/log/check_beacon_presence.log'       # comment this line to console output
In any case, when I created the file in /etc/init.d I did directly from terminal with sudo nano, probably was directly in Unix format.

Don't understand where is the issue on my side...
Cubietruck - Linux cubietruck 4.13.16 (Debian GNU/Linux 8 (jessie)) + Domoticz + RFLink, Xiaomi Gateway, Owl USB, Yeelight Color and B/W, ESP8266, Broadlink RM2, Netatmo Thermostat
woody4165
Posts: 476
Joined: Monday 14 March 2016 13:55
Target OS: Linux
Domoticz version: beta
Location: Rome, Italy
Contact:

Re: How to check presence of Beacon ?

Post by woody4165 »

In the meantime I made a tiny script to check my Nut when entering home, turn on a light and I work like a charm!
Really impressive!
Thanks again for sharing... [WINKING FACE]
Cubietruck - Linux cubietruck 4.13.16 (Debian GNU/Linux 8 (jessie)) + Domoticz + RFLink, Xiaomi Gateway, Owl USB, Yeelight Color and B/W, ESP8266, Broadlink RM2, Netatmo Thermostat
jmleglise
Posts: 192
Joined: Monday 12 January 2015 23:27
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.1
Location: FRANCE
Contact:

Re: How to check presence of Beacon ?

Post by jmleglise »

2 ideas :

1/ Of course, when you try to launch the service (start), you don't have an another instance still running ?
check with this :

Code: Select all

ps -ef | grep check
=> reboot to be sure. and after reboot test the "status" command.

Code: Select all

sudo /etc/init.d/check_beacon_presence status
2/And in the check_beacon_presence modify the first line to root :

Code: Select all

DAEMON_USER=root
My script : https://github.com/jmleglise
RFXTRX433E: Blind Somfy RTS, Portal Somfy Evolvia, chacon IO, Oregon, PIR sensor PT2262
My Last project : Location de vacances a Ouistreham vue mer
KMTronic USB relay
Chinese Z-WAVE: Neo CoolCam
woody4165
Posts: 476
Joined: Monday 14 March 2016 13:55
Target OS: Linux
Domoticz version: beta
Location: Rome, Italy
Contact:

Re: How to check presence of Beacon ?

Post by woody4165 »

Great!

It's working now!.
First I changed the DAEMON to root in the /etc/init.d/check_beacon_presence and rebooted
Working
Then I just tried to set again pi as DAEMON, rebooted, and worked again.
I'm sure that I previously rebooted several times, but now is the working one.

Thanks again!

Just to let you know that I tried also to monitor a Mi Band 1S, but I think it doesn't transmit continuously, since I got the AWAY and HOME after a lot of time (several minutes) while for the Nut it's almost immediate!!!!

I think you need to make a Wiki on this!
Cubietruck - Linux cubietruck 4.13.16 (Debian GNU/Linux 8 (jessie)) + Domoticz + RFLink, Xiaomi Gateway, Owl USB, Yeelight Color and B/W, ESP8266, Broadlink RM2, Netatmo Thermostat
jmleglise
Posts: 192
Joined: Monday 12 January 2015 23:27
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.1
Location: FRANCE
Contact:

Re: How to check presence of Beacon ?

Post by jmleglise »

Good. I'am happy to hear that from you.

Yep i'll do a wiki
My script : https://github.com/jmleglise
RFXTRX433E: Blind Somfy RTS, Portal Somfy Evolvia, chacon IO, Oregon, PIR sensor PT2262
My Last project : Location de vacances a Ouistreham vue mer
KMTronic USB relay
Chinese Z-WAVE: Neo CoolCam
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 1 guest