Reading Data in Openhab

Sorry for the really basic question but would really appreciate if someone could send me in the right direction. Have a Python script that is writing temperature data to the terminal screen of my Rpi. Trying to figure out how to get that information into Openhab. Followed some very good examples to accomplish the same thing from a remote sensor using a wireless connection and mqtt. How do i do what should be simpler as all the data is on the RPI already? Any examples would be great but a push down the right path would be much appreciated. Thanks!! TJ

To get data into openHAB you need to do one of two things:

  1. Define an Item which uses the appropriate binding to read/receive/retrieve and potentially transform the data
  2. Perform an action inside a rule that reads or retrieves the data

Please see the wiki for a complete explanation of Items and the list of available bindings. Look at the demo for a full demo showing how Items, Rules, and Sitemap interact. Look at the bottom right of the wiki page for a bunch of rules examples and at the binding’s pages for examples of how to use that particular binding.

The MQTT approach is indeed a good one as it will give you a standardized way to retrieve and interact with remote sensors when/if you grow your system in that direction. I initially set MQTT up to try out the Mqttitude binding and have since used it for a lot.

Since you have a Python script, you can use the Exec binding to call the script and put the result of the script into an Item. If your Python script gets the temp from the GPIO pins, you can use the GPIO binding to read the value straight from the pins.

1 Like

Rich hit the nail on the head, but I just wanted to add a note if you’re already manipulating data in Python:

  1. Find one of several Python MQTT clients (I like paho-mqtt: https://pypi.python.org/pypi/paho-mqtt/1.1)
  2. Have the client connect to your MQTT host, subscribe to a channel, and write the temperature data to it continually
  3. Setup a MQTT item in openHAB that periodically pulls the value from the MQTT channel (refer to the documentation linked by Rich)

The only downside here is the extra layer of a Python script, but it should have your data to openHAB with only a little bit of extra setup as well as introduce you to a few openHAB items.

Thanks to both of you for the help. I am using an MCP3008 A/D chip to convert temp data and read it using an spi library/command in my python script. I then print it and can see it on the Rpi terminal screen. Problem i have is how to move it into Openhab. I am familiar with the items, sitemaps, rules but am missing how to “read” the terminal data. From the note above I will do some more reading on MQTT as both of you have pointed me in that direction. Thanks very much for taking the time to send me down the right path. If you are aware of any examples along these lines i would appreciate a link. THANKS Tj

I have written a Python script that uses paho to publish sensor readings from my RasPis. It supports reading data off of GPIO pins, querying for nearby Bluetooth devices, or listening for Amazon Dash button ARP requests. It also lets you “ping” it to get the current readings and it sets up a LWT message for easy detection of when it falls offline. It should be easy enough to add your sensor to it. You can find the script here.

But to be thorough:

As I said above, you would use the Exec binding to execute your Python script and put its output into an Item.

Getting closer but no success yet. Have a simple python script (below) using a shell command to execute mosquitto_pub. Can not find a way to format message such that i pass a number through. when i do a shell command with a second window i only get the message test, not the value of test (integer). Any help would be appreciated.