Jump to content
Guides for the Forum Read more... ×
Poradniki na Forum Read more... ×
macjoker

[TUTORIAL] Presence detector - iNode LAN + any BLE gadget (and no more devices)

Recommended Posts

 

Please login or register to see this attachment.

Please login or register to see this attachment.

 

I recently came up with an idea to keep track of each resident presence with Bluetooth devices they keep taking with them. To achieve that I bought iNode LAN device, which can bring BLE devices into existence in Ethernet network. The idea was not really that... fresh as I thought. Just see

Please login or register to see this link.

. But I definitely didn't want to use any other pieces of equipment. And this post is about how to get all these things work together (HC2 + iNode LAN) with full source code attached.

 

What you need (except your HC2):

  1. Please login or register to see this link.

     - it can detect any Bluetooth 4.0/4.1 device (Bluetooth Low Energy = BLE)
  2. BLE tag (

    Please login or register to see this link.

    ,

    Please login or register to see this link.

    Please login or register to see this link.

    , etc.)

 

Remarks about the list above:


Instead of iNode LAN, you could buy an extended version iNode LAN Duos, but I don't recommend that. Why? The "Duos" version has equipment for both BLE and Bluetooth 2.1 so that you could detect older devices too. But these devices most probably will not be proper for the goal we want to achieve. Bluetooth 2.1 devices have shorter range and drain the battery much more quickly. If we use them for identifying persons we can experience more "flickering" about someone's presence (range issues). Moreover, changing the battery of a small device attached to a bunch of keys every few days or weeks (not months!) would make the solution too hard for maintenance. If we are going to stick to BLE devices, the "non-Duos" version is good enough.


Instead of iNode Beacon you can use any device that you can carry with you. The device has to communicate via BLE, that's all. That might be your smartphone as long as you keep your Bluetooth ON all the time.

 

What should you do:

  1. Configure your iNode LAN to use unicast or broadcast for sending datagrams (UDP packets)
    • Go to the Setup page.
    • For "BLE IP address" put your HC2 IP address (unicast) or broadcast address (192.168.1.255 e.g.)
  2. Go back to your HC2 and:
    • Create a new global variable for storing BLE events (BleDevices).
    • Create a new global variable for each person to be tracked.
  3. Download two files attached to this post.
  4. Create a new virtual device (BLE Detector). Read detailed steps inside the source code.
  5. Create a new scene (BLE Users). Again - read steps inside the source code.
  6. Update config values in the scene (provide names and MAC addresses of persons and their belongings).

 

That's all to make it work!
Now you can use global variables you have defined in step "2-second-dot" to check if a person is away or home.
 

Want to tweak it? Sure!

There are more options. Please read all comments in the source code.

 

You may try to:

  • define MACs of devices to ignore in discovery (your iNode LAN itself),
  • define signal values for IN/OUT events (separately for each user),
  • define the timeout value for each device (this also makes user away),
  • turn on/off debug messages.

 

What are these scripts missing?

Only basic information is decoded from BLE datagrams (counter, MAC address, and signal strength). If you use iNode Sensors you will not get additional values (like temperature, pressure, magnetic or movement changes).

 

Why is it better than other solution (x) of presence detection?

  • It does not depend on any movement in your house,  which can make many false positives - a running dog e.g. (x = motion sensors)
  • It is independent of other devices. HC2 communicates directly with iNode LAN. (x = RaspberryPi to read iNode and press some virtual buttons in HC2)
  • More stable results (x = python script from iNode website; explained below). 

 

The Python script published by iNode manufacturer for presence detection uses only signal strength. That means to detect that someone is leaving we need to use some (lower part) signal range to have the record of going away. This additionally reduces the signal range for detecting "being home" (higher part of the signal range) and can give effect to the person appearing and disappearing all the time.

To avoid that we also check the latest timestamp of the device activity. Owing to this feature we may extend range signal for "being home" to all possible values, and use only timeout to decide whether a person is home or not (set "-100" to both signalIn and signalOut in users config to achieve that).

 

 

A few more details. Here are some logs of the working device...

Please login or register to see this code.

and the scene:

Please login or register to see this code.

 

For my configuration, I am using two pieces of notiOne. They are really tiny, the batteries are supposed to stay alive for about a year. Additionally, you can track them whenever someone with BLE and their App is near. 


The results I get in my flat, where walls are made of silicate blocks, are quite stable. iNode LAN can detect these notiOnes with the weakest signal (-90 to -88 dBm) from a distance of 7-8 meters even through two silicate walls (24cm + 12cm thick). So placing iNode LAN in the middle of the flat covers the whole area.
 

 

