Node-RED nodes for hubitat

You can pass device ID, command, and arguments to a Command node, and could use a change or function node within the subflow to set the appropriate message parts based on a global variable. Unfortunately I don't think the same is true for a device node.

Edit: I wrote the above from my phone before checking Node Red. You can set the deviceId and attribute in the input to a Device node, so if I understand what you're trying to do, you can already do it with the existing nodes. In the sub-flow just set the values from your variables and pass them to a Device or Command node that only has the server selected.

Change Node to set message parts from global variables:

Hubitat Device node with no pre-set device or attribute:

image

Test flow

I set the deviceId to 1 and the attribute to "presence" and get this from the debug node:

image

I use this method in some flows that capture the state of a RGB bulb and then later restore it. The capture is done by a function node that stores the attributes of the bulb to flow variables. I have a single Command node in the flow to do the restore function. It gets the deviceId, command, and arguments from the incoming messages.

2 Likes

Thank you so much for opening my eyes!
Not only the nodes themselves already supported what I needed, but there was also a full documentation inside Node-RED itself, brilliant work from @fblackburn which I totally missed :sweat_smile:

I was able to achieve what I wanted and I'm very happy with the result!

The "AC / Floor" subflow has all the logic in it and it's reused for each room / thermostat.

I'd love to have done this with a single triggering node, but it needs to go through the logic if either the mode or the temperature is changed in the thermostat.

Anyway, it now looks clean an tidy :grin:

3 Likes

Except the node vertical spacing that stomps over the status text. :wink:

Just teasing. Glad you got it to do what you needed!

4 Likes

Can anyone confirm that HSM status node is correctly tracking HSM status.

In my system for some reason HSM status nodes is only showing the current status of HSM when the node is added/deployed to a flow. And does not output status when hsm mode changes.

It was working correctly in my system for months/years but just noticed this not working today. running 1.10.1 and just updating to last HE platform.

All three can't be correct??? Each node was added when hsm was in the mode shown
image

Is the "Send Event" box checked on the HSM node? If that is not checked, then nothing will be published when the state changes, but if you query the node, it will return the current status.

2 Likes

Yes it is checked, I was aware of that issue/feature. Besides the blue dot below the node would be hollowed out if the "Send Events" was NOT checked. Left is checked, right is not checked.

These are flows that have been in use for several years.

image

I can change the HSM mode with "Set HSM" node, so that works correctly, the hsm status node does not update or emit changes to hsm status. It only reflects the hsm state when the node is added/deployed.

Interesting.. I don't use HSM, but could you see if any event is generated via the Events node when HSM changes? I believe it should publish a location event. Also, do you see anything in logs -> location events?

No HSM events are generated in the events node but HSM changes are in both the live logs and location events.

I do get other events (temp, humidity, contact, switch) from the events node, so that appears to be working properly.

Can you check your webhook configuration for MakerAPI and confirm if "Post Location Events" is enabled? That's about the only thing I can think of now.

2 Likes

Bingo! That was it. Much appreciated. I migrated from my original C4 to C8Pro back in Jan-Feb. So I missed 1 thing out of 200 :confused:

2 Likes

Question: I am in the process of upgrading my Node-RED built in dashboard to Dashboard 2.0 in a test environment. I have some device nodes that connect to HE just to get device status (battery level, current state etc.) but don't actively interact with the devices. Can I configure my HE node to point to my live instance of HE and leave the "webhook" configuration blank?

Thanks for your help

UPDATE: Just tried it and it worked. What I was missing in the "test" instance was the configuration of the token.

1 Like

@fblackburn - Hopefully you don't mind me posting this here, but I figure most of the Node Red users around here are following this thread.

I use a mix of RM and NR for my automations, and find myself relying on NR for more and more things. I use the built-in trigger node for lots of things. It's kind of a Swiss Army knife that can debounce triggers and handle delay timers among other things. The other day I had to reboot my primary Node Red's host machine, and I did it right around sunset when some delayed actions were pending. As a result a bunch of lights that should come on around sunset didn't automatically turn on.

