Openhab and node-red

Ok…:+1:

Now i added all my 19 rollershutters and it seems to work well.
Spezial thanks to @crxporter and @gozilla01 for their immidiate support.

Please let that post open for concerned questions :wink:

:+1:

@crxporter Hi Garrett,
what is this part in your function for:
var delay = {payload:0};
Could you please explain the need of this variable to me?

That line creates a variable in my nodered functions that will be sent to the delay timer. I use it in both of my curtain functions.

The first is:

var input = msg.payload;
var delay = {payload:0};
if(input < 101){
    msg.payload = {
        "TargetPosition": input
    };
    delay.payload = {
        "CurrentPosition": input
    };
    return [msg,delay];
}

In this one the line you asked about just creates a dummy variable. Later on I update the variable with the input (which is from openhab). Then I finally have return[msg,delay]; which sends “msg” right to homekit and “delay” to my delay timer.

For the other function we have:

var t = context.get('t')||0;
var delay = {payload:0}
if(msg.payload.TargetPosition){
    t = msg.payload.TargetPosition;
    context.set('t',t);
    msg.payload=t
}
if(msg.payload.TargetPosition === 0){
    t = msg.payload.TargetPosition;
    context.set('t',t);
    msg.payload=t
}
if (msg.hap.context !== undefined){
    delay.payload = {
        "CurrentPosition": t
    };
    return [msg,delay]
}

There’s more going on here. It’s looking for “target position” messages from homekit. I could probably make the code a little simpler but this works so I haven’t bothered! Anyway, the delay does the same thing. Create the dummy variable, update it with whatever position is being sent to openhab, and send that position back through my delay timer to later update the homekit “current position”.

HomeKit window/curtain looks for two messages: target position and current position. If the most recent target is different from the most recent current - that’s when your homekit will show either “opening” or “closing”.

Anyway, long answer and way too much information - the line you asked for creates the dummy variable placeholder that I send to my delay timer.

I’m actually looking now and I see that the delay variable is probably unnecessary. I’ll be thinking about it today… I noticed it’s always going to be exactly the same as the msg - so why couldn’t we just send the msg to the delay timer?

I’m out of town though and can’t test it till I get home this weekend. Try it and let me know!

i´m completly new in node. so i have to learn a lot to understand, whats going on here. Do you know some tutorials where i could learn to understand the functions?

The nodered docs are actually quite good. I picked up a lot of my function programming there (especially the context and global variables).

Outside of that the “function” node is simply a javascript function.

You’re probably past “getting started” so I’d go right to “user guide” here:

https://nodered.org/docs/

1 Like

Hi,
just want to thank you guys; I loved node-red so much - i migrated everything to it. It’s really good. And it’s fun.

My latest Fun-Part was using the RedBot to have a chatbot with telegram implementet to switch things:

The little Invert-Function is missing in the openhab-node-red standard (ON <-> OFF; UP<->DOWN). But nothing complicated there:
if(msg.payload.state==‘ON’){
msg.payload=‘OFF’
}
else{
msg.payload=‘ON’
}
return msg;

Some advice to the redbot: Only deploy Full. There is a Bug in partial deploys.

1 Like

yes i love the redbot-nodered-openhab comination. I have quite an expansive chatbot by now. Especially beeing able to use rivescript makes it alot better than other chatbot nodes. I have flow to controll all my switchable items with natural names and one alias per item. But i use the MQTT2 publish trigger for connecting it to openhab.


The link nodes go to the Telegram receiver/sender nodes but all the magic is in the function node:

Each line in the array is for one Item and its aliases. This in combination with iOS text replacement makes a really nice way to trigger scenes as I have a three later acronym saved for each scene.
I havent encountered any bugs with a partial deploy.

Looks great.
Does this mean you can write Telegram messages (e.g. from cell phone) to OH to trigger something?

Yes that is possible either from nodered if you are already using it for your automation or if you are using the built in possibilities like rules DSL or Jsr233 you could have a look here:


Johannes

Thanks for sharing Johannes.
I will play around with it and might come back with questions.

what exactly have you changed, I’m having the same issues.

or is the answer somewhere in this topic? because then I’ve must have mist it

Hi All,

I have some zigbee devices which do not have channels for some actions but are sending events.
i would like to catch these events in nodered. For that the openhab events node seems to be the right one, but have not much idea how to filter to the specific events.
Can someone help, please?
Thanks in advance

Yes you may try this. I am doing it as well for some long/short press events.
I did it by using the ‘filter’ node, which can filter out the right message for you. But you need to find the right naming to filter it.

  1. use the events node and place debug behind it
  2. start debug, trigger the event, and fast stop the debug node.
  3. find the right event and copy that name

For me the event was called: smarthome/channels/mihome:sensor_switch:xxxxxxxx:button/triggered

Afterwards I used the switch node to direct it into the right path.

image

Hi

That’s a really good way of doing that.

Can you export the filter and Switch nodes and paste then here?

I’d love to see how you’ve set that up.

(Currently, I use a function node to filter the traffic, but your solution seems a lot easier)

Cheers,

Stuart

@lampy many thanks for confirming that I am on the right track.
It seems like I can e only 50% successful as if I am not wrong it could only work if the thing has a channel. Unfortunately the IKEA symfonisk remote has only a dimmer channel so capturing the knob event will be not possible

I am not sure, I do catch also the events of the Fibaro dimmers with setup. In that case the filter text is smarthome/items/ZWaveNode015LivingroomCenter_SceneNumber/state.

I would say, just try the debug item, try if you can find something related to you handling.

Yes no problem:

   [{"id":"162e9146.8f096f","type":"switch","z":"7a84deb3.0e4318","name":"Filter Button","property":"topic","propertyType":"msg","rules":[{"t":"eq","v":"smarthome/channels/mihome:sensor_switch:xxxxx:button/triggered","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":339.9500427246094,"y":855.9499359130859,"wires":[["fcefb49e.71f84"]]},{"id":"fcefb49e.71f84","type":"switch","z":"7a84deb3.0e4318","name":"1=short ; 2=long ; 3=double","property":"payload.event","propertyType":"msg","rules":[{"t":"eq","v":"SHORT_PRESSED","vt":"str"},{"t":"eq","v":"LONG_PRESSED","vt":"str"},{"t":"eq","v":"DOUBLE_PRESSED","vt":"str"}],"checkall":"true","repair":false,"outputs":3,"x":552.9500427246094,"y":854.6165618896484,"wires":[["2662deb4.8ddd4a"],["c7e1c2c9.731ee8"],["c818fbba.ec684"]]}]
2 Likes

That’s very kind of you.

Thank you