Node-RED as Alternative Rule Engine

I use a flow or global variable to check the item state within a function node. That is no fiddling for me.

Checking the group events might be more tricky but I have not used that so far.

I don’t want to bitch about openhab. I love it and it is the only open source project so far that convinced me to donate money regularly. Just wanted to point out that the great developer team might save time on developing as some really good solutions are already out there and they can focus on even more innovative things for the nexts major release.

Nodered is already included as an option in Openhabian were it comes ready with the Openhab nodes installed. That is as far as integration will go I’m afraid. I’m a big fan of Nodered and use it a lot but I can see the need for openhab to be an all in one Self sustained solution and Nodered can never become part of that as it is completely independent project which is outside of the control of the openHAB project. So it would create unnecessary dependency on another project. So I guess we will have to live with the limitations of the Rest api for now.
Best regards Johannes

2 Likes

+1 for Node Red!!!

its the best thing that can happen to noobs all over the world :slight_smile:
but serusily , i was able to do some seruis workarounds with node-red, i am not sure OH is that
flexible , in node-red you can get things worng and still make it wrok

also its alwys good to have another way of doing things, when all goes bad

4 Likes

Hi All

A happy new year to everyone :slight_smile:

Something has been bugging me for a while, so I have spent an hour finding a solution.

What I wanted to do was mimic the Press and Hold dimming / volume change that you might see in some hardware.

I found a way to detect a button event, get the current Item state (a number) and add or subtract a number then inject the new value back into the Volume or Dimmer Item.

This worked well, I had 2 buttons.
1 for up
1 for down

I could even use the Long_Press and Release states from these buttons to loop the trigger so that holding the button down kept on having an effect, until the button was released.

What I wanted to do was reduce this down to 1 button, that would increase the volume (or brightness) until a limit was hit, then decrease until another limit was hit.

I found the solution by using a Global Value in Node Red.

Here is what I have running now in a Function node :smile_cat:

var volume = Number(msg.payload.state);
var button = String(msg.payload_in);
var newMsg = { payload:button};
var Dir = global.get("LoungeDir");

var newVolume = 0;

//  newVolume = volume + 5;
msg.payload = volume;

if (isNaN(Dir)) {
     global.set("LoungeDir", 1);
     Dir = global.get("LoungeDir");
}

if  (volume <= 6 ) { if (Dir == -1)  {
        newVolume = volume + 5;
        msg.payload = newVolume;
        global.set("LoungeDir", 1);
        return [msg,newMsg];
	}}
	
if  (volume <= 90 ) { if (Dir == 1)  {
        newVolume = volume + 5;
        msg.payload = newVolume;
//        global.set("LoungeDir", 1);
        return [msg,newMsg];
	}}
	
if  (volume >= 90 ) { if (Dir == 1)  {
        newVolume = volume - 5;
        msg.payload = newVolume;
        global.set("LoungeDir", -1);
        return [msg,newMsg];
	}}
	
if  (volume <= 90 ) { if (Dir == -1)  {
        newVolume = volume - 5;
        msg.payload = newVolume;
//        global.set("LoungeDir", 1);
        return [msg,newMsg];
	}}	



return [msg,newMsg]; 

Here is the entire collection of Nodes

