How to use Openhab with ROS?

I used the following link to Openhab with ROS:

http://wiki.ros.org/iot_bridge

I have run openhab, truly.
In the installing section in the above link (in 3. Edit iot_bridge/config/items.yaml and 4.Edit Openhab’s item file ), I faced with some problems. I mean, I do not know how I can create the ROS group: Group ROS (All) add the (ROS) group to each item that should send status updates to ROS.

Please, guide me.
Thank you.

Create a file that ends in .items in the /etc/openhab2/items folder with the content lasted at the end of step 2.

1 Like

Thank you very much.

I have written a code with ROS and OpenCV. I want to use IOT (Openhab) for my code, but I do not know how I can connect between them.
How can I connect iot_bridge package with my package? I mean, I want to show Openhab my video.

Please, guide me.
Thank you.

I will answer this question very late because there are not so many topics about ROS and openHAB. You have ROS and you have openHAB. Both are two different systems. They can be installed on one or two devices. Maybe if you count multipile robots you have multiple ROS devices but normaly you have one openHAB devices (and not more).

The iot_bridge or openHAB bridge only connects ROS to openHAB. For this use case you have to create items for ROS inside openHAB. They must have the group ROS. The connection from ROS to openHAB or vice versa is the REST API from openHAB. The iot_bridge will use a ROS Publisher to publish state changes from openHAB. So your ROS system will receive openHAB state changes.

If you will work with one of this states you have to create a ROS subscriber. In the example of the iot_bridge there is also a subscriber. This subsciber subscribes from the publisher which sends the state changes. In the example this “informations” are used to publish it for commands. On the commands side there is also a subscriber. After this subscription the REST API will lead to make a sendCommand in openHAB.

If you want to write a ROS package which will change something in openHAB you have to create a at first (an empty) item. This item should be within the ROS group. Then you have to write your own publisher which will publish to the subscriber which will make a REST request for sendCommand. If you need the item state before you do something in your program you have to subscribe from the publisher which publishes the item states after it receives the item States over REST.

If you’ve been paying close attention, you’ll notice that, strictly speaking, there’s one detour too many here. You could access the REST API in your ROS program itself. An example of this is provided by the iot_bridge. I would actually not want to use it as a bridge directly.

I recreated the ROS bridge for openHAB 3:

This should work for ROS Kinetic and ROS Noetic without any problems. ROS Melodic should normally work but is not tested.

A big disadvantage is that all items use the same topic. Good it is distinguished for state and command. But you don’t access one item directly, but always all items in the ROS group. That means in a ROS package where you only need a few items, you would have to check additionally with an if-query, if the just changed item is one of the needed items. So you get too much information that you would not need to edit.

For that I tested following:

I hacked HABApp so I can use the rospy library for ROS Python there too. If you have learned and understood ROS reasonably well, you know that you can build and use ROS nodes outside of the catkin workspace (catkin_ws). In Python now once easier than in C++. Via HABApp I can also access all items of openHAB. What I do differently here is that I have created a separate publisher for each item. This solves the problem mentioned above. A subscriber can then also be created. As callback method they should get a ValueUpdateEvent or a ValueChangeEvent. I haven’t worked out an exact solution for this yet.

I think another approach I will still take is to finally convert the iot_bridge into a proper openhab_bridge. Publishers should publish all states to the items and subscribers should subscribe the commands to them.

To answer the question more clearly and concretely. The Topics use diagnostic_msgs/KeyValue:

http://docs.ros.org/en/noetic/api/diagnostic_msgs/html/msg/KeyValue.html

The used fields are key and value. Both from the type string. The key is your item and the value is your command or state. So a little bit closer. With the key you have to say which item should receive the OpenCV image or video. The problem would be that you have to convert your image or video data to a string. Better said Base64 encode and decode. Better said Base64 encode and decode.

1 Like