Edited by macjoker
  • Like 1
  • Thanks 1

Share this post


Link to post
Share on other sites

Hi, thanks for you great work!

 

The presense detection is very convinient for home automation. But BLE is small range cover, somtimes my BLE smartwatches disconnecting from mobile when i go other room.

So, this is definatley NOT suitable for a big house.

 

I guess, the WiFi is better for this. But I have not seen ready solution for Fibaro. There is homebridge-people plugin I have tested for the Apple HomeKit and it works fine (for me)

It works this way: there is an array of people (actually host ip addresses) preconfigured, each host shows as presense sensor inside HomeKit.

It starts ping loop for every host and breach the sensor when it cross detection threshold.

 

If someone knows equal solution for the Fibaro, let me know, please

 

BR

Share this post


Link to post
Share on other sites

I have an issue with the scense. When I try to run it I get an error. I have set BleDevices as Predefined Variable as Table (I will get the following error if I just put it as a regular variable [ fatal] Unknown exception: /opt/fibaro/scenes/41.lua:93: bad argument #1 to 'pairs' (table expected, got number)

 

 

Please login or register to see this code.

What else I miss?

The other variables (for example isZenekHome) what type they have to be? Do I need to insert the ip address/port of the inode device on the VD? Does it work on different subnets?

Please Help!

 

Share this post


Link to post
Share on other sites

it worked! it seems that there is another "hardware" limitation. iNode LAN has limited coverage on a house so it is not good for everyone. I wonder if we can increase coverage adding multiple iNode devices or even better hack the antenna. 

Share this post


Link to post
Share on other sites
Posted (edited)

@korniza so what type of global variable for both VD and Scene to make everything works?

Edited by Sirhideo

Share this post


Link to post
Share on other sites

BleDevices -> Table

all the other -> common variables

Share this post


Link to post
Share on other sites
Posted (edited)
On 3/28/2018 at 5:26 PM, korniza said:

BleDevices -> Table

all the other -> common variables

 

hi @korniza,

 

Table..........common....?

 

Do you mean

 

Table: upper part of global variable screen

common: lower part, i.e. predefined variable?

 

Thanks

Edited by Sirhideo

Share this post


Link to post
Share on other sites

Hello, @macjoker,

 

is this solution still working? I have purchased TrackR pixels and inode LAN.   On HC2 I have below issues.

 

SCENE:

[DEBUG] 00:43:28: [1,31m2018-04-19 00:43:28.2888709 [fatal] Unknown exception:

/opt/fibaro/scene/260.lua:100 bad argument #1 to 'pairs' (table expected, got number)

 

VIRTUAL DEVICE:

 

IGNORED_DEVICES = { ["11:22:33:44:55:66"] = true }

For those mac addresses I would like to ignore, what is the correct syntax to put them in?

 

Update IP Address and TCP Port. Use the same values as for iNode LAN.

What is the port of iNode LAN, 80?

 

iNODE LAN SETUP PAGE:

What is the port of BLE IP Port, default 20000?

 

Thanks

Share this post


Link to post
Share on other sites
On 4/6/2018 at 5:33 PM, Sirhideo said:

 

hi @korniza,

 

Table..........common....?

 

Do you mean

 

Table: upper part of global variable screen

common: lower part, i.e. predefined variable?

 

Thanks

 

Hi @korniza

 

Ok so after an hour of trial and error I understand that BleDevices is a predefined global variable and its value is "table" ..

After this is done I get the exactly same error message as you got...

Please, may I know how do you fix it?

Share this post


Link to post
Share on other sites
3 hours ago, Sirhideo said:

 

Hi @korniza

 

Ok so after an hour of trial and error I understand that BleDevices is a predefined global variable and its value is "table" ..

After this is done I get the exactly same error message as you got...

Please, may I know how do you fix it?

1st on iNode you need to configure port 20000 and ip address that broadcast to be on the BROADCAST IP of the NETWORK that both devices are placed.

I assume you use a 255.255.255.0 mask and lets say that both devices are registered with ip 192.168.1.xx . 

On i-Node you need to set on ip field the ip 192.168.1.255 and port 20000. On the VD on fibaro you need to set ip address of VD on 192.168.1.255 and port 20000.

Another trick is to delete and create back again the variables with tables.

It did worked for me.

hoped I helped a bit.

Share this post


Link to post
Share on other sites

nice to hear! Still if you use BLE tags for presence detection, you need to find reliable one because most of them have small wireless range.

Share this post


Link to post
Share on other sites

@korniza, you are right, gonna test the trackr pixel. By the way how about ignore device, do you know how to set this up?

 

IGNORED_DEVICES = { ["11:22:33:44:55:66"] = true }

 

comma seperated? my inode lan can scans through my neigbhour...

Share this post


Link to post
Share on other sites

it looks like this...

IGNORED_DEVICES = { ["08:EF:3B:1F:DC:BE"] = true, 
                    ["56:48:47:A5:13:F5"] = true,
                    ["C6:89:74:94:E2:09"] = true }

Share this post


Link to post
Share on other sites

it is a very early version of a device that uses the previous sence/vd for iNode. I build it to check the presence of family members. If you like, you can build an avatar of person from 

Please login or register to see this link.

The key is that a user may have more that one BLE device to track, so I wanted to check if one of the tags/mobiles/etc is missing. In my case my children do not have any keys, so I use BLE tags on their bags. The problem is that they use different bags for school, after school activitis.

So you need to add as many tags on the BlueUserTable. As it is a very basic version you need to search from the variable table.

for example 

Please login or register to see this code.

Also if user is a real Fibaro User (my pet cat does not have access ;D) you need to enter the id on FibaroUser. Else (if it a cat with BLE collar) you leave it empty.

The reason that I want to use UserID is to get coordinates of the user when they are away and display a AWAY message with a url to google maps with log/lat of user.

 

If someone like this, I like to get help to make it compatible with HomeTable, SMsgH, Home Status from @Sankotronic and others.

Please login or register to see this attachment.

Share this post


Link to post
Share on other sites
Posted (edited)

@korniza Hi, is this VD running on top of original author's VD and Scene?  Right now I am having hard time to determine the suitable in/out signal for 5 beacons due to the original BLE users scene debug windows shows way too many dummy BT devices. I have exclude as many devices as possible in VD but not much use since new strange devices keep coming from iNode LAN... (if original author see my post could you make the VD include devices instead of exclude?)

 

I cannot rely on the scene debug log to see dbm for each device when I am outside main door and try to remote control my PC browser (with BLE users scene debug screen) because the log keep scrolling..

 

Can you please elaborate more about your VD/solution? or maybe some screen shot would help me understand more.

Edited by Sirhideo

Share this post


Link to post
Share on other sites
1 hour ago, Sirhideo said:

@korniza Hi, is this VD running on top of original author's VD and Scene?  Right now I am having hard time to determine the suitable in/out signal for 5 beacons due to the original BLE users scene debug windows shows way too many dummy BT devices. I have exclude as many devices as possible in VD but not much use since new strange devices keep coming from iNode LAN... (if original author see my post could you make the VD include devices instead of exclude?)

 

I cannot rely on the scene debug log to see dbm for each device when I am outside main door and try to remote control my PC browser (with BLE users scene debug screen) because the log keep scrolling..

 

Can you please elaborate more about your VD/solution? or maybe some screen shot would help me understand more.

I used @macjoker VD and Sence. I suppose that you have already set a number of variables that respond to the names of your ble tags on Sence "BLE Users". Even without my VD, you can use the variables to any sence to trigger actions.

 

Please login or register to see this attachment.

Please login or register to see this attachment.

Please login or register to see this attachment.

Share this post


Link to post
Share on other sites
Posted (edited)

I have talked to iNode support and he is willing to update the firmware approximately next week, to implement whitelist function, not sure how, maybe on LOCK page.

 

This will enable iNode Lan to detect only specific devices, in terms of mac, instead of scanning everything.  this decreases the udp packet size received by hc2.

Edited by Sirhideo

Share this post


Link to post
Share on other sites

hello!

I face issues with stability of inode. After a week it seems that it crashing (no web gui) and there is no active connection with HC2.

Did you get any firmware that is stable?

Share this post


Link to post
Share on other sites
Posted (edited)
52 minutes ago, korniza said:

hello!

I face issues with stability of inode. After a week it seems that it crashing (no web gui) and there is no active connection with HC2.

Did you get any firmware that is stable?

 

@korniza I am using

Please login or register to see this link.

from "iNode - Firmware" which introduced Mac address whitelist like I mentioned on previous post.  So far it is perfectly stable for me.

 

If you decide to give it a go please remember to update

Please login or register to see this link.

  as well from "iNode LAN - HTML" directory

 

Maybe this helps filter out meaningless BLE devices which reduces udp packet size send to your HC2.

Edited by Sirhideo

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×