Node-Red Input node can not get Item state (OH2.1.0)

Hello together,

I have recently set up a Raspberry Pi in my home with the openhabian image (running OH 2.1.0 stable).
Additionally I have installed Node-Red from the OpenHabian Configuration Tool.

After setting up the OH-Controller in the openhab2-node configuration in Node-Red (Protocol: http, Host: openhabianpi, Port: 8080). I get all my Items listed and I can select one.
However, I immedeately get the following error (red) in the debug tab (once):

msg:error

TypeError: Cannot read property ā€˜closeā€™ of undefined

Afterwards I repeatedly (every 2-3 seconds) get the following warning(?)(orange) in the debug tab:

msg : string [35]

ERROR
{ā€œtypeā€:ā€œerrorā€,ā€œstatusā€:404}

If I delete the controller, the repeated warning messaged donā€™t stop, until I restart the Node-Red Service.

The Item state below the node then only shows a ā€œ?ā€.

I also tried to reach OpenHab with a second Pi (with an old setup, OH2.0) but I run into the same issue. The old OH2.0 setup however can be reached from both Node-Red setups, so I doubt this is an issue with Node-Red.

Did anybody ever run into a similar problem?
Any help, or even a pointer in the right direction would be appreciated.

THANKS!!

2 Likes

Which version of Node-RED are you running? I noticed a similar issue after upgrading to the new .17 versions:

https://community.openhab.org/t/node-red-as-a-rule-script-engine-for-openhab/14914/107?u=rgerrans

@Peter_De_Mangelaere Did you get a chance to test this and see if there were issues with all the changes in the new versions?

Personally, I ended up setting up a mosquitto server and switching to mqtt (was on my to do list anyways and when I started getting similar errors I just made the jump).

On my new Pi Iā€™m running 0.17.4 and on my old one 0.15.1. Iā€™m getting the issue on both systems.

For now Iā€™m working with the MQTT Eventbus, too, but the openHAB nodes are much easier to use.

I wasnā€™t having any issues with the previous version so wonder if there was a change in OH about the same time. I was able to get an openhab-get nodes to pull fine, it was just the openhab-in nodes.

Agree that msqtt isnā€™t quite as convenient but I got to imagine itā€™s a little faster and less resource intensive then checking a REST api. It didnā€™t take too long to switch them all over just miss the -get nodes options and having to use flow variables instead. I never heard back from Peter on my previous posting so hopefully this one catches his attention and he can look into it.

OH 2.1 with node-red 0.17.3 on the same pi for a while now ā€¦ without issues.

Is that the OH stable release? @germanbob are you running stable or snapshots? For me, Iā€™m on the snapshots.

Iā€™m running stable.

And I just tried out the openhab2 get-node, which works, but I still get the weird warning message every few seconds.

Alright so I figured out what the problem was by myself.

Problem:
I looked into the source code of the openhab2-in nodes and noticed that they use a class called eventsource. This basically sets up a listener for ā€œServer-Sent Eventsā€.
However in my OpenHAB-Setup (and Iā€™m assuming it will be the same for all OpenHABian setups) this was disabled by default.

Solution:

1: Navigate to your openHAB application runtime directory.
For OpenHABian this will be /user/share/openhab2/runtime
For a manual installation it will be /opt/openhab2/runtime - I think

cd <application runtime path>

2: Open services.cfg with your preferred text editor

sudo nano services.cfg

3: add the line

org.eclipse.smarthome.cors:enable=true

4: save and restart.

After that everything worked like a charm for me.

If this was helpful, please leave a like.

8 Likes