element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Pi IoT
  • Challenges & Projects
  • Design Challenges
  • Pi IoT
  • More
  • Cancel
Pi IoT
Blog Pi Control Hub : Getting EnOcean Sensor data to Hub via MQTT
  • Blog
  • Forum
  • Documents
  • Polls
  • Files
  • Events
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: carmelito
  • Date Created: 29 Aug 2016 6:43 PM Date Created
  • Views 1419 views
  • Likes 2 likes
  • Comments 0 comments
  • fhem
  • mqtt
  • home automation
  • picontrolhub
  • piiot
  • enocean
  • enocean sensor kit
  • raspberry pi
  • piiot challenge
  • raspberry pi 3
Related
Recommended

Pi Control Hub : Getting EnOcean Sensor data to Hub via MQTT

carmelito
carmelito
29 Aug 2016

As part of this blog post we are going to get the values of the EnOcean Temperature sensor and the Magnetic Contact switch which is attached to the door to check if the door is Open/Closed, to Home-Assistant which is installed on the Hub. The EnOcean module is connected to the Raspberry Pi B+ which we used to automate the blinds (,Pi Control Hub:Spoke2:Blinds Automationblog post) which shows you how to install FHEM home automation server and run the python program ,which takes advantage for the FHEM server telnet port, to rotate a gear motor that opens and closes the blinds

 

To send the EnOcean temperature and magnetic contact values to the Hub via MQTT, we will have to install a MQTT broker on the Hub's Pi 3, for which we will use Mosquitto(An Open Source MQTT v3.1 Broker ) and install a MQTT client on the Pi B+  which is attached to the EnOcean Module used for the blinds automation setup.

 

image

in the screen shot above , the left hand side is the terminal running the program to get the EnOcean Temperature and Magnetic Contact sensor values on Pi B+ connected to the EnOcean module + FHEM event monitor in the browser. And the right,  is Home Assistant dashboard showing the two sensors EnOcean Temperature in circle in the middle and the Door represent the magnetic contact sensor, which is the last circle on the right,  installed on Pi 3, aka the Hub.

{gallery} Integrating EnOcean Temperature and Magnetic Contact sensor with Home-Assistant

image

Magnetic Contact Transmitter Module connected to my front door, currently just using tape ..

image

Magnetic Contact value which shows the Door Open/Closed , here red is corresponds to closed

image

EnOcean Temperature Sensor module to be mounted on the Security camera, to get the outside temperature reading

image

Temperature captured in Home-Assitant from the EnOcean module.

image

Fhem Event monitor screenshot

 

Here are the steps to follow

#1 Install Mosquitto on the Hub's Pi 3

       to use the new repository, first import the repository package signing key using the commands below

           wget http://repo.mosquitto.org/debian/mosquitto-repo.gpg.key

           sudo apt-key add mosquitto-repo.gpg.key

         Then make the repository available to apt

            cd /etc/apt/sources.list.d/

           sudo wget http://repo.mosquitto.org/debian/mosquitto-jessie.list

         Now to install the mqtt mosquitto for the raspberry pi , run an update followed by an install

            sudo apt-get update

            sudo apt-get install mosquitto

    

#2  to test setup we will also install mosquitto-client

           sudo apt-get install mosquitto-clients

#3 Run a quick test locally on the Pi 3

     Open two terminal, in one window create a topic using the command

       mosquitto_sub -d -t topic_tes

     And in the second terminal window, send a message to the topic

        mosquitto_pub -d -t topic_test -m "Hello Pi3"

image

 

#4 As part of the Home- Assistant add the following to the configuration.yaml file

   To integrate MQTT into Home Assistant, add the following section

mqtt:
  broker: 192.168.0.24
  port: 1883
  client_id: home-assistant-1
  keepalive: 60
  protocol: 3.1

     where the broker is the Ip Address of your pi

     For more info check out - https://home-assistant.io/components/mqtt/

 

    In addition, add the following to the configuration.yaml file as a door OPEN/CLOSE sensor

binary_sensor:
  platform: mqtt
  state_topic: "home/door"
  name: "Door"
  qos: 0
  payload_on: "ON"
  payload_off: "OFF"
  sensor_class: opening

 

    And to get the value of the EnOcean Temperature sensor add following under the sensor section

sensor:
- platform: mqtt
  state_topic: "home/temperature"
  command_topic: "home/temperature"
  name: "EnOcean Temperature"
  qos: 0
  unit_of_measurement: "°C"

 

 

#5 on the Pi B+ install MQTT client paho

     Paho makes communicating with an MQTT server installed on the Pi 3 very simple and can be easily used as part of python program, we will install paho-mqtt using pip ,

       sudo apt-get install python-pip

       sudo pip install paho-mqtt

 

#6 Lets run a simple python program on the Pi B+, to check if we are able to send data to the MQTT broker on the Pi3

      Here is a sample python program , change the  hostname value to Pi3 aka the Hub's ip address and the Topic values should match the values above that we entered in the configuration.yaml       file.

 

import paho.mqtt.publish as publish
import time

print("Sending EnOcean Magnetic Contact value")
publish.single("home/door", "ON", hostname="192.168.0.24")
time.sleep(5)
print("Sending EnOcean Temperature value")
publish.single("home/temperature", "28", hostname="192.168.0.24")

print("Sending EnOcean Magnetic Contact value")
publish.single("home/door", "OFF", hostname="192.168.0.24")
time.sleep(5)
print("Sending EnOcean Magnetic Contact value")
publish.single("home/door", "ON", hostname="192.168.0.24")
time.sleep(5)

print("Sending EnOcean Temperature value")
publish.single("home/temperature", "26", hostname="192.168.0.24")

       Now when you run the following program you should see sensor values for Enocean Temperature and Door on the home assistant dashboard update

 

image

 

#7  Run the program to update values from the EnOcean sensor from the Pi B+ to the Pi 3

import telnetlib
import paho.mqtt.publish as publish
import time


#Connection details to the fhem server installed on the same Pi
#For the telnet details check out URL - http://IpAddressOfPi:8083/fhem?detail=telnetPort
HOST = "127.0.0.1"
PORT = 7072
tell = telnetlib.Telnet()
#Connecting to the fhem server
tell.open(HOST,PORT)
#Send command to intiantiate fhem server to get the data
tell.write("inform on\n")


def string_after(s, delim):
    return s.partition(delim)[2]


while True:
        #get the value after the carriage return
        output = tell.read_until("\n")
        #Check the value of the Magnet Contact Transmitter module - Door open close
        if "contact" in output:
                print output
                if "closed" in output:
                        print "Mangentic contact closed"
                        print("Sending EnOcean Magnetic Contact value - ON")
                        #Sending data to door open/close value to topic, change Ip address to the Ip of the pi with broker
                        publish.single("home/door", "ON", hostname="192.168.0.24")
                else:
                        print("Sending EnOcean Magnetic Contact value - OFF")
                        publish.single("home/door", "ON", hostname="192.168.0.24")
        #Checking the temperature sensor
        #if you get the error-No EEP profile identifier and no Manufacturer ID -wait for the sensor to charge
        if "sensor" in output:
                        print output
                        delim ="temperature:"
                        print string_after(output, delim)
                        print("Sending EnOcean Temperature value")
                        publish.single("home/temperature", string_after(output, delim), hostname="192.168.0.24")

 

once your done with testing set the program up in the crontab to run continuously

image

in the screen shot above , the left hand side is the terminal running the program above on Pi B+ connected to the EnOcean module, and the right  is Home Assistant installed on Pi 3 aka the Hub.

  • Sign in to reply
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube