Node-RED nodes for hubitat

I totally understand the local only as I do fear what happens if voiceflow disappears and I want to make a tweak to my skill. Of course then I could learn how to actually program the skill using code. On the other hand it is also possible though much less likely the alexa skill ecosystem could disappear.

In fact there might be a way once all bugs are worked out to trigger Alexa to start listening. Here is how:

  1. build a skill (I did this using voiceflow) with the first action being a choice block (choice blocks are basically Alexa listen for the response)
  2. use the Alexa routine node from node-red-contrib-alexa-remote2 to start the skill
    image
    In this example it is launching the Game Room skill on the tablet named Mike's Fire.

When I did this the first time, I got an Alexa bing and then she listens for my input and processed it according to the skill.

Of course just to be thorough, I thought would also try on my echo. When I did that it basically responded as if I had said Alexa but nothing more. Thus I could give any Alexa command including "open game room testing" or "what time is it" and then she would run the skill. Going back to the tablet as my target, it started acting like the echo and not the way it worked at first.

So I guess either the Alexa routine node has a bug related to launching a skill leading it to work only occasionally or Amazon doesn't want to allow this and blocks it after the first try, or I was hallucinating the 1 time it worked.

The node still seems to work for things like speak or launch routine, but not launch skill.

Has anyone noticed that the Node Red GUI is noticeably slower since 1.13? I moved my Node Red instance onto a Pi 4 8Gb with Berry Boot running off a SSD about the same time so that could be issue related to that to but when I run the benchmark speed tests on this Pi, it is much faster than my Pi 4s running off SD cards. It is not only slower to startup but also slower when opening/exiting a node's Edit Screen. It seems to deploy at the same speed. I have tried from 2 different PCs on my network and speed is same. I just tried to cut a flow w/ ~20 nodes and it took 5-10 seconds before they disappeared so I could paste them somewhere else.

All of my flows are running fast; it's just the GUI.

I can't say that I'm seeing that on mine. GUI still seems to be responsive as before, except for the known lock-up issue related to node groups.

I just tried cutting a sequence with 37 nodes, and it was instant.

Pi4 running off an SD, running the GUI through Chrome on Mac OS.

Care to share your export of that Motion-lighting sub-flow? :slight_smile:

Here ya go @brianwilson .

Motion Lighting Subflow

