Subscribe to item status change from node red

Hello guys, I am trying get update on status of my items in node red. Openhab node red integration doesn’t work for me. I use http request node with persistent connection and use http://localhost:8080/rest/events?topics=smarthome/items/{item}/statechanged as url. However it doesn’t pass on any payload to debug node wwhen the sate changes. Any Idea?

Which NodeRed openHAB2 Nodes version are you using?

This works well for me…


version 1.1.7

1 Like

If you dont want to use the openhab nodered node you will have to use node-red-contrib-sse-client as openhab uses server sent events in its rest api that you need to subscribe too to receive updates for an item or any of the other endpoints that the api offers.
Nodered has no support for sse in the build in nodes.
Best regards Johannes

1 Like

Hey thank you for response, Unfortunately it give me error and doesn’t load the list of things. In my setting I only provide it with ip and port number leaving everything else blank. Is there a user pass or a special path that I have to provided with?

Thank Johannes, How should I set this up? I has a field for url and another one for it of events, How should I define the events?

I think you’re trying to run ahead without checking the basics.

For example.

Have you created a Controller for the NodeRed openHAB2 events?

For example

Port 8080

Yes I have created a controller however it also has fields for username and pass and path, which I left blank. I also use my openhab Ip address rather than local host and use 8080 as port number. Is there a binding I need to install for this to work?

It should be straightforward.

This is what mine looks like

(My NodeRed is on the same machine as openHAB2)

Just import this into your NodeRed and the you should be able to select your own items with it.

        "id": "ea5dc5e3.e85d68",
        "type": "openhab2-in",
        "z": "fd6f5a2.5649fa8",
        "name": "Bathroom V RGB Red",
        "controller": "deaa963.282a968",
        "itemname": "BathroomVRGBDMX_RED",
        "x": 120,
        "y": 80,
        "wires": [
        "id": "deaa963.282a968",
        "type": "openhab2-controller",
        "z": "",
        "name": "OpenHAB2 Home",
        "protocol": "http",
        "host": "",
        "port": "8080",
        "path": "",
        "username": "",
        "password": ""

Exactly but for some reason it doesn’t load up any items for me. I have to add I didn’t add my items through paper UI, but rather added them through code editor

You’ve lost me there.

I assume you can get status’ of items from the Rest docs interface without any issues?

Yes, I can do that, ok. Lets say I want to add the event node on node red here are the step I take:

  1. add the controller
  2. I go back to select an item. However, the item list on the node is empty.

My items and their status work fine on openhab and RestAPI, they just don’t show up on the node red

Is there an easy way for me to convert my Openhab items to mqtt items?

Sorry, you’re now WAY outside my comfort zone

1 Like

:smiley: thanks for your help though

1 Like


I’m curious, but that’s as far as my understanding of Rest goes…

Do you see a full list of Items when you use this URL?


If you have installed this:

you can use the flow below to subscribe to an openhab item and its updates without using the openhab node. You just need to edit the first function to add the item name. Everything is commented and should be self explanatory.

[{"id":"2efe2021.554008","type":"inject","z":"58cf3979.df1d7","name":"","topic":"","payload":"START","payloadType":"str","repeat":"300","crontab":"","once":true,"onceDelay":0.1,"x":380,"y":1620,"wires":[["b4c396d4.f1d3e8"]]},{"id":"d6659199.0f11f","type":"sse-client","z":"58cf3979.df1d7","name":"","url":"","events":[],"headers":{},"proxy":"","restart":false,"timeout":"60","x":750,"y":1620,"wires":[["55e4a9a8.e66ef"]]},{"id":"55e4a9a8.e66ef","type":"json","z":"58cf3979.df1d7","name":"","property":"payload","action":"","pretty":false,"x":910,"y":1620,"wires":[["6554638e.60a614"]]},{"id":"6554638e.60a614","type":"json","z":"58cf3979.df1d7","name":"","property":"payload.payload","action":"","pretty":false,"x":1050,"y":1620,"wires":[["ae683bb2.76ba1"]]},{"id":"b4c396d4.f1d3e8","type":"function","z":"58cf3979.df1d7","name":"make url for sse","func":"var item = \"OpenhabItem\"; //put you Openhab Item name here\nmsg.url = \"http://localhost:8080/rest/events?topics=smarthome/items/\" + item + \"/statechanged\";\n//use commented line instead if its a group\n//msg.url = \"http://localhost:8080/rest/events?topics=smarthome/items/\" + item + \"/*/statechanged\";\nreturn msg;","outputs":1,"noerr":0,"x":560,"y":1620,"wires":[["d6659199.0f11f"]]},{"id":"8ef02f9f.9de1f8","type":"debug","z":"58cf3979.df1d7","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":1450,"y":1620,"wires":[]},{"id":"ae683bb2.76ba1","type":"function","z":"58cf3979.df1d7","name":"add msg.payload.item","func":"var itemarr = msg.payload.topic.split(\"/\");\nmsg.payload.item = itemarr[2];\nreturn msg;","outputs":1,"noerr":0,"x":1240,"y":1620,"wires":[["8ef02f9f.9de1f8"]]},{"id":"f0be5d30.005dd8","type":"comment","z":"58cf3979.df1d7","name":"add openhab item name here","info":"change the variable named item within function to your openhab item name.\nIf nodered is on a different machine you need to change localhost.","x":560,"y":1560,"wires":[]},{"id":"62815620.58fed8","type":"comment","z":"58cf3979.df1d7","name":"nested json parsing","info":"this is why we need two json nodes to have a workable js object","x":970,"y":1560,"wires":[]},{"id":"b7ba5c13.8e39f","type":"comment","z":"58cf3979.df1d7","name":"sse connection to openhab","info":"we pass the url to this from the previous function no changes needed here","x":750,"y":1680,"wires":[]},{"id":"fe031117.5f1e4","type":"comment","z":"58cf3979.df1d7","name":"just for comfort","info":"we parse the topic to create  a msg.payload.item property that just includes the item name","x":1240,"y":1680,"wires":[]},{"id":"15886264.dfb596","type":"comment","z":"58cf3979.df1d7","name":"autostart on deploy or restart","info":"this also restarts the connection every few minutes","x":360,"y":1680,"wires":[]}]


1 Like