Node-RED as a rule/script engine for openHAB

Hello Jürgen

What would like your payload to be after the condition was met?


I wan’t to control my blinds. When the rainsensor says, that it is raining, then the blinds shouldn’t open. But the rainsensor is not able to detekt, if it is snowing instead of raining. So i wnat to build a switch. When the temperature is below 0°C then usualy it is snowing. And then the blinds should open in any case.

I tried to follow this tutorial and i think, i have found my mistake…
i will try this, when i’m at home…



Now it is working…

[{"id":"b06b15bf.ee6b38","type":"openhab2-in","z":"b8c4244.ab94bd8","name":"Außentemperatur","controller":"a6d4cb64.b94bd8","itemname":"Garten_Temperatur","x":180,"y":420,"wires":[["8dbaeda6.5b8e"],[]]},{"id":"8dbaeda6.5b8e","type":"switch","z":"b8c4244.ab94bd8","name":"Gefrierpunkt?","property":"payload","propertyType":"msg","rules":[{"t":"gt","v":"0","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":440,"y":420,"wires":[["62f74bed.1efc44"],["e65f51d7.33b46"]]},{"id":"e65f51d7.33b46","type":"change","z":"b8c4244.ab94bd8","name":"unter gefrierpunkt","rules":[{"t":"set","p":"gefrierpunkt","pt":"flow","to":"NO","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":810,"y":480,"wires":[[]]},{"id":"62f74bed.1efc44","type":"change","z":"b8c4244.ab94bd8","name":"über Gefrierpunkt","rules":[{"t":"set","p":"gefrierpunkt","pt":"flow","to":"YES","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":810,"y":380,"wires":[[]]},{"id":"a6d4cb64.b94bd8","type":"openhab2-controller","z":"","name":"OpenHab","protocol":"http","host":"localhost","port":"8080","path":"","username":"","password":""}]

I had to use “otherwise” in the switch-node…


Hi Paul, what kind of nodes are the orange switch Sun set to xx h nodes in your example?


Did answer this myself, it is the node-red-contrib-time-range-switch.

1 Like

Hi can someone give code exmpales for lets say MQTT switches
i am also using node red and OH and i am doing all from scratch again…

i want to take some exmpales maybe i can do better this time :slight_smile:

on my system :

  1. MQTT is going from Node to OH, and OH is just where the items are stored and changed
  2. RM2 bidnidng on OH , Node takes care of all the sending of coomands and rules
  3. sensor data coming from both OH and Node
  4. Siri bidnidng on OH , Node takes care of the rules related to the switchs

yep probbly the best post out there!
if there is more?..
and thanks vince

I just started to play around with Node Red and have a rookie question.

With my alarmclock in the morning I would like to switch ON my coffee machine.
But only if I am at home.

I have realized this with the following structure, but I assume there must be a much simpler way.

What I do is, I join both to ON/ON and just let this through. I then change ON/ON to ON to switch the coffee machine (Strega).

A short feedback about options to improve (simplify) are greatly appreciated.


You could use an openhab get node triggered by the change of your alarm clock item that gets you presence and than a switch node which evaluates only this. That way you would have two nodes less but any way that works reliably is good :smiley:

I know that Scheduling is the holy grail that we all seek, so imagine my delight in finding this node

Now we / I just need to create some kind of way to put it into a GUI

Does anyone have any ideas how we can put the scheduling variables into a UI like this?


I’ve asked Niklas if it would be possible to expose the scheduling part to a NodeRed Dashboard.


Yes great Node , there is an option to set to minutely output , so some things that needs to stay on just get on command each min, if its already on so nothing… very good for some critical house stuff, and provided some good workarounds hhh

1 Like

Hi Johannes,

that’s a good hint (I just started playing around with it).
My expectation would be that the switch returns “ON” only if I use this approach:

However, it returns the entire message like:
22.6.2019, 07:23:22node: DEBUG 1

msg.payload : Object

{ link: "http://localhost:8080/rest/ite…", state: "ON", editable: false, type: "Switch", name: "Loc_Home_NCO" … }

Got it myself: I needed to put a change node behind it to set the msg “msg.payload” to “msg.payload.state”

1 Like

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.