That got me thinking, and with the help (and hindrance!) of 3 different AI LLMs, I created a new node called persisted-trigger. It is designed to have all the capabilities of the stock trigger with one major enhancement - this node will store pending messages so they can survive a reboot or a restart of Node Red. You have to have persistent context storage set up (A guide to understanding 'Persistent Context' - General - Node-RED Forum), but that is a good thing to have for Node Red in general if you want your flow and global variables to survive restarts.

The way the persisted-trigger works, if the original timer expiration is still in the future when NR restarts, the message will be acted on at that time. If the original time has passed, the user can opt to discard the message, forward the message, or forward the message 'flagged'. The flagged option adds msg.expired=true and msg.triggerOriginalExpiry={unix timestamp} to the msg object so you can have downstream nodes conditionally act on messages that expired or that expired a certain time ago.

You can install it directly from the Node Red palette, just search for 'persisted'. Make sure it is showing version 1.0.2.

The node is here on GitHub: GitHub - youzer-name/node-red-contrib-persisted-trigger: Trigger node with persistence across Node Red restarts and here on npm: node-red-contrib-persisted-trigger - npm.

I've done some testing, but I probably didn't hit every possible combination of settings you could configure, so if you find any issues (or have enhancement requests), please post those to GitHub. I only use the 'default' context store which is set up to persist in localfilesystem, so if anyone is using multiple context stores, please verify it works with non-default stores.

You'll notice that the node shows 2 outputs, while the built-in trigger only shows the second output when it's been enabled. The LLMs couldn't make the dynamic outputs work and kept breaking other things while trying, so I cut my losses and went with the always-visible second output.

It was incredibly frustrating trying to get ChatGPT to make changes to the code without introducing regressions. There were a few 'one step forward, 4 steps back' moments, and I had to feed it back code it had written earlier to help it figure out how to undo some of the regressions. By the end I was only letting it give me line-item edits that I added to the code myself to avoid it deciding to break something totally unrelated to whatever change I was asking it to do.

I hope others find this useful.

1 Like

After dipping my feet in the node-building pool, I decided to try building nodes to add new capabilities to the Node-RED nodes for hubitat. I've sent these up to @fblackburn as a pull request on GitHub, but I thought I'd put a post here to see what others think. My fork of the project is here: GitHub - youzer-name/node-red-contrib-hubitat: Fork to add new functionality. I haven't done anything with the README.md yet, so it doesn't mention these new nodes as of the time I'm writing this.

I started off with a node to act as a logic gate for multiple Hubitat switches, called 'hubitat switch logic'. Later I built a more flexible version of the logic gate that can handle switches, motion sensors, contact sensors, presence sensors, and locks, called just 'hubitat logic'. (There really is no need at this point for the switch-logic node, since the logic node can handle switches and has some other tweaks added)

The logic node can operate on one type of device at a time, but multiple devices of that type. You can select a device type, one or more devices, the mode ('all' or 'any') and the target value (on or off for switches, active or inactive for motion, etc). It evaluates the selection as either true or false. It can either act as a gate where messages only pass through when the state is true, or you can select 'Send Events' where it will act as a trigger and send a message when the state turns true.

Just as one example of where I'm using this, I have a flow that triggers when any of 3 door contacts opens. That used to look like this:

image

It had one device node for each door with 'Send Events' selected, plus a switch to only pass 'open' messages. Now that is a single node with 'any' and 'open' selected.

image

The two do operate slightly differently, as the original will trigger every time any door goes from closed to open, and my logic gate trigger will only trigger when the whole group goes from 'all closed' to 'at least one open'. For the purpose of my flow that works just as well.

As another example, this snippet checks three lights to see if any are on. The message passes to the junction node at the first 'on' device:

image

That is now this:

image

