Instant Stuck with Node Red :) Create Trigger

Hello there,

i am using openhab2 for quite a long time now and works create.
I now tried node-red and have gotten some things to work with the “openhab2 in” node and item changes. So far it works create. The only thing what i can’t figure out to do and not found any help with examples is how to create a basic trigger with no item change.
For example i have some HUE and Homematic switches which are currently controlled by simple scripts like this:

rule “ColorLamp_Fado_Simple”
when
Channel ‘homematic:HG-HM-PB-6-WM55:63b0d0a3:LEQ1059820:3#BUTTON’ triggered SHORT_PRESSED

How can i replicate this with node-red ?
Thanks for any help.

The forum search tool is your friend

You can either do everything inside a function node, or you can use two switch nodes.

You need to filter the channel, then the state

1 Like

Thanks for the answer, but i am actually not much smarter than before. I found some snippets and code before, but probably i just don’t get it. I don’t know what nodes i need to add and configure them.

But I didn’t give you an answer.

I showed you where “some” information could be found.

It only took you 6 minutes to reply, so unless you’re a record breaking speed reader, I’d say that you didn’t

Perhaps there is a chance, i already read that and i wrote i already looked up examples, but didn’t undertsand it how to get it to work with this types of triggers.

What you want for triggers in NR is the event node:
image

However this node is very chatty (if you hook a debug node to it) use a switch node and change the default == to ‘contains’ and put in part of what you want to capture so you can review just the thing/item you are looking to capture.

Ok thanks for the hints.
I now have some more played around and have following:


I got my Openhab Events and and Filter which filters the Button:
image
And another input for the Light Input “State” for the current Brightness:
image

Then on the right side there is an Input and Output node for the On and Off of the Lamp.
In my current thinking i now need a switch which now checks if the brightness is >0 and the switch is trigged then go to the turn of output and vise versa.

But i cannot figure out, how to “combine” these payloads to one payload for the switch to actually decide what way to go.

When i Chance my light status manually the payload of the “Lamp_Esstisch_Brightness” is:
image

And if i press the Button the payload looks like this:
image

But the actually deciding part i am struggeling with.

Okay, you’ve moved on quickly with that one.

Try dropping an openHAB2-get node between function and the switch.

Then set the switch to compare msg.payload.state which will contain the value for the brightness (or whatever state the item has)

( FYI, all the Previous payload, as it was before it hit the Get node, is moved to msg.payload_in )

