Node-RED as a rule/script engine for openHAB

Have a read through this thread, probably the best one on nodered -openhab here on the forum.


I am diggin through this as well.
Thanks for sharing!
Even though I just started to use Node red - I already like it a lot.

However, my screen is too smal for complex stuff I assume :wink:

I will see how fast I can replace my text based rules with node red


I ended up using a combination of Jsr233 rules written in Jython and Nodered but I’m still loving Nodered especially for quickly prototyping stuff and how many 3rd party things you can quickly integrate without much setup. You will definitely have fun along the way.

1 Like

I try to replace a rule with “channel triggered”.
How can i get the channel direct as an input into node red?

Have a look at this and the discussion in the posts above it:

There is a few different ways to do it


I think this might be what you’re looking for.

It’s certainly working for me.

If you would like me to post the JSON file for the node, just let me know.

***** update *****

For anyone else looking for an IF Function node that can handle openHAB2 channel triggers, here’s what I use.

Just use the import option to paste it from the clipboard.

        "id": "ff5aa376.8b767",
        "type": "function",
        "z": "323c754e.27612a",
        "name": "Lounge Oled Btn 3",
        "func": "var event = msg.payload.event;\nvar channel =;\nvar newMsg = { payload: msg.payload.event };\nvar button = \"velbus:vmbgpod:d212bf44:2C:input#CH3\"\n\nif  (channel === button )  {\n\tif (event === \"PRESSED\") {\n\t\treturn [msg, newMsg, null, null];\n\t}\n\tif (event === \"LONG_PRESSED\") {\n\t\treturn [msg, null, newMsg, null];\n\t}\n\tif (event === \"RELEASED\") {\n\t\treturn [msg, null, null, newMsg];\n\t}\n}\nreturn null;",
        "outputs": 4,
        "noerr": 0,
        "x": 350,
        "y": 120,
        "wires": [
        "outputLabels": [
            "Whole Msg",

The essence of this node is…

Match an openHAB2 event to the three states that the channel can be.

Output anything that comes from the channel to output 1

Then the three other outputs get a payload when the state of the channel matches



Obviously the event trigger and states will need to be changed to suit your application :slight_smile:

Thanks Stuart - I found a way by using the OH event and look for the channel.
It’s so easy!
And my learning curve is very steep :slight_smile:

1 Like

A question came up along the way trying to migrate my rules to node RED:

  1. Is there an option to send a debug node output to a logfile (e.g. openhab.log)?
    I currently use the debug nodes heavily to learn, but they obviously just log with the web interface open.
    So I don’t know how to check logs later on, if something is nor working properly.

Have you seen the “File” nodes in the storage section ?


This just popped up in an email, I thought you might like to review it.


Thanks. I will check out both suggestions!

I installed the node flogger, stopped node red and started it again.
All my flows are gone!

Is there any way to get them back?

Got them in home/.node-red/flows_Homer.json

1 Like

I’m glad you’ve found some files to restore.

I did a quick search and found this, if I’m reading it correctly, NodeRed saves a backup of the files each time flows are deployed.

Search for the word “deploy” to see what I saw.

flows_*.json & flows_*_cred.json

These define the flows and any credentials stored for the flows. The * indicates that the actual file is named after the machine name you are running on. If you have transferred from another machine name, you might have multiple files though only one set will be active. In addition, there are *.backup versions of these files. Node-RED copies the old active flow/cred files each time you deploy.

Thanks a lot. I will check it out.
I though I need to start from scratch.

There is still a way to go to migrate 6000+ LOC of my rules into nodeRED… :wink:

i was lucky enough to find node red before i started any rules on my setup, i was in the early stages of understanding OH, and then node-red came , and this got me real amped up

from controlling just some MQTT devices ,my entire house is node-red based
i use OH dont get me wrong OH is the best for
,DB, logging , cloud ,site map , for the great REST API, and it is so stable!
but my all logic is there and i love the simplicity

i can tell you i switched my setup many times but with Node somehow its fun! and worth it
if you need help i am here…

also dont forget if it dosent work in OH you can always try the Node red way, it provided me some flexibility, and allot of workarounds !

1 Like

I agree, that it’s a lot of fun to create flows with node RED.
Even though my (text) rules are running fine and some might be too complex to transfer them into node RED (at least on my current knowledge level of node RED) I am considering to move over as much as possible.

However, I just recognized that the CPU load went up after changing some rules to node red and I wonder if my entire code in node RED (~ 6000 LOC) might cause problems on my raspberry pi 3…

Another issue:
I am using node-red-contrib-telegrambot and listen to this Bot using the receiver.

This kind of works and I can receive messages from my chat.

However, as soon as I add another Telegram node (notify), this notify node works, but the receiver shows “polling error”

For both nodes I need to create a separate Telegram Bot config - one for receiver - one for notify.

Googling did not help yet…
There must be an option to be using more than one instances of telegram related nodes!?

the telegram bot is not that simple!

i advise to watch this video , take the code and try by yourself
thats what i did and its working great!

i can send commands
i can reccive updates
the bot can ask me Qs like turn of the boiler?
i share it with my wife

cosongor also did a accses level , so not every user can use all actions
to explain it i cant sorry!

I use the bot itself since a few years with the Telegram binding, so the main task is done ( I thought).

Thanks for sharing - I will check it out

I am strugling with temperature comparison:
I have Number:Temperature item and would like to compare this in nodeRED:

I tried different syntac for the temperature:
20.0 °C
and the one above, none of this works.
As soon as I use a temperature item which is just number (not declared as temperature in the items file), the comparison works as expecte.
How does the comparison need to look like to work here?