[
    {
        "id": "bfe462be.f71a5",
        "type": "function",
        "z": "f5370db.29be5f",
        "name": "Dining Room Btn 3",
        "func": "var event = msg.payload.event;\nvar channel = msg.payload.channel;\nvar newMsg = { payload: msg.payload.event };\nvar button = \"velbus:vmbgp2:c5053467:24: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": 390,
        "y": 140,
        "wires": [
            [],
            [
                "6ba85279.a48a9c"
            ],
            [
                "82c396c8.6ef1d8"
            ],
            [
                "f7ff8751.3c9c78"
            ]
        ],
        "outputLabels": [
            "Whole Msg",
            "PRESSED",
            "LONG_PRESSED",
            "RELEASED"
        ]
    },
    {
        "id": "6ba85279.a48a9c",
        "type": "openhab2-get",
        "z": "f5370db.29be5f",
        "name": "",
        "controller": "deaa963.282a968",
        "itemname": "LoungeZone_Volume",
        "x": 880,
        "y": 60,
        "wires": [
            [
                "b93a65be.3a6588"
            ]
        ]
    },
    {
        "id": "4954678d.cca448",
        "type": "openhab2-out",
        "z": "f5370db.29be5f",
        "name": "Lounge Volume",
        "controller": "deaa963.282a968",
        "itemname": "LoungeZone_Volume",
        "topic": "ItemCommand",
        "payload": "",
        "x": 1220,
        "y": 140,
        "wires": [
            []
        ]
    },
    {
        "id": "82c396c8.6ef1d8",
        "type": "looptimer",
        "z": "f5370db.29be5f",
        "duration": "1",
        "units": "Second",
        "maxloops": "15",
        "maxtimeout": "1",
        "maxtimeoutunits": "Minute",
        "name": "",
        "x": 700,
        "y": 140,
        "wires": [
            [
                "6ba85279.a48a9c"
            ],
            []
        ]
    },
    {
        "id": "f7ff8751.3c9c78",
        "type": "change",
        "z": "f5370db.29be5f",
        "name": "Stop Loop",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "STOP",
                "tot": "str"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 570,
        "y": 240,
        "wires": [
            [
                "82c396c8.6ef1d8"
            ]
        ]
    },
    {
        "id": "b93a65be.3a6588",
        "type": "function",
        "z": "f5370db.29be5f",
        "name": "Change Volume value by 5",
        "func": "var volume = Number(msg.payload.state);\nvar button = String(msg.payload_in);\nvar newMsg = { payload:button};\nvar Dir = global.get(\"LoungeDir\");\n\nvar newVolume = 0;\n\n//  newVolume = volume + 5;\nmsg.payload = volume;\n\nif (isNaN(Dir)) {\n     global.set(\"LoungeDir\", 1);\n     Dir = global.get(\"LoungeDir\");\n}\n\nif  (volume <= 6 ) { if (Dir == -1)  {\n        newVolume = volume + 5;\n        msg.payload = newVolume;\n        global.set(\"LoungeDir\", 1);\n        return [msg,newMsg];\n\t}}\n\t\nif  (volume <= 90 ) { if (Dir == 1)  {\n        newVolume = volume + 5;\n        msg.payload = newVolume;\n//        global.set(\"LoungeDir\", 1);\n        return [msg,newMsg];\n\t}}\n\t\nif  (volume >= 90 ) { if (Dir == 1)  {\n        newVolume = volume - 5;\n        msg.payload = newVolume;\n        global.set(\"LoungeDir\", -1);\n        return [msg,newMsg];\n\t}}\n\t\nif  (volume <= 90 ) { if (Dir == -1)  {\n        newVolume = volume - 5;\n        msg.payload = newVolume;\n//        global.set(\"LoungeDir\", 1);\n        return [msg,newMsg];\n\t}}\t\n\n\n\nreturn [msg,newMsg];",
        "outputs": 2,
        "noerr": 0,
        "x": 900,
        "y": 200,
        "wires": [
            [
                "deb42c17.7b645",
                "4954678d.cca448"
            ],
            [
                "43fac0f6.8305b"
            ]
        ]
    },
    {
        "id": "ec5643f1.2da01",
        "type": "inject",
        "z": "f5370db.29be5f",
        "name": "",
        "topic": "",
        "payload": "PRESSED",
        "payloadType": "str",
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "x": 340,
        "y": 200,
        "wires": [
            [
                "6ba85279.a48a9c"
            ]
        ]
    },
    {
        "id": "deb42c17.7b645",
        "type": "debug",
        "z": "f5370db.29be5f",
        "name": "",
        "active": true,
        "tosidebar": false,
        "console": false,
        "tostatus": true,
        "complete": "payload",
        "targetType": "msg",
        "x": 1210,
        "y": 200,
        "wires": []
    },
    {
        "id": "43fac0f6.8305b",
        "type": "debug",
        "z": "f5370db.29be5f",
        "name": "",
        "active": true,
        "tosidebar": false,
        "console": false,
        "tostatus": true,
        "complete": "payload",
        "targetType": "msg",
        "x": 1210,
        "y": 260,
        "wires": []
    },
    {
        "id": "569a9540.f364ec",
        "type": "inject",
        "z": "f5370db.29be5f",
        "name": "",
        "topic": "",
        "payload": "LONG_PRESSED",
        "payloadType": "str",
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "x": 310,
        "y": 240,
        "wires": [
            [
                "82c396c8.6ef1d8"
            ]
        ]
    },
    {
        "id": "a2023990.27a8e8",
        "type": "inject",
        "z": "f5370db.29be5f",
        "name": "",
        "topic": "",
        "payload": "10",
        "payloadType": "str",
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "x": 1190,
        "y": 60,
        "wires": [
            [
                "4954678d.cca448"
            ]
        ]
    },
    {
        "id": "63c707ec.0969b8",
        "type": "inject",
        "z": "f5370db.29be5f",
        "name": "",
        "topic": "",
        "payload": "RELEASED",
        "payloadType": "str",
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "x": 330,
        "y": 280,
        "wires": [
            [
                "f7ff8751.3c9c78"
            ]
        ]
    },
    {
        "id": "deaa963.282a968",
        "type": "openhab2-controller",
        "z": "",
        "name": "OpenHAB2 Home",
        "protocol": "http",
        "host": "127.0.0.1",
        "port": "8080",
        "path": "",
        "username": "",
        "password": ""
    }
]

