Node-RED nodes for hubitat

@fblackburn

I'm not sure how examples are added into the node code base, but I would be happy to add some more examples if given a pointer or two.

I can think of a few that would cover most of the questions we see in here.

  1. Generic Sensor to Change node to command node
  2. Overriding command node parameters via incoming msgs
  3. Event node use for bulk attribute collection/use
    etc
  4. Filtering values from device node
  5. Probably something on HSM or MODE. I don't use either of this in Hubitat, but know enough to make an exmaple.
  6. Re-triggering flows on Node-RED or Hubitat system startup
3 Likes

Sure it would be appreciated !! :pray:

Export your flow, drop in the examples directory and voila :slight_smile:

Or you can send my your flow, I'll add it and standardize examples between them (use same config node, indent json to be readable)

Note:

  • the file name will be the name exposed in NR
  • Try to avoid depends with other libraries
1 Like

I'll start working on it today. Thanks!

4 Likes

This is a question mostly about general node-red programming best practices so it might be best asked over in their forum, but there's a lot of talent here and I'd love to learn from all of you too.

I've been using node-red now for a couple months and really like it for fairly simple, mostly linear tasks. When I've tried to use it for problems that involve loops it seems to get fairly unwieldy pretty quickly though. I want to believe there is a good way to handle loop problems (probably involving trigger and rbe? Maybe a contributed node I don't know about) and I just need to get it in my mental toolbox.

Here's an example of what I'd like to be able to do. I have an air conditioner that has an IR remote to control it. I'm using a BroadLink RM Mini 3 to send IR commands from node-red, but sometimes the IR command needs to be sent a few times before it works correctly. I've got a power monitoring switch on the A/C appliance but I want the regular remote to work at all times so I don't want to power it off - just read it's power consumption and use the IR remote capabilities to turn it off (really a stand-by mode).

In pseudocode, I'd like to do the following:

powerLevel = getCurrentPower()
count = 0

while (count < 10) AND (powerLevel > offPowerLevel) {
    sendIROff()
    wait(settleTime)
    powerLevel = getCurrentPower()
    count++
}

Implementing a loop like this in NR seems fiendishly complicated, I have to assume I'm missing something. Anyone know of any good examples for doing this type of thing? Or have other pointers?

Can use a function block if you like writing code or the "do-red" palette. I think "do-red" is probably the most popular node set in use for loops.

There are others, though, like:
node-red-contrib-loop-processing
node-red-contrib-actionflows
node-red-contrib-repeat

I used to use node-red-contrib-repeat a lot, but pretty much only do it brute force or use do-red now.

Or here is an example I worked up for someone a long time ago with BOTH do-red and repeat. :slight_smile:

1 Like

To do your example with "do-red" would look something like this. I just mocked this up real fast:

Continue = Do the task over again
Done = Move on to next step (as there is only 1 step in this example, it goes to the exit)

Whether you think that is burdensome or not is up to you. :slight_smile:

Or... You could do exactly 10 tasks in "do-red" and abort if the value becomes correct like this:

2 Likes

Perfect!!! This is exactly what I needed to unblock my brain. There's so much power in the palettes I haven't discovered yet. I'm off to spend some time exploring do-red. And node-red-contrib-repeat too,

Thank you for putting the time into this for me!

1 Like

I do something similar with the "do" node (like @JasonJoel) . You could have done this in a function node, but because it looks "getCurrentPower" is the current reading from a device, you would have to use a device node to get that. Below is my flow - when the door is unlocked, it starts a counter, loops through checking the status of the lock. This is repeated 20 times (unless the door is locked in the meantime) and then sends a message.

Hope this helps

1 Like

If you want to keep it very simple - here is an example with just the basic nodes...

Edit - stick a device node in the loop somewhere and test the result with a switch node and get out if you want. Easy Peasy.

2 Likes

Yep, working with HE and other device nodes in the loop makes it tricky with a function - that was my first route of attack.

I think do-red is the missing link in my problem solving skills.

2 Likes

Thanks for answering this. I've had dupe events forever and now I know why.

2 Likes

I'll send one to you tonight for you to review before I make a bunch more. I can't upload it to github as I don't have push rights to the repository.

Couldn't you fork it and then do a PR?

1 Like

Probably. I suck at git. I'll look into it.

EDIT: I forked it a while back. Need to refresh it I guess and then do the PR. Need to learn how to use github better anyway.

1 Like

Github desktop app is probably the easiest way to start, then you can expand to CLI or integrating into your IDE or text editor.

Yeah, I use github desktop. I still seem to get squirrely commits/changes in there somehow that I don't understand and then have to reconcile. But I'm a hack. :stuck_out_tongue:

I made a PR for @fblackburn for the new file. Hopefully I didn't PR a bunch of other things too on accident (I see my pull commits on there from my forked repository... :confused: ).

1 Like

I sort of take that back. I still don’t know when send events needs to be checked vs not checked. :slight_smile:

if goodnight switch is on do x doesn’t work unless send events is checked. Shouldn’t my pico remote toggle it on hubitat and then node red see the event change without send events?

You can do this a couple of ways, you could have the pico remote buttons directly in NR sending events, or you can have pico remote buttons turning things on with HE, then have those things you just turned on in NR sending events. At the end of the day, you still need a trigger event and, in most cases, in terms of NR and HE, that "Send Events" option is the trigger event.

Take for instance my motion lighting sequence. My motion sensors are sending events so that they act as triggers for the lights, but I also have a motion detection switch that when turned ON sends an event into the motion sensors to "poll" their state so that if they are active, the lights get turned on, but if inactive nothing changes.

Motion Lighting Sequence

This is my den Pico.. the middle button checks the device (send events is off) and toggles it based on the results.. I put the toggle check in a subflow but it's a simple switch etc.

Also for more fun.. you can trap double/triple clicks with the timed-counter node..

2 Likes

Think of "send events" as a trigger in Hubitat terminology.
Think of unchecked "send events" as a condition in Hubitat terminology.

5 Likes