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

Post Reply
User avatar
blackdog65
Posts: 311
Joined: Tuesday 17 June 2014 18:25
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Norfolk, UK
Contact:

Re: How to check presence of Beacon ?

Post by blackdog65 »

for this purpose there's no need for domoticz, just a running copy of raspian (or flavour of choice). I actually do use a domoticz image by habit because as a non programer I can add to that raspi via gpio or piface or MySensors usb gateway and it can then (as in my poly tunnel) work independantly and communicate 2-way with the master domoticz.

But as I say, for these BT setups it's just there unused for now.

Sean
CubieTruck Master
RasPi slaves
Aeon Labs Z-Stick, multi sensor
Fibaro Dimmers, relays, Universal sensors
EQ3 MAX!
TKB Sockets
RFXCOM
LightwaveRF sockets, switches, relays, doorbell
MySensors
ESPEasy ESP8266-12E
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 »

Hi everyone,

Could you please, resume all the problems you have, (with errors output, and maximum information. distrib of your Linux...) and all the testings you have made without success.

I will have a look this wk.

thank 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
User avatar
blackdog65
Posts: 311
Joined: Tuesday 17 June 2014 18:25
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Norfolk, UK
Contact:

Re: How to check presence of Beacon ?

Post by blackdog65 »

jmleglise wrote:Hi everyone,

Could you please, resume all the problems you have, (with errors output, and maximum information. distrib of your Linux...) and all the testings you have made without success.

I will have a look this wk.

thank you,
Hi Buddy! :D

Provided that my units run using the cron script, I'm happy. It's what my American friend calls "A $10 call girl. Not pretty, but gets the job done." :lol:
However they work and can either set a variable or switch (depending which version of the .py script I use).

My big desire is to harvest the RSSI into a variable that I can use to mark specific locations reasonably accurately. At the moment, with 4 devices, I have 4 overlapping circles which is not very accurate at all... But still VERY useful :D

Huge thanks for your hard work

Sean (Jean en français) :lol:
CubieTruck Master
RasPi slaves
Aeon Labs Z-Stick, multi sensor
Fibaro Dimmers, relays, Universal sensors
EQ3 MAX!
TKB Sockets
RFXCOM
LightwaveRF sockets, switches, relays, doorbell
MySensors
ESPEasy ESP8266-12E
User avatar
Westcott
Posts: 423
Joined: Tuesday 09 December 2014 17:04
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: UK - Glos
Contact:

Re: How to check presence of Beacon ?

Post by Westcott »

What sort of range is everybody getting, using which beacons and receivers?

I've had a look at the Python script, it will take a little bit of work to get it to send both presence and strength.
One way would be to extend a beacon's definition to add an idx for strength.
Zwave - Sigma Z+ stick, Fibaro, Horstmann, Neo Coolcam, EUROtronic
RFlink - IR detectors and temperatures
Wifi - YeeLights, ESP32s, Anoop sockets
Zigbee - lots with zigbee2mqtt and ZbBridge
User avatar
blackdog65
Posts: 311
Joined: Tuesday 17 June 2014 18:25
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Norfolk, UK
Contact:

Re: How to check presence of Beacon ?

Post by blackdog65 »

Hi Westcott,
I quite agree, though I don't know how.
As I said in a previous post, the signal strength isn't linear i.e. drops by 10 per 2 paces. Also it's affected by obstacles, signal bounce and other factor such as manufacturer.
RSSI-Value-Changes-By-Distance.png
RSSI-Value-Changes-By-Distance.png (11.53 KiB) Viewed 3101 times
From http://blog.bluetooth.com/proximity-and-rssi/