[{"id":"755ce7c2.ed7d58","type":"subflow","name":"Motion Lighting","info":"","category":"","in":[{"x":220,"y":200,"wires":[{"id":"53adad5e.5d7e34"},{"id":"3365317a.e42a9e"}]}],"out":[{"x":1360,"y":240,"wires":[{"id":"6611dfd1.4fed2","port":0}]}],"env":[{"name":"time_delay_minutes","type":"num","value":"10"}],"color":"#DDAA99","status":{"x":1140,"y":360,"wires":[{"id":"c58a7d82.8e66d","port":2}]}},{"id":"53adad5e.5d7e34","type":"switch","z":"755ce7c2.ed7d58","name":"active","property":"payload.value","propertyType":"msg","rules":[{"t":"eq","v":"active","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":410,"y":200,"wires":[["a0f78e0a.d93b8","9075b96e.cb97a8"]]},{"id":"a0f78e0a.d93b8","type":"change","z":"755ce7c2.ed7d58","name":"stop","rules":[{"t":"set","p":"payload","pt":"msg","to":"stop","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":630,"y":260,"wires":[["c58a7d82.8e66d"]]},{"id":"c58a7d82.8e66d","type":"stoptimer-varidelay","z":"755ce7c2.ed7d58","duration":"time_delay_minutes","durationType":"env","units":"Minute","payloadtype":"num","payloadval":"0","name":"","reporting":"last_minute_seconds","persist":true,"x":940,"y":340,"wires":[["6611dfd1.4fed2"],[],[]]},{"id":"3365317a.e42a9e","type":"switch","z":"755ce7c2.ed7d58","name":"inactive","property":"payload.value","propertyType":"msg","rules":[{"t":"eq","v":"inactive","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":420,"y":340,"wires":[["d8d98b07.496778"]]},{"id":"6611dfd1.4fed2","type":"delay","z":"755ce7c2.ed7d58","name":"","pauseType":"rate","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":true,"x":1190,"y":240,"wires":[[]]},{"id":"9075b96e.cb97a8","type":"change","z":"755ce7c2.ed7d58","name":"","rules":[{"t":"set","p":"command","pt":"msg","to":"on","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":630,"y":180,"wires":[["6611dfd1.4fed2"]]},{"id":"d8d98b07.496778","type":"change","z":"755ce7c2.ed7d58","name":"","rules":[{"t":"set","p":"command","pt":"msg","to":"off","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":630,"y":340,"wires":[["c58a7d82.8e66d"]]}]

2 Likes

How does the status node work (bottom right)?

Also, how would this go with multiple or differing numbers of motion sensors in a room/area? I presume it would need to be modified for >1 motion sensors (specifically the issue I asked about a few weeks ago, and got a satisfactory resolution)

Thanks! Can you pass an environment variable in from the input that would override the sub-flow variable? Never used environment variables.

Yes! The only drawback is it has to be static. I use them a lot in subflows. The other way to do it is by passing a custom msg property.

(apologies on jumping in)

1 Like

The way I have it configured, subflow status shows the countdown of the timer node.

It works with multiple motion sensors as-is if they are the same "type". Meaning, if they all toggle active/inactive with continuous motion it works. If they all stay active the whole time with continuous motion it works. If some of them stay active the whole time, and others don't then it does not work as you then have to check the active/inactive status of all sensors before starting the off timer.

@erktrek Already answered it. You can either configure the subflow node properties and set the variable there. Or you could modify the subflow to use a specific msg property (which would have to be set with a change node, or other before entering the subflow node).

Can anyone think of a way of incorporating this into the motion lighting subflow? It's beyond my paygrade. I use the "AND node", as recommened above. The issue is setting the message topics in the "AND node" for a variable number of motion sensors. The message topic in the "AND node" can only be a string.

No suggestions here. I've never used that and-gate node. Just downloaded it on my dev system, and it is interesting. Can do a few things boolean logic ultimate can't I guess.

Very poorly documented, and hasn't been updated in >3 years. For example, how does it handle value persistence or initialization after reboots/restarts? Who knows? (EDIT: For the record, there is no persistence or initialization. yuck)

Or any way to do it by other means?

I’ve used it a bunch. It’s pretty handy and I find the logic fairly straightforward to understand.

Agree that lack of persistence is annoying. I have an inject node set to reinitialize all my flows on startup.

1 Like

Unless I'm missing something in NR you have a bunch of inject nodes to accomplish that, no?

I'm sure you're probably looking for a way to do this using some native nodes, rather than a function node, but here's the code I use in an Unsafe Function node that forms part of my much more complex subflow. It basically stores the sensors' status in a flow variable, and counts the number of still active sensors each time a new event is parsed.

ps. I use an inject node into the sensor nodes to make sure the subflow gets their current status at startup, since I don't currently use persistent storage for flow variables.

pps. This is a constant work-in-progress, and I'm no javascript guru, so there's probably a lot of room for improvement in this code, but it works well for me as it is.

Process Motion Event
// Output 1 - Active event
// Output 2 - Inactive event

// node.warn("Processing Motion Event");

var motionStatus = null;
var activeCount = 0;

var motionSensors = flow.get("motionSensors");
var automationActive = flow.get("automationActive");

if (typeof motionSensors == "undefined") {
    // node.warn("flow.motionSensors not yet defined. Creating new.");
    var motionSensors = {};
}

if (typeof msg.payload != "undefined" && msg.payload !== null) {
    var deviceId = msg.payload.deviceId;
}


if (typeof deviceId != "undefined") {
    // Receiving a device ID indicates we have received an event, so process it.
    // Note: If we didn't receive an event, the process was triggered by something else (eg. enabling the automation)
    motionStatus = msg.payload.value;

    if (typeof motionSensors[deviceId] == "undefined") {
    	// First time seeing this devie, so add it to the list now
        // node.warn("Device object doesn't exist");
        motionSensors[deviceId] = {};
    }

    var deviceObject = motionSensors[deviceId];

    deviceObject.state = motionStatus;
    deviceObject.displayName = msg.topic;

    flow.set("motionSensors", motionSensors);
    
    // If this is an 'active' event, then pass the msg on now and finish here
    if (motionStatus == 'active' ) {
        // node.warn("New active event received.");
        return [msg, null];
    }
}


for (let [deviceId, values] of Object.entries(motionSensors)) {
    if ( values.state == 'active' ) {
        activeCount++;
    }
}

if (activeCount > 0) {
    // If any of the sensors are still active, proceed as an 'active' event
    // node.warn("Still active.");
    return [msg, null];
} else {
    // If all sensors are now inactive, proceed as an 'inactive' event
    // node.warn("Status: inactive.");
    return [null, msg];
}
1 Like

Correct. Basically an inject node at the beginning of every flow. I really had that already to test things as I created each flow β€” I then just set it to inject after startup also.

Makes sense. I rarely do it that way though. I pretty much always just do it with native nodes.

Nodes in series with a switch to check the value is what I want = AND, parallel nodes=OR.

I probably would use a logic node if I had maybe 5 or more inputs. But for just 2 or 3 I prefer to use raw nodes in series/parallel. Is 100% understandable, and completely self documenting as you can see it explicitly from the flow overview.

But there is always more than one way to skin a cat. :slight_smile: I'm just really into self-documenting flows with as many native nodes as possible.

1 Like

Hi all,

I've started using node-red timidly. I had a workflow that would take the Hubitat Events and log them into a file using the flogger nodes. This stopped working a few days ago. If I hook it up to the /eventsocket WebSocket node instead, it works but not the Hubitat Events node.

The IP, port, AppID (from Makers API) and token are configured.

I am not sure why it stopped working (at 3 am a couple of days ago) but I can't get it to work again. Is there a way to double-check that my Hubitat config node is set up properly? Anywhere to look at, log wise? I tried to connect the Hubitat event node to a debug node and that doesn't show any output either. I am dumbfounded. I connected a device node with the event output connected to debug as well and nothing shows up there either. When configuring it, it lists all the nodes connected to the Makers API so I am guessing the Hubitat config node is fine.

agree with you. I generally to to use native nodes as much as possible (probably less of an issue with node red, but I've certainly bogged down my hubitat hubs this way in the past). I have a number of rooms with 2-3 motion sensors and 2-3 pressure sensors in the furniture - those are the primary places I've used these and/or nodes.