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).
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?
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,
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.
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.
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... ).
I sort of take that back. I still don’t know when send events needs to be checked vs not checked.
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.
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.