Follow the guide on https://debian.fhem.de/ which incudes a repo for debian like distro.
Step 2. Configure basic FHEM settings.
As it is installed on /opt/fhem, you need to edit fhem.cfg. The very basics are the following. I just comment the last line as I got errors that do not find usb devices.
Code: Select all
attr global userattr cmdIcon devStateIcon devStateStyle icon sortby webCmd widgetOverride
attr global autoload_undefined_devices 1
attr global logfile ./log/fhem-%Y-%m.log
attr global modpath .
attr global motd SecurityCheck:\
\
WEB,WEBphone,WEBtablet has no basicAuth attribute.\
telnetPort has no password/globalpassword attribute.\
\
Restart FHEM for a new check if the problem is fixed,\
or set the global attribute motd to none to supress this message.\
attr global statefile ./log/fhem.save
attr global updateInBackground 1
attr global verbose 3
define telnetPort telnet 7072 global
define WEB FHEMWEB 8083 global
attr WEB stylesheetPrefix dark
define WEBphone FHEMWEB 8084 global
attr WEBphone stylesheetPrefix smallscreen
define WEBtablet FHEMWEB 8085 global
attr WEBtablet stylesheetPrefix touchpad
# Fake FileLog entry, to access the fhem log from FHEMWEB
define Logfile FileLog ./log/fhem-%Y-%m.log fakelog
define autocreate autocreate
attr autocreate filelog ./log/%NAME-%Y.log
define eventTypes eventTypes ./log/eventTypes.txt
# Disable this to avoid looking for new USB devices on startup
#define initialUsbCheck notify global:INITIALIZED usb create
Fhem-ble does not require a full FHEM installation. This script has to be installed also on Master FHEM server.
Download fle-ble init script
Move it as service under /etc/init.d/fhem-ble.
Make it executable
Code: Select all
sudo chmod +x /etc/init.d/fhem-ble
Move it to /opt/fhem/lepresenced
Make it executable
Code: Select all
sudo chmod +x /opt/fhem/lepresenced
Code: Select all
sudo cpan -i Net::Server::Daemonize
Code: Select all
sudo apt-get install python-yaml
Code: Select all
sudo update-rc.d fhem-ble defaults
Code: Select all
sudo service fhem-ble start
netstat |grep 5333
Edit lepresenced for matching personal settings
Code: Select all
sudo vi /opt/fhem/lepresenced
Code: Select all
sub parse_options() {
my $device = "hci0";
my $daemonize = 0;
my $listen_address = "127.0.0.1";
my $listen_port = "5333";
.
.
.
Step 4. Install collectord on master server.
Collectord connects to all fhem-ble services and looks for the devices are configured on fhem.cfg
Download collectord debpackage and install it
Code: Select all
wget http://svn.code.sf.net/p/fhem/code/trunk/fhem/contrib/PRESENCE/deb/collectord-1.6.deb
dpkg -i collectord-1.6.deb
Code: Select all
# room definition
# ===============
#
[room-name] # name of the room
address=192.168.0.10 # ip-address or hostname
port=5111 # tcp port which should be used (5111 is default)
presence_timeout=120 # timeout in seconds for each check when devices are present
absence_timeout=20 # timeout in seconds for each check when devices are absent
[living room]
address=192.168.0.11
port=5111
presence_timeout=180
absence_timeout=20
You need to put the ip of devices you previous installed fhem-ble and as port the number 5333 (fhem-ble use this port to communicate)
Step 5. Configure fhem & include BLE beacons
Code: Select all
nano /opt/fhem/fhem.cfg
Code: Select all
define NUT PRESENCE lan-bluetooth ZZ:ZZ:ZZ:ZZ:ZZ:ZZ localhost:5222 30 60
attr NUT event-on-change-reading state
define NUT_p notify NUT:present "curl -s "http://[b]xx.xx.xx.xx:8080[/b]/json.htm?type=command¶m=switchlight&idx=[b]YY[/b]&switchcmd=On" &"
define NUT_a notify NUT:absent "curl -s "http://[b]xx.xx.xx.xx:8080[/b]/json.htm?type=command¶m=switchlight&idx=[b]YY[/b]&switchcmd=Off" &"
XX: IP address of Domoticz
YY: IDX of a virtual switch to associate
As you see, I used virtual switches but you can use user variables.
Also if you notice we connect to port 5222. It is the port that collectord listens. If you have devices that they are not moved you can use direct port of fhem-ble on 5333.
Save and close all. Reboot all your Master/slave devices and you have a basic setup running. After you can fine tune the timeout times for presence.
Panic buttons
As I have purchased other ble trackers till find NUT that is beaming all the time it's status, I have some of them sitting in front of my desk. So I used them as triggers for domoticz. If FHEM detect them it will send to Domoticz a call. They are associate on Domoticz as Panic Buttons, so if they go ON, using some LUA scripts they trigger alarm for fire (I have stickered them around house) or sound the alarm / turn on lights on night and get cameras on record mode.
This period I try to get from FHEM the room (as FHEM knows that from collectord) that a panic button is triggered so to build complex scenarios. Another difference with presence is that panic buttons always send their status even if it not changed. The difference on fhem.cfg is ommiting the line
Code: Select all
attr NUT event-on-change-reading state
I run this setup for 3 weeks and it works great. I have also added izSynth script ON Action and our home welcome family members when they come in!
Hope I helped. If something is missing please let me know

Rederences:
http://fhem.de/commandref.html
http://fhem.de/fhem.html#Installation
http://www.fhemwiki.de/wiki/Anwesenheitserkennung
viewtopic.php?f=23&t=11696