Node-RED nodes for hubitat

Apologies for blathering on.. if you reverse the switch logic you can also do this (with global var as shown or an array in jsonata etc)...

edit: I like this way a bit better...

2 Likes

Thanks for the help. ̶T̶h̶i̶s̶ ̶s̶e̶e̶m̶s̶ ̶t̶o̶ ̶w̶o̶r̶k̶.̶ ̶

Removed, as not working.

What if you add some logic that sets/adds to a global array based on the events node and "presence". You could then test against it like my last post with no hard-coding needed.... or am I missing something.. :thinking:

Sorry, I not sure what you are referring. Also, the above didnt work. Nothing got through, just not the devices I was trying to stop reaching the table.

Put the jsonata expression in the "..property" field as an array..

["857","923",....]

then test using "contains" payload.deviceid

To "not" the condition just add an "otherwise".. also is deviceid numeric? if so lose the quotes.

edit: from another thread about providing solutions to problems I hope I am reading what you want to do correctly and not wasting your time. Apologies if so. Still a little bleary this (us/east coast) morning.

1 Like

That just blew my mind. I had no idea you could put JSONata in all three of those dropboxes above. I only thought it was the last dropdown box. 20 mins ago I discovered the JSONata option where the "contains" is in your picture. Just now you pointed out the first!

Currently testing. Thanks!

1 Like

Lots of ways to do it.

I would just do a switch looking at property msg.payload.deviceId with "Matches regex" and do 111|123 as the regex string, where 111 and 123 are deviceIds you are looking for - keep adding more |xxx for more Ids.

I just tested this, seems to work as expected.

@erktrek idea to put it in a re-usable variable is a pretty smart idea too.

2 Likes

Attach a mouse to the iPad and the right click will allow you to drag select nodes. IMO the ability to use a mouse or touchpad in iOS 13 is one of the great iPad productivity enhancers.

1 Like

Pretty sure you just long touch to enable lasso/multi select mode on node-red in android and ipad.

I had a flow : when the switch is On/Off ( or contact : open/closed ) then send to my phone a notification : ... was on ( open ) 10 minutes , ... was on ( open ) 20 minutes ...

On Node RED :

1/ How to write a expression :

A1 = 0, delay 10 minutes
A1 = A1 + 10, delay 10 minutes
A1 = A1 + 10 ....

2/ Send Notification : " Switch ( contact ) was on ( open ) {A1} minutes "
Thanks.

I don't know if this will help but here is my subflow with email that sends multiple left "opened" alert messages. You set the properties of the subflow when you add it to your sequence..

Open for X Seconds with Alert

