Node-RED nodes for hubitat

Here is the version that doesn't use a device block for the light status at all.

2 Likes

How do I create the equivalent of a "wait until" node that is available with Home Assistant?

Is this what you are looking for?

I'm not sure its similar. The Home Assistant wait node it is a node that imposes a wait (with timeout) until a condition is met.

Can be really useful.

Edit: Here's an example of that utility.

Not sure how I would do that in standard blocks... Usually I would do it in a function node with some code.

Here is a different way of doing it with a function node:

Inside the function, there is the following code:

//in this example I get a presence event and wait that the mode changes to "Day"
//There is a 20 second timeout that this function waits for and then continues even if the mode hasn't changed

if ( (msg.payload.name === 'mode') && (msg.payload.value === "Day") ) {
    var retMsg = context.get('msg');  //get the saved message for the presence event
    context.set('msg', null);  //reset the saved message to null to not cause repeated actions
    return retMsg;
} else {
    context.set('msg', msg); // save the message and start a timeout
    setTimeout(function(){
        var retMsg = context.get('msg');  //get the saved message for the presence event
        context.set('msg', null); //reset the saved message to null to not cause repeated actions
        node.send(retMsg);
    }, 20000);
}

return null;

The timeout in here is 20 seconds (20000 in the setTimeout function).
This approach has a the negative side effect that a mode change would be necessary....

There is another issue with the current plugin that doesn't make this easy to do:
For devices, the msg object only has the "payload" set with the attribute information. However, you have no idea what device it is for. What I would suggest is to have at least the "name" and/or "deviceid" set too. The node has all of the necessary information.

@fblackburn, might I request a change to the device node to include the name and the deviceid in the "sendEvent"? You would have to add the following two lines in the device.js callback
image

2 Likes

That would be handy. I rarely like to use DeviceID, so am not interested in that, but I could remove a number of parallel path functions nodes I've had to use if the "name" were in there.

For instance, on this I could pump both events into a single switch and single function node if I knew where the event came from... Reducing from 2 switches to 1 and 3 function nodes to 1.

2 Likes

Its really nice to see all this activity on the project. Im currently unavailable, but in the next days I will have some time to add your requests and merge PR :slight_smile:

4 Likes

Thanks again for creating this. I had just started down the road of trying to filter webhooks to do everything your pallet can do more easily and more efficiently. Creating the 1st flow for a Pico remote took some learning time but creating other flows for other 7 remotes was quicker than had I done it in RM. Switching to using your nodes in my Vacation Lighting flow significantly simplified it. If you implement @JasonJoel"s suggestion of putting Device Name in the sendEvent, it will get even cleaner.

I have also taken off some of my more complicated RMs into Node Red and am letting HE concentrate on its incl apps and simple Rules.

Thank you again. My HE has never been faster and my number of Node Red flows has increased significantly.

1 Like

Hi @JasonJoel, just out of my curiosity as I'm still learning node-red, what's the config you put for http request? what the url? (just in your implementation of it) do you mind sharing the screenshot?

cheers

For what device exactly? I use a lot of http requests for different devices that have a web interface - stereo receivers, TVs, etc. Obviously the http call is device and manufacturer dependent, though, so there is no 1 answer to that question.

I'm happy to share any of them i have/use, though!

Roku TV are easy, and the http get is just: http://ip address:8060/query/device-info

Yamaha receiver are easy: http://ip address/YamahaExtendedControl/v1/main/getStatus

Pentair pool equipment, when using the node.js pool controller server, are easy:
http://ip address:3000/pump
http://ip address:3000/circuit
http://ip address:3000/temperature

Sony TV are more complicated as it is a POST instead of GET, and the structure is JSON/XML.

1 Like

Ah, I see.
how about for a tasmota plug? I'm having a hard time understanding http request as I would like to get status / get and push commands.

EDITED: maybe if you can please point me to the right direction of an article or tutorial youtube, that'd be much appreciated.

I don't have any Tasmota, so I am not much help there. Sorry!

Can you help with how you would handle (like with rule machine) a cancel on truth change delay in your flow?

I've successfully implemented a delay, but not sure on how to stop that delay if that state changes back.

It all depends on how you did the delay. If using a delay node, you would send a message with msg.reset in it to the delay node. If in a function node in code, you would cancel the setTimeout.

I'm using the delay node. I'm not sure how to send a message to the delay node?

delay

Well, based on whatever condition you want to cancel the delay, put a change block in the path that sets msg.reset to anything, and pipe that into the delay block.

So you would probably end up with two paths into the delay block... One normal and then the other with whatever event/condition that you want to reset/cancel the delay.

1 Like

It's a simple motion lighting flow is what I'm trying to accomplish

If either motion sensor detects motion > turn light on.

Turn light off after no motion from either sensor after 20 seconds unless motion happens again.

You could do it that way, but a lot easier way would be to use a stoptimer node, as it will automatically reset itself every time it gets a new message.

But if you wanted to do it with a delay node, just put a change node coming off of the ON branch of the switch node (or maybe after your "evening" node), going to the input of the delay node.

In the change node make it set msg.reset to anything.

That should work the exact same as using a stoptimer node.

Ahh, I see how that works now. Thanks for the help