The node status message works like the other Hubitat nodes where a solid icon (gray for false, green for true) means it will send events, and an icon with a white dot in the center means it will not send events. The node shows the last time the true/false state changed. All three nodes append the number of selected devices to the node name and update that as you add/remove selected devices.

The logic node can be useful even with only a single device selected, as I usually had a device node followed by a switch to only pass one state (only on, only present, only active, etc). In each of those cases I can now remove the device and switch nodes and replace with a single logic node. As a bonus the logic node shows me the current status of the gate.

The second thing I added was 'capture' and 'restore' nodes that work like the capture and restore function in Hubitat. They can handle switches, dimmers, and RGBW bulbs in either CT or RGB mode. Each capture node can capture one or more devices of any of those types, and the restore node can restore one or more devices that have been captured.

I'm using the capture and restore nodes in some flows where I previously used a combination of 'hubitat device' nodes, function nodes, and 'hubitat command' nodes to do the capturing and restoring. These nodes do it with many fewer nodes on the flow.

Here's one example. This flow snippet captures 3 bulbs, turns on a Room Lighting activator to turn them on in CT mode, then resets them to their former state after a 5 minute delay. It used to look like this:

I had to pass the message through 3 device nodes, 3 copies of my capture function, and use change nodes to send three separate messages to my restore function. Now it looks like this:

image

I have a few rules still running on my hub where there were just too many devices to try replicating them in Node Red. I'm going to give that a try now and see how things go. The restore node might need some throttling if the hub can't handle the restore commands all at once for a large number of devices.

If anyone wants to try these out you can add them to Node Red by dropping the HTML and JS files from the fork into your node_modules folder in Node Red, adding the JS files to package.json file, and restarting Node Red. If you do that, please test them and make sure they're working as expected. I've already deployed 62 logic nodes and a couple of capture/restore nodes in my flows and so far everything seems to be working well.

4 Likes

How does this work? Is the captured state stored to disk? Or memory? Can the state be made available as variables?

Thanks!

The captured state is stored to the Node Red flow context storage. If you've configured it to save the context to disk (see my previous post about persisted storage), then it is saved to disk. Otherwise it is only in memory.

You can view the context data from the hamburger menu at the top right:

image

Expand "Flow" and click the refresh button to load:

image

Here I've captured 3 bulbs. I expanded the first one to show the stored data:

These can be accessed like any other flow variables while they exist*

image

* the captured states are removed when the device is restored or if the capture node is edited or deleted

I just realized I didn't make this compatible with multiple hubs. If you have more than one hub connected to Node Red (as I do), the device IDs could overlap. I'll work on that tomorrow. Need to add some sort of hub identifier to the name of the flow variable.

1 Like

@aaiyar - Your questions made me think of a few other things that could be improved.

There was a cleanup process on every edit of the capture node to make sure stored states weren't orphaned when adding or removing devices from the list. That meant that while the data was written to persistent storage, it still got deleted by the cleanup on any edit of the node or restart of the flow. I added a checkbox where the user can select whether to clear the stored data on each edit/restart. If that box is unchecked, which is the default state, the captured devices will persist across edits and restarts.

I also changed the name of the flow data to include the hub name, taken from the config node, so there are no issues with capture/restore from multiple hubs. This was captured from the a hub named "C8" in the config editor:

image

If the user didn't enter a hub name, it uses the hostname or IP: This was captured from a hub at 192.168.0.9 with no name in the config:

image

I also added the variable name to the output of the capture node, so it emits an array containing the name, deviceId, and variable name for each device that got captured:

image

If you wanted to access the stored data outside of the restore node, you could pick up the variable names from there.

Is anyone testing Node-RED v5 beta? If so, any issues with the HE nodes? I believe the next release may be the "official" one, so wanted to check (not that I am in a hurry to upgrade - still dealing with the fallout from Dashboard 2.0🤦🏻‍♂️)

1 Like

I just updated to beta 6 this morning. I'm not seeing any Hubitat node issues. 'cast-v2' isn't working for me at this time. I have not done much troubleshooting.

3 Likes