I've found that a stationary Nut Tag's RSSI can fluctuate by about 5 points give or take, although a script could take an average over a given time.
All my RSSI readings are dramatically affected by my crazy thick walls which makes life difficult for all wireless tech :(
I'd like to find the RSSI average for say 3 raspis for a nut being at point "X" and a script, when seeing those parameters met, can say with some confidence that the Nut has reached point "X".
CubieTruck Master
RasPi slaves
Aeon Labs Z-Stick, multi sensor
Fibaro Dimmers, relays, Universal sensors
EQ3 MAX!
TKB Sockets
RFXCOM
LightwaveRF sockets, switches, relays, doorbell
MySensors
ESPEasy ESP8266-12E
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 »

Hi,

This is version 1.3

Code: Select all

wget https://raw.githubusercontent.com/jmleglise/mylittle-domoticz/master/Presence%20detection%20%28beacon%29/check_beacon_presence.py
- Script takes care of hciconfig. switch down , then UP the bluetooth adapter. And report to log each error. So no need to use any more hciconfig before launching the script.
- script operates now in 2 mode. Choose for each beacon wich one you want :
REPEAT MODE : When beacon is in range, update the uservariable every 3 secondes with the RSSI. And "AWAY" otherwise.
SWITCH_MODE : When beacon is in range, update only 1 time the uservariable with "HOME". And "AWAY" otherwise.

Kind regard,
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
Raspberry Piet
Posts: 158
Joined: Saturday 11 January 2014 16:21
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: NL
Contact:

Re: How to check presence of Beacon ?

Post by Raspberry Piet »

jmleglise wrote:Hi,

This is version 1.3
Just tried your excellent script, works great with Nut Beacons. Detection is very fast!
As i understand it will scan only for BLE devices and not also for ordinary bluetooth devices like smartphones?

Thanks for the script!
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 »

Thanks!!!
It's working like a charm also with me and without the hciconfig stuff in crontab

Is it correct the in the /etc/init.d/check_presence_beacon I need to have DAEMON=root and not =pi?

I tried with pi and I get the active(exited) instead of active(running) in the status.

Maybe I'm asking too much, but it would be nice to have a switch to get the status instead of HOME/AWAY and an uservariable to get the RSSI.

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 »

Thank you, you're welcome !

@ Raspberry Piet : this script is only for BLE 4.0
Bluetooth and bluetooth 4.0 are 2 protocols totally different. For Bluetooth, there are already severals solutions in the forum

Yes, fast detection is a must have. I choose this technology to be fast enough, to enter my house and desactivate my alarm before Alarm detection.

@woody :
Yes, for me too, root owner is needed for the DAEMON. I haven't undestood why.

For the switch, you can do it easily yourself.
Create a LUA script_device : On uservariablechange then : if uservariable=="AWAY" then switch Off else switch On
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
Raspberry Piet
Posts: 158
Joined: Saturday 11 January 2014 16:21
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: NL
Contact:

Re: How to check presence of Beacon ?

Post by Raspberry Piet »

jmleglise wrote:I choose this technology to be fast enough, to enter my house and desactivate my alarm before Alarm detection.
What about the possibility of the mac address could be spoofed?
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 »

I think that someone able to spoof macAddress or jam a wireless Alarm has better to rob than my home :lol:

To such a degree that I have let the Mac Address in the source code of my script ! :lol:


(Seriously : you 're right : it's possible to change mac address on some bluetooth adapter).
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:I think that someone able to spoof macAddress or jam a wireless Alarm has better to rob than my home :lol:

To such a degree that I have let the Mac Address in the source code of my script ! :lol:


(Seriously : you 're right : it's possible to change mac address on some bluetooth adapter).
Still you can bond the NUT with another device (for example get nfc tag sticker to your NUT). ;) and use it as a second layer of id.
>>>> 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)
Raspberry Piet
Posts: 158
Joined: Saturday 11 January 2014 16:21
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: NL
Contact:

Re: How to check presence of Beacon ?

Post by Raspberry Piet »

It is possible with the Nut app to make the Nut Beacon beep (find keys when lost), is it somehow possible to do the same through a script?
User avatar
blackdog65
Posts: 311
Joined: Tuesday 17 June 2014 18:25
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Norfolk, UK
Contact:

Re: How to check presence of Beacon ?

Post by blackdog65 »

Hi guys,

I've found time this evening to have a play with the new script (which works beautifully thank you jmeglise!) but as I mainly use blockly I've hit a snag (maybe not for lua) in that the numeric RSSI output (i.e. -74) is a string and needs to be in the " " blockly block and so will not work with operators such as ≥ ≤ etc.

Is there a simple lua method of asking "if string_variable_x ≤ -51 or ≥ -71 then xxxxx" or does the string need to be "converted" to an integer.

Please excuse my ignorance but I speak more Russian than I do Lua :lol:

Sean
PS I agree with the beeping nut idea... my wife will lose hers on day one :roll:
CubieTruck Master
RasPi slaves
Aeon Labs Z-Stick, multi sensor
Fibaro Dimmers, relays, Universal sensors
EQ3 MAX!
TKB Sockets
RFXCOM
LightwaveRF sockets, switches, relays, doorbell
MySensors
ESPEasy ESP8266-12E
User avatar
jvdz
Posts: 2441
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: How to check presence of Beacon ?

Post by jvdz »

This will test the numeric value of the string in LUA:

Code: Select all

if tonumber(string_variable_x) <= -51 or tonumber(string_variable_x) >= -71 then
Should it be between those 2 values ( AND relation) or do you really mean an OR relation here?