[{"id":"5a92cf26.eafdc","type":"subflow","name":"Open for X Seconds with Alert","info":"","category":"","in":[{"x":60,"y":40,"wires":[{"id":"f10f9937.329328"}]}],"out":[{"x":1620,"y":240,"wires":[{"id":"f2aea4a8.c48848","port":0}]},{"x":1620,"y":300,"wires":[{"id":"997593fc.7b90b","port":0}]},{"x":1620,"y":360,"wires":[{"id":"3f80ff5a.11667","port":0}]}],"env":[{"name":"DELAY","type":"num","value":"300"},{"name":"LABEL","type":"str","value":"DEVICE"},{"name":"MAXALERTS","type":"num","value":"5"},{"name":"ALERTIMMEDIATELY","type":"bool","value":"false"}],"color":"#DDAA99","outputLabels":["In Progress","Gave Up","Resolved"]},{"id":"1bd998dc.a36f27","type":"change","z":"5a92cf26.eafdc","name":"flow.action = open/closed","rules":[{"t":"set","p":"action","pt":"flow","to":"payload.value = \"unlocked\" or payload.value = \"on\" or payload.value = \"wet\" ? \"open\" : \t( payload.value = \"locked\" or payload.value = \"off\" or payload.value = \"dry\" ? \"closed\" : payload.value)\t","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":510,"y":100,"wires":[["11c52b3c.363f65"]]},{"id":"1dbc857d.b721cb","type":"stoptimer-varidelay","z":"5a92cf26.eafdc","duration":"DELAY","durationType":"env","units":"Second","payloadtype":"str","payloadval":"timed out","name":"","x":1460,"y":40,"wires":[[],["31c53733.93a678"],[]]},{"id":"edbda1d7.c3c0e","type":"switch","z":"5a92cf26.eafdc","name":"open/closed","property":"action","propertyType":"flow","rules":[{"t":"eq","v":"open","vt":"str"},{"t":"eq","v":"closed","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":1030,"y":40,"wires":[["1dbc857d.b721cb"],["8723dcee.bddd1"]]},{"id":"8723dcee.bddd1","type":"change","z":"5a92cf26.eafdc","name":"stop timer","rules":[{"t":"set","p":"payload","pt":"msg","to":"stop","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1240,"y":80,"wires":[["1dbc857d.b721cb"]]},{"id":"f10f9937.329328","type":"switch","z":"5a92cf26.eafdc","name":"flow.count does not exist","property":"count","propertyType":"flow","rules":[{"t":"null"},{"t":"nnull"}],"checkall":"true","repair":false,"outputs":2,"x":230,"y":40,"wires":[["70f9a00e.3ac45"],["8de438fe.118078"]]},{"id":"70f9a00e.3ac45","type":"change","z":"5a92cf26.eafdc","name":"flow.count = 0","rules":[{"t":"set","p":"count","pt":"flow","to":"0","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":480,"y":40,"wires":[["8de438fe.118078"]]},{"id":"b95823b1.03341","type":"change","z":"5a92cf26.eafdc","name":"inc flow.count","rules":[{"t":"set","p":"count","pt":"flow","to":"$flowContext(\"count\") + 1","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":480,"y":300,"wires":[["6d2275cc.11279c"]]},{"id":"31c53733.93a678","type":"switch","z":"5a92cf26.eafdc","name":"timer not stopped","property":"payload","propertyType":"msg","rules":[{"t":"neq","v":"stopped","vt":"str"},{"t":"eq","v":"stopped","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":210,"y":300,"wires":[["b95823b1.03341"],["a5d56ae.6a17198"]]},{"id":"6d2275cc.11279c","type":"switch","z":"5a92cf26.eafdc","name":"flow.count < MAXALERTS","property":"count","propertyType":"flow","rules":[{"t":"lt","v":"MAXALERTS","vt":"env"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":730,"y":300,"wires":[["edbda1d7.c3c0e","f2aea4a8.c48848"],["997593fc.7b90b"]]},{"id":"a5d56ae.6a17198","type":"switch","z":"5a92cf26.eafdc","name":"flow.count > 0","property":"count","propertyType":"flow","rules":[{"t":"gt","v":"0","vt":"num"}],"checkall":"true","repair":false,"outputs":1,"x":480,"y":340,"wires":[["185579a.5550286"]]},{"id":"997593fc.7b90b","type":"change","z":"5a92cf26.eafdc","name":"set email - giving up on alerts","rules":[{"t":"set","p":"topic","pt":"msg","to":"$env('LABEL') & \" has been \" & $flowContext('value') & \" for too long!\"","tot":"jsonata"},{"t":"set","p":"payload","pt":"msg","to":"\"Maximum delay count has been exceeded. Alerts halted.\"","tot":"jsonata"},{"t":"set","p":"alertInfo","pt":"msg","to":"{     'count': $flowContext('count'),     'maxAlerts': $env('MAXALERTS'),     'delay': $env('DELAY'),     'label': $env('LABEL'),     'status': 'gave up' }","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":1180,"y":300,"wires":[["b759a1ce.6b1c1"]]},{"id":"3f80ff5a.11667","type":"change","z":"5a92cf26.eafdc","name":"set email - device has stopped action","rules":[{"t":"set","p":"topic","pt":"msg","to":"$env('LABEL') & \" has been \" & ( $flowContext('value') in ['on','off'] ? 'turned ' : '') & $flowContext('value') & \".\"\t","tot":"jsonata"},{"t":"set","p":"payload","pt":"msg","to":"$env('LABEL') & \" has been \" & ( $flowContext('value') in ['on','off'] ? 'turned ' : '') & $flowContext('value') & \".\"","tot":"jsonata"},{"t":"set","p":"alertInfo","pt":"msg","to":"{     'count': $flowContext('count'),     'maxAlerts': $env('MAXALERTS'),     'delay': $env('DELAY'),     'label': $env('LABEL'),     'status': 'resolved'}","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":1150,"y":340,"wires":[["b759a1ce.6b1c1"]]},{"id":"f2aea4a8.c48848","type":"change","z":"5a92cf26.eafdc","name":"set email - alert device action exceeds delay","rules":[{"t":"set","p":"topic","pt":"msg","to":"\"Alert! \" & $env('LABEL') &  \" has been left \" & $flowContext('value')","tot":"jsonata"},{"t":"set","p":"payload","pt":"msg","to":"$env('LABEL') &  \" has been left \" & $flowContext('value') &  \" for \" & $string($round(($flowContext('count') * $env('DELAY'))/60)) &  \" minutes and \" & $string((($flowContext('count') * $env('DELAY')) % 60)) & \" seconds.\"","tot":"jsonata"},{"t":"set","p":"alertInfo","pt":"msg","to":"{\t    'count': $flowContext('count'),\t    'maxAlerts': $env('MAXALERTS'),\t    'delay': $env('DELAY'),\t    'label': $env('LABEL'),\t    'status': 'in progress'\t}","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":1130,"y":260,"wires":[["b759a1ce.6b1c1"]]},{"id":"185579a.5550286","type":"change","z":"5a92cf26.eafdc","name":"flow.count = 0","rules":[{"t":"set","p":"count","pt":"flow","to":"0","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":700,"y":340,"wires":[["3f80ff5a.11667"]]},{"id":"8de438fe.118078","type":"change","z":"5a92cf26.eafdc","name":"flow.value = payload.value","rules":[{"t":"set","p":"value","pt":"flow","to":"payload.value","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":240,"y":100,"wires":[["1bd998dc.a36f27"]]},{"id":"11c52b3c.363f65","type":"switch","z":"5a92cf26.eafdc","name":"Alert Immediately? false/true and flow.count = 0","property":"$env('ALERTIMMEDIATELY') and $flowContext('count') = 0","propertyType":"jsonata","rules":[{"t":"false"},{"t":"true"}],"checkall":"true","repair":false,"outputs":2,"x":580,"y":160,"wires":[["edbda1d7.c3c0e"],["8d52bc23.5a712","edbda1d7.c3c0e"]]},{"id":"8d52bc23.5a712","type":"change","z":"5a92cf26.eafdc","name":"set email - immediate alert","rules":[{"t":"set","p":"topic","pt":"msg","to":"\"Alert! \" & $env('LABEL') &  \" is \" & $flowContext('value') & \".\"","tot":"jsonata"},{"t":"set","p":"payload","pt":"msg","to":"\"This message will repeat \" & $env('MAXALERTS') & \" time(s) every \" & $string($env('DELAY')/60) &  \" minutes and \" & $string($env('DELAY') % 60) & \" seconds.\"","tot":"jsonata"},{"t":"set","p":"alertInfo","pt":"msg","to":"{\t    'count': $flowContext('count'),\t    'maxAlerts': $env('MAXALERTS'),\t    'delay': $env('DELAY'),\t    'label': $env('LABEL'),\t    'status': 'immediate'\t}","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":1180,"y":220,"wires":[["b759a1ce.6b1c1"]]},{"id":"b759a1ce.6b1c1","type":"e-mail","z":"5a92cf26.eafdc","server":"smtp.gmail.com","port":"465","secure":true,"tls":true,"name":"","dname":"","x":1610,"y":460,"wires":[]}]

edit: am using the stoptimer-varidelay and email nodes. You can set how many times it alerts you before giving up, how long to wait (in seconds) between alerts etc.

1 Like

@erktrek, thanks.
I can not import your flow because this error :


Could you share a simple flow then I can import ?

Add those nodes to your palette. Click on the "hamburger" menu in the upper right and from the drop-down choose "manage palette" then select install tab.. type "email" in the search box and the first node should be "node-red-node-email".. install it then search for "stoptimer" and install "node-red-contrib-stoptimer-varidelay" node.

1 Like

On the Palette have some e-mail :

  • node-red-node-email
  • node-red-contrib-email-out
    ... Witch one I need Install ?
    Thanks.

node-red-node-email - I just edited my previous post with the proper node names.

1 Like

On my subflows :

That is strange there should be an email node at the bottom.. connected to all the "set email:" nodes... like this:

the email at the bottom is another subflow but it can just be the email out node... apologies on messing that up!! - need to delete existing subflow and reimport or maybe just reimport..

Delete existing subflow and reimport

Have you seen node-red-contrib-interval-length?

Just yesterday I was looking for a way to do something similar; a sort of watchdog sequence for some motion/temp sensors. Since I use them for thermostat setting, I wanted to know if their values haven't changed in a while, as I've had examples of Iris and Hue sensors somehow falling silent until I pulled and re-inserted the batteries. I found this node, which includes a "Timeout" option. I was able to make this work pretty easily.

I've only had this working for a day, so it hasn't had exhaustive testing.

Node-RED interval flow

Can you see any obvious shortcomings to this one?

1 Like

Looks like it would work.

I use stoptimer for basically the same thing. Each new msg resets the stop timer, if it times out, the output msg triggers a pushover message.

Like this:

3 Likes