Node-RED as Alternative Rule Engine

Sorry, was on travel the last few weeks so now getting back into updating the tutorial as I learn more during my migration.

Just revised the Item changed trigger:

And revised Item <item%gt; received command [<command>] / Item <item> received update [<state>] to differentiate between a change in status vs. just an update (where the status might not change)

Updated * If…then Statements to include the openhab-get node for checking item state

If you want to base your checks on the status of other items in OpenHab, you have two ways to do this. One option is to assign a state change to a variable as shown above (Variables)

The other is to use an openhab2-get node to lookup the item’s state. Because this node returns a single response object containing item name, label, state, etc. You then need to do a logic check on a slightly modified topic to specify which you want to use.

Hey @rgerrans,
just realized that I never wrote back to you! Just as we discussed we’ve looked into NodeRED and it’s part of openHABian v1.3:
So far I did not hear any negative feedback. Feel free to check it out, let me know if any further automation step during the installation might be useful.
If you like, you can mention the integration in your first posting.
Best! :wave:

@ThomDietrich Thanks for the heads up and will add the reference. I have a few more pieces to add to this tutorial and then will likely spin off a new one as I finish migrating from the openhab2 node to straight mqtt interactions

I managed to get the Sense-hat data to get shown in the NodeRed Dashboard.
Is it possible to get the SenseHat data into Openhab? To be displayed for example in “HABPanel”?

Thanks for your help! :slight_smile:

I’d just create a number item in OpenHab and use the OpenHAB-out node to push the values to it.

1 Like

Hello Community,

I just run into a little problem. I am working with a Xiaomi Mihome Wireless Switch, which only supports a “Button Event” mihome:sensor_switch:158d00014a0770:button <- like this.
How can I use a Button Event with Node-Red? :thinking:

Not sure what you are asking. Once you get the device configured in OpenHAB as an item (if you are having issues with that I’d open up a separate thread, not take this one off topic) then you just use the OpenHAB-in / -out nodes to let OpenHAB control the device. If you are trying to go direct from Xiaomi to Node-RED that’s more approriate for the Node-RED forums.

Okay maybe it was not clear.
With textual rules I can do this

rule “Xiaomi Switch”

Channel “mihome:sensor_switch:158d00014a0770:button” triggered

var actionName = receivedEvent.getEvent()
switch(actionName) {
if (v_Switch_Outdoor_Xiaomi_VirtualSwitch.state==ON) {
sendCommand(a_Licht_Outdoor_Sonoff4Channel_1_Fahrradstaender, OFF)
sendCommand(a_Licht_Outdoor_Sonoff4Channel_2_Biertisch, OFF)
sendCommand(a_Licht_Outdoor_Sonoff4Channel_3_Rauchertisch, OFF)
sendCommand(a_Licht_Outdoor_SonoffBasic_Grilllampe, OFF)
sendCommand(v_Switch_Outdoor_Xiaomi_VirtualSwitch, OFF)
else {
sendCommand(a_Licht_Outdoor_Sonoff4Channel_1_Fahrradstaender, ON)
sendCommand(a_Licht_Outdoor_Sonoff4Channel_2_Biertisch, ON)
sendCommand(a_Licht_Outdoor_Sonoff4Channel_3_Rauchertisch, ON)
sendCommand(a_Licht_Outdoor_SonoffBasic_Grilllampe, ON)
sendCommand(v_Switch_Outdoor_Xiaomi_VirtualSwitch, ON)
// case “DOUBLE_PRESSED”: {
// }
// case “LONG_PRESSED”: {
// }
// case “LONG_RELEASED”: {
// }


HOW can I do this with Node-Red

I’m not at all familiar with mihome but assuming that’s the binding, you can define an item in your .items file based on that channel:

Switch some_name {mihome:sensor_switch:158d00014a0770:button}

Then you can use the openHAB-in node to trigger off that item. It looks to me that v_Switch_Outdoor_Xiaomi_VirtualSwitch.state may already be an item defined to that channel?

The Button “Event” has no “Channel”

Wait WTF, I eat a broom… it does fml…

But I can’t link my existing Item, I have to figure out what is going wrong there

No worries, we all have those facepalm moments.

I’d take that up in a separate thread related to that binding. Given you can reference it in a rule, I’d bet you can create a text item along the lines of what I suggested above.

But now I cant link my Item :roll_eyes:
This seems a bit bugged, I can’t select an item Type :rofl:
How it is.
I can’t link an Item to a “Button event” channel.
I will post this on Xiaomi / Mihome too

Definitely looks like an issue there. I’d still suggest trying the text file route as another option in the meantime.

Can you tell me how to check for 2 states?
Like if time == 10:00 and Movement == True then Do Stuff?

Assuming your two states are coming from the same trigger node, easiest is just two sequential switch nodes. There is an optional Match node you can install that allows you to do it in a single node. I tend to do the former so it’s easily visible to me when I glance at my flow and I can throw a debug node on each one separately if I’m having issues.

Like this, but this does not work.
I want to check IF time is correct AND movment is True THEN switch stuff on

You will need to use a flow or global variable to define your time since you don’t have a method to go back to Bigtimer and ask if it’s that time.

For mine I have a bunch of time triggered events and a number of checks like yours where if something triggers I only want action during a time frame. So I just set up a single flow to define all my time triggers / time states. For states I used global variables:

So in this case dayMode is defined as a global variable. Then I just have a switch case that checks the dayMode variable after I checked if I achieved the trigger state:

In this case my trigger is linked to an outside temperature I get from a WeatherUnderground node. Then if temperature is either above a certain range in the summer or below in the winter I run a day mode check against my global dayMode variable to make sure its during the day before I turn on the switch for the fan/heater.

Might be a little too much info but thought that might help to see a flow example

I found something strange again.
Which is really sad, because there are AND / OR Logic Gate nodes for Node-Red which need a Topic.
Listens to state changes of a selected openHAB Item.

BUT! If you look into the Debug log of the outgoing MSG there is no topic.
The bottom Node with “MyTopic” is a simple injection to compare a msg.payload with a topic.

Thats because your debug node is set to only show msg.payload. Set your debug to msg.topic or choose full object and you’ll see the additional info available to you (sorry, switched to mqtt so don’t remember exactly all the data the openhab-in node passes)

Edit: saw that you grabbed the info screenshot for the in node. You can put in a change node to move msg.item to msg.topic ahead of your logic check.

1 Like