Node-RED as a rule/script engine for openHAB

Sure, I don’t use OpenHabian so can you give me the url to do so.

Edit (as I tell others, Google is your friend :wink: )…Done

https://github.com/openhab/openhabian/issues/193

@rgerrans just add a few lines here with this new package, e.g.:

  cond_redirect npm install -g node-red-contrib-bigtimer
  if [ $? -ne 0 ]; then echo "FAILED (nodered bigtimer addon)"; exit 1; fi
  cond_redirect npm update -g node-red-contrib-bigtimer
  cond_redirect npm install -g norelite
  if [ $? -ne 0 ]; then echo "FAILED (nodered norelite addon)"; exit 1; fi
  cond_redirect npm update -g norelite
  cond_redirect npm install -g node-red-contrib-openhab2
  if [ $? -ne 0 ]; then echo "FAILED (nodered openhab2 addon)"; exit 1; fi
  cond_redirect npm update -g node-red-contrib-openhab2
1 Like

Done, hopefully I didn’t break anything since it’s the first time I’ve tried adding a PR. https://github.com/openhab/openhabian/pull/194

Edit: I started to play with this and it’s really designed to be a more standalone set of flows that are meant to be integrated with OpenZwave or other direct communication nodes. I’m going to close out the PR and may reopen it when I get a chance to play with it some more.

I have identified my problem with reading the Harmony Hub Activity in a flow. It finally twigged that flows that are triggered by a Harmony Hub Activity work fine. All the ones with a problem are where the Harmony Hub Activity is being read mid flow.

The openhab-in node returns a simple string, e.g. PowerOff which my simple cases ‘==“PowerOff”’ work with just fine.

The openhab-get node returns an object. Part of the object is a ‘state:“PowerOff”’, but it is buried in amongst a lot of other text. So the simple case to match the string exactly fails.

I’ve just changed the cases in the switch node that checks the message payload to be ‘contains’ rather than ‘==’. I’m hoping this will sort it.

The other way to do it is to use the msg.payload.variable structure in your switches to pull the correct topic out to evaluate (I don’t use the openhab-contrib nodes anymore but I do remember that for some I had to do a msg.payload.payload.variable)

1 Like

Perfect! msg.payload.state gives me a match to the Harmony Hub Activity and a rule behaving exactly as I need. Thanks again for your assistance!

1 Like

Just finished writing short tutorial on Rules creation in Node-RED. Hope it will be interesting for everyone.
https://www.linkedin.com/pulse/node-red-smart-home-making-your-first-rule-tutorial-artyom-syomushkin

3 Likes

@ThomDietrich Thom I installed nodered though the openhabian install menu. Works great and installed additional nodes like global cache through the node red UI.

However I now noticed that some nodes like bigtimer have an update and when trying to update though the UI the update fails. I tried sudo npm update -g node-red-contrib-bigtimer but that did not update the big timer node. (still showing 1.7.5 in the UI)

So basically 2 questions:

  1. how to update the pre-installed nodes that have updates available
  2. wouldn’t it be usefull to change the scripts of the pre-installed nodes (or if not i not pre-install them and have the users install them manually) so node management can be done through the UI)

— EDIT —
sudo npm update -g node-red-contrib-bigtimer
does update the node (the reason for not showing must be some caching issue).
So 1 is no longer a question but that being said I think it would still make sense to do such from the UI. So I might experiment with uninstalling bigtimer and trying to re-install trough node-red UI

One easy option to facilitate that solution is to add updates of existing packages to the nodered openHABian routine. If you agree, please open an issue in the openHABian issue tracker

yes makes sense. Just opened issue. Thanks !!

https://github.com/openhab/openhabian/issues/213

@rgerrans any chance you could join the discussion?

I’ll take a look later today/this evening to see if I can help. I have the same issue with some of the default nodes (like RBE just updated) included in a regular node-red install and it’s been on my to-do list to go figure out how to update them independent of a full node-red update.

Hi all,

I found this thread while searching for a hint for my rule issue. However, node-Red looks interesting to me.
Maybe a stupid question, but I wonder how to setup it in my current installation (I’m not using openhabian).
Do I have to setup a node red installation and then install this openhab conrtribution?

Is there any tutorial to setup everything from scratch in a openhab 2 installation on ubuntu?

Thanks in advance.

BR Marcel

Here you go. Here are the official docs on how to get it up and running. Feel free to throw out any questions as you get it going. - https://nodered.org/docs/getting-started/installation

Here is the tutorial I put together on how to replace your OH rules functionality with Node-Red equivalents:

Thanks that helped me. Installed it so far. After vacation I will try to convert my rules.

Hi,

I wanted to implement the first flow. Somehow I don’t get any item in the controller node. I have checked the REST API via browser and I found and error the JSON error tells me

{"schemaValidationMessages":[{"level":"error","message":"Can't read from file http://192.168.0.10:8080/rest/swagger.json"}]}

I’m on OpenHab 2.1 stable release. Do you think this is related to this? Basic UI and everything else works fine.

Thanks for your help.

BR Marcel

Ok, I found the problem. I have some items with state null. Then I have to save first my flow as described here. Now I can select items. :slight_smile:

1 Like

@rgerrans just updated my node-red modules and my OH2 install and it broke the openhab 2 write node. the read nodes are working fine.

The write nodes that were working fine before now report “request error ‘Error: Argument error, options.body.’ on ‘http://127.0.0.1:8080/rest/items/OH2_Watchdog/state’” and they’ve made all the other nodes in my flow start acting all wonky until I deleted them

When I visit the above rest URL it displays “NULL” as expected as the item hasn’t been updated yet by Node-Red (since the write node is failing). I thought it might be a bug trying to write to items with a state of NULL, but I also tested writing to items with a state such as a number, still getting same error.

Did the OH2 REST interface change or something? my phone apps using the rest API are still working fine

node-red-contrib-openhab2@1.0.7
OH2 version: 2.2.0-SNAPSHOT Build #1072

Unfortunately, I don’t think I can be of much help. I switched from the OH nodes MQTT. I had some issues back in July -

Not sure if they are similar but from my responses I think I got things to clear up with a reboot.

Otherwise, you probably need to reach out to @Peter_De_Mangelaere who developed the nodes.

Oops sorry! Thought you were the dev :stuck_out_tongue: Sadly not affected by a reboot