Jos
User avatar
blackdog65
Posts: 311
Joined: Tuesday 17 June 2014 18:25
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Norfolk, UK
Contact:

Re: How to check presence of Beacon ?

Post by blackdog65 »

WOW! That was quick!
Hi Jos,

Yes I'm looking for a value between the two values inclusive

Many thanks

Sean
CubieTruck Master
RasPi slaves
Aeon Labs Z-Stick, multi sensor
Fibaro Dimmers, relays, Universal sensors
EQ3 MAX!
TKB Sockets
RFXCOM
LightwaveRF sockets, switches, relays, doorbell
MySensors
ESPEasy ESP8266-12E
User avatar
jvdz
Posts: 2441
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: How to check presence of Beacon ?

Post by jvdz »

blackdog65 wrote:Yes I'm looking for a value between the two values inclusive
So that means you need an and in the logic:

Code: Select all

if tonumber(string_variable_x) <= -51 and tonumber(string_variable_x) >= -71 then
User avatar
blackdog65
Posts: 311
Joined: Tuesday 17 June 2014 18:25
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Norfolk, UK
Contact:

Re: How to check presence of Beacon ?

Post by blackdog65 »

brilliant! I'll soon be writing lua like... well an amateur, but I'm trying. :lol:

many thanks again for your help

Sean
CubieTruck Master
RasPi slaves
Aeon Labs Z-Stick, multi sensor
Fibaro Dimmers, relays, Universal sensors
EQ3 MAX!
TKB Sockets
RFXCOM
LightwaveRF sockets, switches, relays, doorbell
MySensors
ESPEasy ESP8266-12E
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 would like to use the new RSSI to trigger based on value what to do, but I don't understand what to trigger and how.

With the AWAY/HOME I had a script based on uservariable event like this:

Code: Select all

commandArray = {}

if uservariablechanged['NutG'] == "AWAY" then
        commandArray['OpenURL']="https://api.telegram.org/botxxx/sendMessage?chat_id=xxx&text=yyyyyy"
elseif  uservariablechanged['NutG'] == "HOME" then
        commandArray['OpenURL']="https://api.telegram.org/botxxx/sendMessage?chat_id=xxx&text=yyyyyy"
elseif  uservariablechanged['NutC'] == "AWAY" then
        uservariables['orauscita'] = os.time()
        commandArray['OpenURL']="https://api.telegram.org/botxxx/sendMessage?chat_id=xxx&text=yyyyyy"
        commandArray['PresaGiu']='Off'	
elseif  uservariablechanged['NutC'] == "HOME" then
        nuovaora=os.time()
        differenza = nuovaora - uservariables['orauscita']
        if ((differenza > 300) and (otherdevices['IsDark']=="On")) then
        commandArray['OpenURL']="https://api.telegram.org/botxxx/sendMessage?chat_id=xxx&text=yyyyyy"
            commandArray['PresaGiu']='On'	
        end
end

return commandArray
Now with a continuos update of the value of the uservariables, I understood, maybe I'm wrong, that the script have to be device event type, and not uservariable.

Then, what I should trigger to have a functionality like the previous one, based this time on RSSI values ?

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
User avatar
blackdog65
Posts: 311
Joined: Tuesday 17 June 2014 18:25
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Norfolk, UK
Contact:

Re: How to check presence of Beacon ?

Post by blackdog65 »

Lolz @ Woody :lol:
I'm in the same position.
I have just tried this with help from Jos

Code: Select all

commandArray = {}
for variableName,variableValue in pairs(uservariablechanged) do
	if (variableName=='Zhenya_SitRm') then
	if tonumber(variableValue) <= -51 and tonumber(variableValue) >= -71 then
            commandArray['ZSitRoomBT'] = "On"
        end
    end
    if (variableName=='Zhenya_SitRm') then
        if variableValue == "AWAY" then
            commandArray['ZSitRoomBT'] = "Off"
        end
    end
end
return commandArray
Where "ZSitRoomBT" is a virtual switch for testing

but it doesn't work (I don't get lua yet :roll: )
In the log I get

Code: Select all

[string "-- script_variable_bt.lua..."]:5: attempt to compare nil with number
Help!!! :cry:
CubieTruck Master
RasPi slaves
Aeon Labs Z-Stick, multi sensor
Fibaro Dimmers, relays, Universal sensors
EQ3 MAX!
TKB Sockets
RFXCOM
LightwaveRF sockets, switches, relays, doorbell
MySensors
ESPEasy ESP8266-12E
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest