Node-RED as Alternative Rule Engine

@dakipro just saw this which might be useful
https://www.npmjs.com/package/node-red-contrib-batcher

I saw that one before for some other application (I want to collect and send log-type messages once a day), but it looks I have to use database for that (mysql, because that I know).

Not sure how link you shared applies for checking if a switch is on/off in openhab? If I understand from description, it just collects messages and when buffer is full it sends them as one message. It could perhaps hold messages until a switch is triggered back?
Or were you referring to some other scenario?

Anyway, since I am going to use database for log-type messages, I might as well log all communication and send it with the email. Just for a control, and if I was “offline” with the switch I would get missed communication the next day.

I would like daily report of activity, I like the way home-assistant does that with history overview https://home-assistant.io/components/history/
but that is perhaps separate project from node-red :slight_smile: (one could install home-assistant just for that functionality and monitor mqtt)

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.

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:

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

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.

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” https://github.com/openhab/openhabian/issues/213#issuecomment-341232300 )

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.

2 Likes

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

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:
image
But i don’t know how to get the individual values out the payload. Can somebody help on the way how to do this?

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:
image
and
image
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…

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.

Can you post the json?

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

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

@vzorglub
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!

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

image

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


And these are the change Temperature change node properties:
image

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:

1 Like

Hi all, Found a solution using a function node:
image
image