[
    {
        "id": "a2f09dd.58e4b6",
        "type": "function",
        "z": "d055bce9.0a808",
        "name": "",
        "func": "\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "x": 540,
        "y": 520,
        "wires": [
            [
                "79deec4d.6ec694"
            ]
        ]
    },
    {
        "id": "79deec4d.6ec694",
        "type": "openhab2-get",
        "z": "d055bce9.0a808",
        "name": "",
        "controller": "",
        "itemname": "",
        "x": 740,
        "y": 520,
        "wires": [
            [
                "8be75d4f.ec97e"
            ]
        ]
    },
    {
        "id": "8be75d4f.ec97e",
        "type": "switch",
        "z": "d055bce9.0a808",
        "name": "State of brightness",
        "property": "payload.state",
        "propertyType": "msg",
        "rules": [
            {
                "t": "gt",
                "v": "0",
                "vt": "num"
            },
            {
                "t": "eq",
                "v": "0",
                "vt": "num"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 2,
        "x": 970,
        "y": 520,
        "wires": [
            [
                "ad9ff65c.1bffd8",
                "6eaf08e.eeec9f8"
            ],
            [
                "663f5db.07179a4",
                "88d9a911.187e58"
            ]
        ]
    },
    {
        "id": "ad9ff65c.1bffd8",
        "type": "openhab2-out",
        "z": "d055bce9.0a808",
        "name": "",
        "controller": "",
        "itemname": "",
        "topic": "",
        "payload": "",
        "x": 1270,
        "y": 400,
        "wires": [
            []
        ]
    },
    {
        "id": "6eaf08e.eeec9f8",
        "type": "openhab2-out",
        "z": "d055bce9.0a808",
        "name": "",
        "controller": "",
        "itemname": "",
        "topic": "",
        "payload": "",
        "x": 1280,
        "y": 440,
        "wires": [
            []
        ]
    },
    {
        "id": "663f5db.07179a4",
        "type": "openhab2-out",
        "z": "d055bce9.0a808",
        "name": "",
        "controller": "",
        "itemname": "",
        "topic": "",
        "payload": "",
        "x": 1280,
        "y": 600,
        "wires": [
            []
        ]
    },
    {
        "id": "88d9a911.187e58",
        "type": "openhab2-out",
        "z": "d055bce9.0a808",
        "name": "",
        "controller": "",
        "itemname": "",
        "topic": "",
        "payload": "",
        "x": 1280,
        "y": 640,
        "wires": [
            []
        ]
    },
    {
        "id": "cebcafa8.dd76f",
        "type": "comment",
        "z": "d055bce9.0a808",
        "name": "If brightness is >0",
        "info": "",
        "x": 1260,
        "y": 340,
        "wires": []
    },
    {
        "id": "8f1a739d.a8492",
        "type": "comment",
        "z": "d055bce9.0a808",
        "name": "If brightness is == 0",
        "info": "",
        "x": 1270,
        "y": 560,
        "wires": []
    },
    {
        "id": "611fd2b9.46262c",
        "type": "openhab2-events",
        "z": "d055bce9.0a808",
        "name": "",
        "controller": "",
        "itemname": "",
        "x": 330,
        "y": 520,
        "wires": [
            [
                "a2f09dd.58e4b6"
            ]
        ]
    }
]

Yeah, it just spits out everything from openHAB2.

Except Group states, which is really odd

:man_facepalming: Well, thats genius. I am struggeling with comparising and i not really need it :slight_smile: I will test this later on and message back, right now i am on the goy. But thanks a lot for the brain-knot-removal.

1 Like

What a great phrase.

I can see that being used a number of times

1 Like

I designed my NR to leverage flow/global vars; I have a dedicated tab and just have OH-in node and then use the switch nodes and change to a flow or global object. Not that this is a better way than what is proposed, just another way to think about capturing data for comparison purposes.

There’s always a “different” way of doing things, who’s to say what is right and what is wrong?

Hello there and first of all again thanks for all your input and “brain-opener”.
I now figered it out and just for “inspiration” thats the way i did it:

.

I filter my buttons in 2 steps. First all of my Openhab Events to a Button and then the type of presses. I now can just copy paste the button construct and change one value in the button filter according to the button.

1 Like

Fyi

By increasing the amount of outputs from a function node, you could merge your group of function nodes.

Simply by using this in the return lines

return [msg, null, null, null]

Or

return [null, msg, null, null]

And so on.

It’s also possible to send batches of messages from each output, but that’s for a different topic

But again, all this info is in that other topic

If anyone is remotely interested, I’ve worked out how to detect Group states in Node-RED

This flow shows how, it’s just a matter of filtering the outpout of the openHAB events node topic to show the StateChange you are looking for.

In this case, it is smarthome/items/All_House_Heat_Mode/statechanged

[
    {
        "id": "d5055179.819f6",
        "type": "debug",
        "z": "7ff00033.a4e8c",
        "name": "msg.payload.value",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": true,
        "complete": "true",
        "targetType": "full",
        "statusVal": "payload.value",
        "statusType": "auto",
        "x": 930,
        "y": 60,
        "wires": []
    },
    {
        "id": "4860f60.e48d40c",
        "type": "switch",
        "z": "7ff00033.a4e8c",
        "name": "All House Heat Mode",
        "property": "topic",
        "propertyType": "msg",
        "rules": [
            {
                "t": "eq",
                "v": "smarthome/items/All_House_Heat_Mode/statechanged",
                "vt": "str"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 1,
        "x": 730,
        "y": 60,
        "wires": [
            [
                "d5055179.819f6"
            ]
        ]
    },
    {
        "id": "1ee4be23.b7e282",
        "type": "openhab2-events",
        "z": "7ff00033.a4e8c",
        "name": "openHAB Home",
        "controller": "67ebb539.d211ec",
        "itemname": "",
        "x": 80,
        "y": 40,
        "wires": [
            [
                "1f9ec9bd.2745b6",
                "a24cc3e.3a4e44",
                "baa5c7f.20a0a38",
                "4860f60.e48d40c"
            ]
        ]
    }
]
2 Likes