enocean.pngEnOcean offers a range of wireless, self-powered sensors, measuring: temperature, humidity, contact, etc ... I've been using them in my house ever since the Forget Me Not Design Challenge. After almost two years, I can say that I've never had to perform any maintenance on the sensors and they are truly reliable. The indirect light shining on them from nearby windows has been enough to keep them powered all this time!


If you're still not convinced and have some time to spare, you can watch this ad from EnOcean, explaining how using their solution can save you a lot of time:



Anyway, let's proceed with getting things set up





IMG_1565.JPGThe EnOceanPi is the gateway through which all sensor data can be collected. It connects to the Pi via the old 26pin GPIO header, but is compatible with the 40pin version. EnOceanPi uses only 4 pins on the GPIO header: 3.3V and GND, and UART Tx/Rx.


Unlike with previous generations Raspberry Pi, additional configuration is required to be able to use the EnOceanPi on Raspberry Pi 3. This is because the Pi 3 has onboard Bluetooth which makes use of the UART interface on "/dev/ttyAMA0". The serial console has moved to the mini-UART on "/dev/ttyS0". Additionally, in order to have stable, consistent serial output using the mini-UART interface, an new parameter was introduced in the "/boot/config.txt" configuration file. The parameter is called "enable_uart" and when set to "1", will fix the core frequency to the minimum. Unless the "force_turbo" parameter is set to "1" as well, forcing maximum core frequency. Forcing turbo will consume more power and may require a heatsink for better heat dissipation.


More information on this topic can be found on the Raspberry Pi forums: https://www.raspberrypi.org/forums/viewtopic.php?f=28&t=141195


Here's what to do:


As per the instructions, add the "enable_uart" parameter. Optionally, add "force_turbo" as well.


pi@piiot1:~ $ sudo nano /boot/config.txt


# Enable UART



Because we don't want the serial console to interfere with the EnOceanPi module, we disable it.


pi@piiot1:~ $ sudo nano /boot/cmdline.txt


Remove the reference to serial0, as illustrated below.


#dwc_otg.lpm_enable=0 console=serial0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait
dwc_otg.lpm_enable=0 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait


Finally, to apply the changes, reboot the Pi.


pi@piiot1:~ $ sudo reboot


The serial interface is now usable and dedicated to the EnOceanPi module.




During the FMN, I used FHEM to determine the IDs of the EnOcean sensors. I have found a more lightweight option, namely EnOceanSpy.


You could also use "hexdump", which is available without installing any additional tools. It doesn't print the telegrams as cleanly though, making the parsing slightly more difficult, especially the first time.


pi@piiot1:~ $ sudo stty -F /dev/ttyS0 57600
pi@piiot1:~ $ sudo hexdump -C < /dev/ttyS0
00000000  55 00 0a 07 01 eb a5 00  00 66 00 01 80 9d c1 00  |U........f......|
00000010  01 ff ff ff ff 30 00 da  55 00 0a 07 01 eb a5 00  |.....0..U.......|
00000020  00 65 00 01 80 9d c1 00  01 ff ff ff ff 33 00 cd  |.e...........3..|
00000030  55 00 0a 07 01 eb a5 00  00 65 00 01 80 9d c1 00  |U........e......|
00000040  01 ff ff ff ff 31 00 e7  55 00 0a 07 01 eb a5 00  |.....1..U.......|


Let's continue with EnOceanSpy ...




Clone the GitHub repository using the "git" command:


pi@piiot1:~ $ git clone https://github.com/hfunke/EnOceanSpy
Cloning into 'EnOceanSpy'...
remote: Counting objects: 139, done.
remote: Total 139 (delta 0), reused 0 (delta 0), pack-reused 139
Receiving objects: 100% (139/139), 82.14 KiB | 0 bytes/s, done.
Resolving deltas: 100% (65/65), done.
Checking connectivity... done.


Change directory to the cloned repo:


pi@piiot1:~ $ cd EnOceanSpy/


In the source file, remove the following block of code. As it expects the serial interface to either be "/dev/ttyAMA0" or "/dev/ttyUSB0", it won't work with EnOceanPi on Pi3 where the interface is called "/dev/ttyS0".


pi@piiot1:~/EnOceanSpy $ nano EnOceanSpy.c


// Check content of args
if ((strcmp(argv[1], "/dev/ttyUSB0") != 0)
  && (strcmp(argv[1], "/dev/ttyAMA0") !=0) )
  printf("Error: %s is not a valid port name!\n", argv[1]);
  return -1;


After the modification, compile the source code. It only takes a second.


pi@piiot1:~/EnOceanSpy $ gcc -o EnOceanSpy EnOceanSpy.c




Run the "EnOceanSpy" command and specify the serial interface used by EnOceanPi. Triggering the EnOcean sensors should result in hexadecimal data being displayed on screen.


pi@piiot1:~/EnOceanSpy $ ./EnOceanSpy /dev/ttyS0
Starting EnOceanSpy...
2016-06-12 09:46:54  55 00 0A 07 01 EB A5 00 00 63 00 01 80 9D C1 00 01 FF FF FF FF 31 00 B7
2016-06-12 09:46:59  55 00 0A 07 01 EB A5 00 00 62 00 01 80 9D C1 00 01 FF FF FF FF 2D 00 F9
2016-06-12 09:47:01  55 00 0A 07 01 EB A5 00 00 62 00 01 80 9D C1 00 01 FF FF FF FF 2D 00 F9


This data can now be parsed to determine the sensor ID required by the EnOcean binding in OpenHAB.




Unless you are planning to write your own application to parse the EnOcean telegrams, the most useful/relevant part is the sensor ID, which can be used by another application such as OpenHAB.


The structure and content of such a telegram is described in detail in the EnOcean documentation:


Below is an illustration of the relevant data of the documentation, and how it maps to the data received via EnOceanPi.

Screen Shot 2016-06-12 at 19.29.32.png


Based on this, I was able to retrieve all sensor IDs and configure them in OpenHAB, to be used with the EnOcean binding.




I have chosen to use OpenHAB for this project, so I configured my sensors there.


Four things need to be done:

  • Tell OpenHAB to use "/dev/ttyS0" for serial communication
  • Install and configure the EnOcean binding
  • Define the items with the correct data
  • Populate the sitemap with those items


In "/etc/default/openhab", set:

  • "USER_AND_GROUP" to "pi:pi"
  • "JAVA_ARGS" to "-Dgnu.io.rxtx.SerialPorts=/dev/ttyS0"


Next, in "/etc/openhab/configurations/openhab.cfg", configure the EnOcean binding:


################################# EnOcean Binding #####################################
# EnOcean USB adapter serial port


Install the EnOcean binding:


pi@piiot1:~ $ sudo apt-get install openhab-addon-binding-enocean


Finally, define your items and sitemap.




Switch EnOcean_sensor_00298B1A_A "Master A" <switch> (Switches) {enocean="{id=00:29:8B:1A, eep=F6:02:01, channel=A}"}
Switch EnOcean_sensor_00298B1A_B "Master B" <switch> (Switches) {enocean="{id=00:29:8B:1A, eep=F6:02:01, channel=B}"}

Contact EnOcean_sensor_0180FC58 "Door 1 [MAP(en.map):%s]" <door> (Contacts) {enocean="{id=01:80:FC:58, eep=D5:00:01, parameter=CONTACT_STATE}"}
Contact EnOcean_sensor_0180AAFA "Door 2 [MAP(en.map):%s]" <door> (Contacts) {enocean="{id=01:80:AA:FA, eep=D5:00:01, parameter=CONTACT_STATE}"}

Number EnOcean_sensor_01809DC1 "Room 1 [%.1f °C]" <temperature> (Temperature_Chart) {enocean="{id=01:80:9D:C1, eep=A5:02:05, parameter=TEMPERATURE}"}
Number EnOcean_sensor_0181A67A "Room 2 [%.1f °C]" <temperature> (Temperature_Chart) {enocean="{id=01:81:A6:7A, eep=A5:02:05, parameter=TEMPERATURE}"}




sitemap demo label="EnOcean"
        Frame label="Switches" {
                Switch item=EnOcean_sensor_00298B1A_A
                Switch item=EnOcean_sensor_00298B1A_B
        Frame label="Temperature" {
                Text item=EnOcean_sensor_01809DC1 valuecolor=[>25="orange",>15="green",>5="orange",<=5="blue"]
                Text item=EnOcean_sensor_0181A67A valuecolor=[>25="orange",>15="green",>5="orange",<=5="blue"]
        Frame label="Contacts" {
                Text item=EnOcean_sensor_0180FC58
                Text item=EnOcean_sensor_0180AAFA


The result should look something like this, although the GUI itself may differ, as I'm experimenting with PaperUI.

Screen Shot 2016-06-14 at 20.30.33.png


Using the sensors results in realtime updates:



Now you know how to set up EnOceanPi and sensors!




Navigate to the next or previous post using the arrows.