Node-RED as a rule/script engine for openHAB

I just started to play around with Node Red and have a rookie question.

With my alarmclock in the morning I would like to switch ON my coffee machine.
But only if I am at home.

I have realized this with the following structure, but I assume there must be a much simpler way.

What I do is, I join both to ON/ON and just let this through. I then change ON/ON to ON to switch the coffee machine (Strega).

A short feedback about options to improve (simplify) are greatly appreciated.

2 Likes

You could use an openhab get node triggered by the change of your alarm clock item that gets you presence and than a switch node which evaluates only this. That way you would have two nodes less but any way that works reliably is good :smiley:
Johannes

I know that Scheduling is the holy grail that we all seek, so imagine my delight in finding this node

Now we / I just need to create some kind of way to put it into a GUI


Does anyone have any ideas how we can put the scheduling variables into a UI like this?


Update

I’ve asked Niklas if it would be possible to expose the scheduling part to a NodeRed Dashboard.

2 Likes

Yes great Node , there is an option to set to minutely output , so some things that needs to stay on just get on command each min, if its already on so nothing… very good for some critical house stuff, and provided some good workarounds hhh

1 Like

Hi Johannes,

that’s a good hint (I just started playing around with it).
My expectation would be that the switch returns “ON” only if I use this approach:
grafik

However, it returns the entire message like:
22.6.2019, 07:23:22node: DEBUG 1

msg.payload : Object

{ link: "http://localhost:8080/rest/ite…", state: "ON", editable: false, type: "Switch", name: "Loc_Home_NCO" … }

EDIT:
Got it myself: I needed to put a change node behind it to set the msg “msg.payload” to “msg.payload.state”
:smile:

1 Like

Have a read through this thread, probably the best one on nodered -openhab here on the forum.

Johannes

I am diggin through this as well.
Thanks for sharing!
Even though I just started to use Node red - I already like it a lot.

However, my screen is too smal for complex stuff I assume :wink:

I will see how fast I can replace my text based rules with node red

2 Likes

I ended up using a combination of Jsr233 rules written in Jython and Nodered but I’m still loving Nodered especially for quickly prototyping stuff and how many 3rd party things you can quickly integrate without much setup. You will definitely have fun along the way.
Johannes

1 Like

I try to replace a rule with “channel triggered”.
How can i get the channel direct as an input into node red?

Have a look at this and the discussion in the posts above it:

There is a few different ways to do it

Hi

I think this might be what you’re looking for.

It’s certainly working for me.

If you would like me to post the JSON file for the node, just let me know.

***** update *****

For anyone else looking for an IF Function node that can handle openHAB2 channel triggers, here’s what I use.

Just use the import option to paste it from the clipboard.

[
    {
        "id": "ff5aa376.8b767",
        "type": "function",
        "z": "323c754e.27612a",
        "name": "Lounge Oled Btn 3",
        "func": "var event = msg.payload.event;\nvar channel = msg.payload.channel;\nvar newMsg = { payload: msg.payload.event };\nvar button = \"velbus:vmbgpod:d212bf44:2C: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": 350,
        "y": 120,
        "wires": [
            [
                "dc2adba6.1277f8"
            ],
            [],
            [],
            []
        ],
        "outputLabels": [
            "Whole Msg",
            "Pressed",
            "Long_Pressed",
            "Released"
        ]
    }
]

The essence of this node is…

Match an openHAB2 event to the three states that the channel can be.

Output anything that comes from the channel to output 1

Then the three other outputs get a payload when the state of the channel matches

IE

PRESSED
LONG_PRESSED
RELEASED

Obviously the event trigger and states will need to be changed to suit your application :slight_smile:

Thanks Stuart - I found a way by using the OH event and look for the channel.
It’s so easy!
And my learning curve is very steep :slight_smile:

1 Like

A question came up along the way trying to migrate my rules to node RED:

  1. Is there an option to send a debug node output to a logfile (e.g. openhab.log)?
    I currently use the debug nodes heavily to learn, but they obviously just log with the web interface open.
    So I don’t know how to check logs later on, if something is nor working properly.

Have you seen the “File” nodes in the storage section ?

Hi

This just popped up in an email, I thought you might like to review it.

2 Likes

Thanks. I will check out both suggestions!
:grinning:

I installed the node flogger, stopped node red and started it again.
All my flows are gone!

Is there any way to get them back?

EDIT:
Got them in home/.node-red/flows_Homer.json
:smiley:

1 Like

I’m glad you’ve found some files to restore.

I did a quick search and found this, if I’m reading it correctly, NodeRed saves a backup of the files each time flows are deployed.

Search for the word “deploy” to see what I saw.

flows_*.json & flows_*_cred.json

These define the flows and any credentials stored for the flows. The * indicates that the actual file is named after the machine name you are running on. If you have transferred from another machine name, you might have multiple files though only one set will be active. In addition, there are *.backup versions of these files. Node-RED copies the old active flow/cred files each time you deploy.

Thanks a lot. I will check it out.
I though I need to start from scratch.

There is still a way to go to migrate 6000+ LOC of my rules into nodeRED… :wink:

i was lucky enough to find node red before i started any rules on my setup, i was in the early stages of understanding OH, and then node-red came , and this got me real amped up

from controlling just some MQTT devices ,my entire house is node-red based
i use OH dont get me wrong OH is the best for
,DB, logging , cloud ,site map , for the great REST API, and it is so stable!
but my all logic is there and i love the simplicity

i can tell you i switched my setup many times but with Node somehow its fun! and worth it
if you need help i am here…

also dont forget if it dosent work in OH you can always try the Node red way, it provided me some flexibility, and allot of workarounds !

1 Like