Node-RED as Alternative Rule Engine

Tags: #<Tag:0x00007fd30eaa0878> #<Tag:0x00007fd30eaa06e8>

(Rgerrans) #81

I saw it as a potential option for not needing to use variables to hold your message while you check staus. Since this allows you to store the two messages in an array which you can then pull them back out of.

(dalibor) #82

ok, so that would then go in “parallel” on the flow, when message comes in the flow it would at the same time check for openhab, store both messages in this node, and then catch/compare them in another if/else statement? Not sure what would happen if few messages come at the same time, i just started with node-red, still getting used to asynch way of thinking, sorry if it is obvious

Anyway, local flow variable solution is pretty simple and it is just a small amount of data that is stored in it (small json), so I think I will continie with it :slight_smile: might even create two simple custom store-retrieve nodes, to avoid writing 3 lines of codes in function in case i need to use it again :slight_smile:

(dalibor) #83

but it would be awesome if openhab2-get could forward original message within its flow

(Rgerrans) #84

If my memory serves me right, there was some discussion here:

At one point about trying to create a switch/get node in the openhab2 contrib nodes. I switched from them to mqtt so haven’t been engaged in any discussion. You could suggest it to the maintainer of those nodes.

(dalibor) #85

if anyone needs it, openhab2-get now does forward original message with its flow as msg.payload_in, which significantly simplifies things. You just need to parse/process data once after fetching the item (as now both messages are available).

You need to upgrade openhab2 nodes to the latest version for this (there is a little issue with automatic update if you installed node-red via openhabian script but there is a “fix” )

(Randomname) #86

I’ve created a more advanced version of the input node, to make my NodeRED flows less bloated. I’ve contacted the original creator and asked if he/she would be open for adding it to the plugin.

This is what you have to do when using the current original input node to subscribe to a change in state for a sensor:

So this is what my input node requires to accomplish the same:

And the configuration screen looks like this (to give an idea of what it can do):

My version of the more advanced input node is on github, but it’s not an official plugin so using it requires some manual installation action (not recommended though). If you’d like to see this added tot the openhab2 nodered plugin you can help out here.

(Brian M. Pedersen) #87

Thats looks great. How do I update my NR OH2 node to this version? I’ve installed mine though the openhabian configuration tool?

(Bert) #88

Hello all,
I am trying to start with node-RED as an alternative rule engine. My first attempt is getting my Sonoff TH16 switches working. I have two of those, which have a S17021 temperature sensor and the other an DS18B20 Temp and Humidity sensor. The switch part of these Sonoff’s is working perfectly. That was the easy part :wink:
But i do not know how to extract the temperature and humidity values and display these on the dashboard.
I am trying with this setup.

I found that i have to translate the JSON code in order te get the values. The debug output of this is:
But i don’t know how to get the individual values out the payload. Can somebody help on the way how to do this?

(Bert) #89

OK, i tried to extract the sensor object from the payload with a change node. Like this:

The cfg of the temperature change nodes is as follows:
I do get debug info from the json node, (see the commend nodes) bu i do not get any debug info after the change nodes…
Hope someone can shed a light on this… Bare with me, I am very new to node-Red…

(Brian M. Pedersen) #90

I think you need to split your payload, I did it with a HSB payload from a hue color bulb with the following function:

[{"id":"d6b05b45.5d4f28","type":"function","z":"b44f7d9a.bc6dc","name":"split HSB value","func":"var values = msg.payload.state.split(\",\");\nvar result = [];\n\n\nfor(i=0; i<values.length; i++) {\n    msg.payload[i] = { payload: values[i] }\n}\n\n\nreturn msg;","outputs":"1","noerr":0,"x":1060,"y":420,"wires":[["cb911c99.f2ca2","733b57bb.9a8028"]]}]

I would also try out the split and or json node for formatting your output.

(Vincent Regaud) #91

Can you post the json?

(Brian M. Pedersen) #92

I mean just try using the node red build in json note, It reads:

(Vincent Regaud) #93

Change node:
only one change needed
Set msg.payload
To msg.payload.SI1721.Temperature

(Bert) #94

I am not sure whitch fields i should change. In msg #89 i placed two node properties. Which of the two are you refering to? Could you please put an screen print from what you exaclty mean. I appreciate your help very much!

(Vincent Regaud) #95

The change Temperature node needs only one change
Set msg.payload
To msg.payload.SI1721.Temperature

(Vincent Regaud) #96


(Bert) #97

Hi @vzorglub
I configured the … node but i receive the same message as debug output…

And these are the change Temperature change node properties:

As you can see in de debug part, the debug from the change step is the same as fron the json step…
Perhaps must there some selection in the Gauge node?

I put also a text node and this displays the followingh:

(Bert) #98

Hi all, Found a solution using a function node:

(Vincent Regaud) #99

The SI code you provide before was wrong:


It didn’t work because node-red could get the object property and didn’t set a new msg.payload.
Your work around is correct.
I tend to use function nodes only when too many single nodes are needed and the flow gets messy or when there is no node with the functionality that I require.

Good luck

(Bert) #100

Yes the Sl7021 was a typo which i did not see…:frowning: I am glad it works now. Also have the graphs.
But now i use two function nodes… It should also could work with a switch node. I’l keep that for later on; i will keep on experimenting with alternatives.

Thank you for your help!