The amusing thing (or at least to my mind) is that if I hold the button in the Long_Press state, the volume (or brightness) will happily glide between 5 & 95.

Not a feature I can see using very often, but a nice side effect.

I hope this helps someone.

Best wishes,

Stuart

1 Like

Hi

I’ve managed to code my first bit of Javascript in a Function node.

It’s not pretty, but it’s working :smile:

If you have a Velbus setup, you might be interested to take a look

Now here’s something really interesting…

There is a “Blocky” Node set for Node-Red

I wish I have known that before I embarked on my painful JavaScript journey

Oh well, timing is everything

Thanks for the tip @QuagmireMan

Hi All .From a Still LOCKED DOWN South Africa.
i have a question. not sure if this is the right place to ask. i use node red for my Alarm monitoring. but i have a slight problem i cant wrap my head around.

  1. when i havesay a Burglary condition. and the alarm goues in to reset time. (still armed away) my rule sets the alarm status back to disarmed. but it is still armed. how do i have node red look if my alarms armed input on my raspberry pi is still armed and send the armed msg. instead of the disarmed.

here is my flows.

[
    {
        "id": "34244cb1.db726c",
        "type": "tab",
        "label": "Alarm_Status",
        "disabled": false,
        "info": ""
    },
    {
        "id": "9fa153b5.8770b8",
        "type": "mqtt out",
        "z": "34244cb1.db726c",
        "name": "",
        "topic": "OpenHAB-DB/alarmstat/",
        "qos": "",
        "retain": "",
        "broker": "d7d44fb3.3406d8",
        "x": 1610,
        "y": 320,
        "wires": []
    },
    {
        "id": "2eb0c44b.03f504",
        "type": "switch",
        "z": "34244cb1.db726c",
        "name": "",
        "property": "payload",
        "propertyType": "msg",
        "rules": [
            {
                "t": "eq",
                "v": "Armed-Away",
                "vt": "str"
            },
            {
                "t": "eq",
                "v": "Armed-Stay",
                "vt": "str"
            },
            {
                "t": "eq",
                "v": "Burglary",
                "vt": "str"
            },
            {
                "t": "eq",
                "v": "Panic-Duress",
                "vt": "str"
            },
            {
                "t": "eq",
                "v": "0",
                "vt": "str"
            },
            {
                "t": "eq",
                "v": "Siren Error",
                "vt": "str"
            },
            {
                "t": "eq",
                "v": "Zone Tamper",
                "vt": "str"
            },
            {
                "t": "eq",
                "v": "Wifi jam",
                "vt": "str"
            },
            {
                "t": "eq",
                "v": "Detector Bat",
                "vt": "str"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 9,
        "x": 1030,
        "y": 440,
        "wires": [
            [
                "9fa153b5.8770b8",
                "100b83e3.e34014"
            ],
            [
                "9fa153b5.8770b8",
                "100b83e3.e34014"
            ],
            [
                "9fa153b5.8770b8",
                "100b83e3.e34014",
                "cf044360.17e51"
            ],
            [
                "9fa153b5.8770b8",
                "100b83e3.e34014",
                "cf044360.17e51"
            ],
            [
                "9b6094a7.9c9228",
                "100b83e3.e34014"
            ],
            [
                "9fa153b5.8770b8",
                "cf044360.17e51"
            ],
            [
                "9fa153b5.8770b8",
                "cf044360.17e51"
            ],
            [
                "9fa153b5.8770b8",
                "cf044360.17e51"
            ],
            [
                "9fa153b5.8770b8",
                "cf044360.17e51"
            ]
        ]
    },
    {
        "id": "ab6f54ce.5f3578",
        "type": "switch",
        "z": "34244cb1.db726c",
        "name": "",
        "property": "payload",
        "propertyType": "msg",
        "rules": [
            {
                "t": "eq",
                "v": "1",
                "vt": "str"
            },
            {
                "t": "eq",
                "v": "0",
                "vt": "str"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 2,
        "x": 210.5,
        "y": 92,
        "wires": [
            [
                "e2ba3db1.d4d5f"
            ],
            [
                "2eb0c44b.03f504"
            ]
        ]
    },
    {
        "id": "e2ba3db1.d4d5f",
        "type": "change",
        "z": "34244cb1.db726c",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "Armed-Away",
                "tot": "str"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 233.5,
        "y": 36,
        "wires": [
            [
                "2eb0c44b.03f504"
            ]
        ]
    },
    {
        "id": "9b6094a7.9c9228",
        "type": "change",
        "z": "34244cb1.db726c",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "Disarmed",
                "tot": "str"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 1400,
        "y": 440,
        "wires": [
            [
                "9fa153b5.8770b8"
            ]
        ]
    },
    {
        "id": "cfe141b3.77af08",
        "type": "rpi-gpio in",
        "z": "34244cb1.db726c",
        "name": "Armed-Away",
        "pin": "33",
        "intype": "down",
        "debounce": "25",
        "read": false,
        "x": 75,
        "y": 92,
        "wires": [
            [
                "ab6f54ce.5f3578"
            ]
        ]
    },
    {
        "id": "dfacdce5.d50d6",
        "type": "switch",
        "z": "34244cb1.db726c",
        "name": "",
        "property": "payload",
        "propertyType": "msg",
        "rules": [
            {
                "t": "eq",
                "v": "1",
                "vt": "str"
            },
            {
                "t": "eq",
                "v": "0",
                "vt": "str"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 2,
        "x": 215.5,
        "y": 237,
        "wires": [
            [
                "f86a1487.0d2358"
            ],
            [
                "2eb0c44b.03f504"
            ]
        ]
    },
    {
        "id": "f86a1487.0d2358",
        "type": "change",
        "z": "34244cb1.db726c",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "Armed-Stay",
                "tot": "str"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 207.5,
        "y": 172,
        "wires": [
            [
                "2eb0c44b.03f504"
            ]
        ]
    },
    {
        "id": "c8548dbd.331cb8",
        "type": "rpi-gpio in",
        "z": "34244cb1.db726c",
        "name": "Armed-Stay",
        "pin": "31",
        "intype": "down",
        "debounce": "25",
        "read": false,
        "x": 75,
        "y": 238,
        "wires": [
            [
                "dfacdce5.d50d6"
            ]
        ]
    },
    {
        "id": "1a05a6e1.75e2e1",
        "type": "switch",
        "z": "34244cb1.db726c",
        "name": "",
        "property": "payload",
        "propertyType": "msg",
        "rules": [
            {
                "t": "eq",
                "v": "1",
                "vt": "str"
            },
            {
                "t": "eq",
                "v": "0",
                "vt": "str"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 2,
        "x": 328.5,
        "y": 368,
        "wires": [
            [
                "72eb3758.2b698"
            ],
            [
                "2eb0c44b.03f504"
            ]
        ]
    },
    {
        "id": "72eb3758.2b698",
        "type": "change",
        "z": "34244cb1.db726c",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "Burglary",
                "tot": "str"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 206.5,
        "y": 306,
        "wires": [
            [
                "2eb0c44b.03f504"
            ]
        ]
    },
    {
        "id": "48e3603f.68647",
        "type": "rpi-gpio in",
        "z": "34244cb1.db726c",
        "name": "Burglary",
        "pin": "35",
        "intype": "down",
        "debounce": "25",
        "read": false,
        "x": 65,
        "y": 369,
        "wires": [
            [
                "48b0a0bb.a86cb8"
            ]
        ]
    },
    {
        "id": "48b0a0bb.a86cb8",
        "type": "trigger",
        "z": "34244cb1.db726c",
        "op1": "1",
        "op2": "0",
        "op1type": "str",
        "op2type": "str",
        "duration": "4",
        "extend": true,
        "units": "s",
        "reset": "",
        "bytopic": "all",
        "name": "",
        "x": 201.5,
        "y": 368,
        "wires": [
            [
                "1a05a6e1.75e2e1"
            ]
        ]
    },
    {
        "id": "e064d73b.89b488",
        "type": "switch",
        "z": "34244cb1.db726c",
        "name": "",
        "property": "payload",
        "propertyType": "msg",
        "rules": [
            {
                "t": "eq",
                "v": "1",
                "vt": "str"
            },
            {
                "t": "eq",
                "v": "0",
                "vt": "str"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 2,
        "x": 372.5,
        "y": 473,
        "wires": [
            [
                "7c7685c5.40235c"
            ],
            [
                "2eb0c44b.03f504"
            ]
        ]
    },
    {
        "id": "7c7685c5.40235c",
        "type": "change",
        "z": "34244cb1.db726c",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "Panic-Duress",
                "tot": "str"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 206.5,
        "y": 411,
        "wires": [
            [
                "2eb0c44b.03f504"
            ]
        ]
    },
    {
        "id": "8b24b2b.4e896d",
        "type": "rpi-gpio in",
        "z": "34244cb1.db726c",
        "name": "Panic-Duress",
        "pin": "37",
        "intype": "down",
        "debounce": "25",
        "read": false,
        "x": 75,
        "y": 474,
        "wires": [
            [
                "a9d97f7f.da1608"
            ]
        ]
    },
    {
        "id": "a9d97f7f.da1608",
        "type": "trigger",
        "z": "34244cb1.db726c",
        "op1": "1",
        "op2": "0",
        "op1type": "str",
        "op2type": "str",
        "duration": "4",
        "extend": true,
        "units": "s",
        "reset": "",
        "bytopic": "all",
        "name": "",
        "x": 229.5,
        "y": 475,
        "wires": [
            [
                "e064d73b.89b488"
            ]
        ]
    },
    {
        "id": "50481e36.8b22c8",
        "type": "inject",
        "z": "34244cb1.db726c",
        "name": "",
        "topic": "",
        "payload": "1",
        "payloadType": "str",
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "x": 90,
        "y": 540,
        "wires": [
            [
                "a9d97f7f.da1608"
            ]
        ]
    },
    {
        "id": "100b83e3.e34014",
        "type": "debug",
        "z": "34244cb1.db726c",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "x": 1610,
        "y": 180,
        "wires": []
    },
    {
        "id": "19021deb.288ee2",
        "type": "inject",
        "z": "34244cb1.db726c",
        "name": "",
        "topic": "",
        "payload": "0",
        "payloadType": "str",
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "x": 467,
        "y": 32,
        "wires": [
            [
                "2eb0c44b.03f504"
            ]
        ]
    },
    {
        "id": "abf2befa.1849b",
        "type": "switch",
        "z": "34244cb1.db726c",
        "name": "",
        "property": "payload",
        "propertyType": "msg",
        "rules": [
            {
                "t": "eq",
                "v": "1",
                "vt": "str"
            },
            {
                "t": "eq",
                "v": "0",
                "vt": "str"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 2,
        "x": 230,
        "y": 640,
        "wires": [
            [
                "a3a33786.632fa8"
            ],
            [
                "2eb0c44b.03f504"
            ]
        ]
    },
    {
        "id": "a3a33786.632fa8",
        "type": "change",
        "z": "34244cb1.db726c",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "Siren Error",
                "tot": "str"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 222,
        "y": 575,
        "wires": [
            [
                "2eb0c44b.03f504"
            ]
        ]
    },
    {
        "id": "97ef033f.e52d8",
        "type": "rpi-gpio in",
        "z": "34244cb1.db726c",
        "name": "Siren Error",
        "pin": "29",
        "intype": "down",
        "debounce": "25",
        "read": false,
        "x": 79.5,
        "y": 641,
        "wires": [
            [
                "abf2befa.1849b"
            ]
        ]
    },
    {
        "id": "64b306c6.66d068",
        "type": "switch",
        "z": "34244cb1.db726c",
        "name": "",
        "property": "payload",
        "propertyType": "msg",
        "rules": [
            {
                "t": "eq",
                "v": "1",
                "vt": "str"
            },
            {
                "t": "eq",
                "v": "0",
                "vt": "str"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 2,
        "x": 230,
        "y": 760,
        "wires": [
            [
                "7dcbb712.044c48"
            ],
            [
                "2eb0c44b.03f504"
            ]
        ]
    },
    {
        "id": "7dcbb712.044c48",
        "type": "change",
        "z": "34244cb1.db726c",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "Zone Tamper",
                "tot": "str"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 222,
        "y": 695,
        "wires": [
            [
                "2eb0c44b.03f504"
            ]
        ]
    },
    {
        "id": "e1aa1bf1.c3a2e8",
        "type": "rpi-gpio in",
        "z": "34244cb1.db726c",
        "name": "Zone Tamper",
        "pin": "40",
        "intype": "down",
        "debounce": "25",
        "read": false,
        "x": 89.5,
        "y": 761,
        "wires": [
            [
                "64b306c6.66d068"
            ]
        ]
    },
    {
        "id": "41ce7145.78061",
        "type": "switch",
        "z": "34244cb1.db726c",
        "name": "",
        "property": "payload",
        "propertyType": "msg",
        "rules": [
            {
                "t": "eq",
                "v": "1",
                "vt": "str"
            },
            {
                "t": "eq",
                "v": "0",
                "vt": "str"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 2,
        "x": 230,
        "y": 900,
        "wires": [
            [
                "310c72e6.c49a6e"
            ],
            [
                "2eb0c44b.03f504"
            ]
        ]
    },
    {
        "id": "310c72e6.c49a6e",
        "type": "change",
        "z": "34244cb1.db726c",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "Detector Bat",
                "tot": "str"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 222,
        "y": 835,
        "wires": [
            [
                "2eb0c44b.03f504"
            ]
        ]
    },
    {
        "id": "a19d3fa3.1c6b9",
        "type": "rpi-gpio in",
        "z": "34244cb1.db726c",
        "name": "Detector Bat",
        "pin": "38",
        "intype": "down",
        "debounce": "25",
        "read": false,
        "x": 89.5,
        "y": 901,
        "wires": [
            [
                "41ce7145.78061"
            ]
        ]
    },
    {
        "id": "809b7c20.94568",
        "type": "switch",
        "z": "34244cb1.db726c",
        "name": "",
        "property": "payload",
        "propertyType": "msg",
        "rules": [
            {
                "t": "eq",
                "v": "1",
                "vt": "str"
            },
            {
                "t": "eq",
                "v": "0",
                "vt": "str"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 2,
        "x": 230,
        "y": 1020,
        "wires": [
            [
                "f3e849a5.e84cb8"
            ],
            [
                "2eb0c44b.03f504"
            ]
        ]
    },
    {
        "id": "f3e849a5.e84cb8",
        "type": "change",
        "z": "34244cb1.db726c",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "Wifi jam",
                "tot": "str"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 222,
        "y": 955,
        "wires": [
            [
                "2eb0c44b.03f504"
            ]
        ]
    },
    {
        "id": "3e0fa69b.bb458a",
        "type": "rpi-gpio in",
        "z": "34244cb1.db726c",
        "name": "Wifi jam",
        "pin": "36",
        "intype": "down",
        "debounce": "25",
        "read": false,
        "x": 69.5,
        "y": 1021,
        "wires": [
            [
                "809b7c20.94568"
            ]
        ]
    },
    {
        "id": "cf044360.17e51",
        "type": "mqtt out",
        "z": "34244cb1.db726c",
        "name": "",
        "topic": "OpenHAB-DB/alarmSystem/",
        "qos": "2",
        "retain": "true",
        "broker": "d7d44fb3.3406d8",
        "x": 1710,
        "y": 580,
        "wires": []
    },
    {
        "id": "d7d44fb3.3406d8",
        "type": "mqtt-broker",
        "z": "",
        "name": "OpenHAB-MQTT",
        "broker": "192.168.1.5",
        "port": "1883",
        "clientid": "OpenHAB-db",
        "usetls": false,
        "compatmode": true,
        "keepalive": "60",
        "cleansession": true,
        "birthTopic": "",
        "birthQos": "0",
        "birthRetain": "false",
        "birthPayload": "",
        "closeTopic": "",
        "closeQos": "0",
        "closeRetain": "false",
        "closePayload": "",
        "willTopic": "",
        "willQos": "0",
        "willRetain": "false",
        "willPayload": ""
    }
]

Hi

Are you using openHAB2 to monitor the state of the Raspberry Pi input?

There’s a great openHAB2 “GET” node that queries the state of an Item when it’s triggered.

And the output is seen as msg.payload.state

And in you still want the state of whatever triggered the GET node, you can find it with
msg.payload_in

Does that help?

no i have OpenHAB running on a server. and node red sends the information to mqtt where openhab gets the information.
so basically the pi is just a unit running node red and node red gets the statuses of the gpio and send strings to mqtt where openhab subscribes to it. then the rule below sends a broadcast to notify me .

rule "alarm notify"
when
	Item Alarm_Status changed
then
	// do something
   sendBroadcastNotification("Alarm " + Alarm_Status.state.toString + " - " + now.toString("MM/dd HH:mm "))	
end

So I’m using Node-Red a bit to respond to value requests of OH items…and it’s working fairly well.

I saw this YAML script someone is using with HA

alias: Garbage Week
sequence:
- data: {}
service: alexa_media.update_last_called
- delay: 00:00:01
- service: notify.alexa_media
data_template:
target:
- '{{ states.sensor.last_alexa.state }}'
data:
type: tts
message: This week's collection is {{ states('sensor.garbage_collection') }},
and it needs to be put out {{ states('sensor.garbage_collection_day') }}.

HA has a system node, that allows you to script back to Alexa with the mixture of text and values…how can I accomplish this with OH??

EDIT - I ended up getting this to work using the node-red-contrib-alexa-remote2 nodes.

Will Node-Red also be part of OH3, or will this rule engine not be usable anymore?

1 Like

I’ve only got a tiny part of my test rig transferred, but so far so good…

2 Likes

NodeRED isn’t part of openHAB. It’s installed with openHABian if you use it, but it’s distinct software. NodeRED relies on an openHAB plugin to communicate.

I haven’t tried the current plugin with openHAB 3, but even if it doesn’t work yet I’d be shocked if the developers didn’t update it.

Even if they didn’t, there’s other options, like exposing the items you want to control to MQTT and then connectI’m nodeRED to MQTT.

Thanks. Hoping for the best…

Hello all,
I am running OH 2.5 on Raspberry Pi and for a long time I created my automation in code.
Just installed Node Red and it looks very interesting.

My problem now is that i can’t seem to get the nodes to respond to updates of the items they are connected to…
Couldn’t find any entry in the forum on that subject.

Sorry for pasting the actual code, I’m away from my computer…

So my example is pretty strate forward.
I have a switch item defined in an items file, not connected to any channel (ie a dummy switch) and it’s just visible in basic UI for interaction.
In Node Red i defined the openhab config node and i guess it’s connected correctly because when i added “openhab in” node i could see all my items including the above summy switch.
I connected the first port to a debug msg node, and that’s it.

After hitting “deploy” i can see that the status of the item gets updated (OFF for instance) and the correct message appears on the debug console (“OFF”).

But after that when I change the status of that dummy switch from basic UI (turning it ON) nothing happens in node res and i don’t see the item’s status updated (stays OFF) and obviously i don’t get a new message in thw console.

The same thing happens with other items- when deploying the flow the status is updated but it doesn’t seem to respond to changes after that.

Has anyone encountered this problem?

By the way- in the openhab controller i didn’t enter any username or password. But even when i entered “openhabian” and my password it didn’t change a thing.

Am I missing something?

Thank you guys a lot…

I am no expert, but in OH3, there are API tokens preferred, not username/password.

Do you have both versions of the openHAB node installed? That caused issues for me.

No, i have only one version installed…

node-red-contrib-openhab2
Version 1.1.8

I had after openhab3 migration problems with the openhab2-get node. As @Tobi77 allready mentioned the API token solved the issue.

Just wanted to point out that I’m still running OH 2.5…
So all the OH 3 problems is not yet relevant in my case.
And after few more days of trying, still the same problem- the openahb in node doesn’t respond to updates of my items.

Any ideas? Has anyone faced that kind of behavior?

Thanks…