Node-Red - advanced motion lighting control example with lux

First off a huge thanks to @aaiyar, @csteele and @JasonJoel for helping me through the intricacies of Node-Red. I have been making good progress thanks to those above.

If anyone can give me an idea on how to add "manual control" to the "active" motion LVL setting that would be great. If someone turns on the light to full brightness though the "mode" says it should be LVL 3 then ignore it as an example.

My current example (will update if solution for manual control is available):

EDIT: Thanks @csteele for seeing my error in modes since I have that as a global variable

Master Bathroom Adv Motion

[{"id":"b812c215.4f5cc","type":"hubitat command","z":"d30b65df.fdcd68","name":"Set Master Bathroom LVL","server":"a3287340.7b34d","deviceId":"714","command":"setLevel","commandArgs":"msg.arguments","x":1390,"y":580,"wires":[[]]},{"id":"48dc2914.464598","type":"change","z":"d30b65df.fdcd68","name":"","rules":[{"t":"set","p":"arguments","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1150,"y":580,"wires":[["b812c215.4f5cc"]]},{"id":"37da6d8e.f22382","type":"easing","z":"d30b65df.fdcd68","name":"","easingType":"linear","outputType":"overTime","duration":1000,"interval":"2000","numberOfValues":10,"x":970,"y":580,"wires":[["48dc2914.464598"]]},{"id":"4e851c63.b849c4","type":"change","z":"d30b65df.fdcd68","name":"LVL change from ? to 0 over 2 mins","rules":[{"t":"set","p":"payload","pt":"msg","to":"{\t \"from\":(payload.value),\t \"to\": 0,\t \"duration\":120000\t}","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":740,"y":580,"wires":[["37da6d8e.f22382"]]},{"id":"f43ae31a.d721b","type":"hubitat device","z":"d30b65df.fdcd68","name":"Get Master Bathroom LVL","server":"a3287340.7b34d","deviceId":"714","attribute":"level","sendEvent":false,"x":690,"y":520,"wires":[["4e851c63.b849c4"]]},{"id":"791ab187.d10c8","type":"stoptimer","z":"d30b65df.fdcd68","duration":"5","units":"Minute","payloadtype":"num","payloadval":"0","name":"","x":460,"y":480,"wires":[["f43ae31a.d721b"],[]]},{"id":"ed47b08.da09a5","type":"stoptimer","z":"d30b65df.fdcd68","duration":"1","units":"Minute","payloadtype":"num","payloadval":"0","name":"","x":460,"y":560,"wires":[["f43ae31a.d721b"],[]]},{"id":"bc53db97.7e0208","type":"switch","z":"d30b65df.fdcd68","name":"Mode","property":"currentMode","propertyType":"global","rules":[{"t":"eq","v":"Early Morning","vt":"str"},{"t":"eq","v":"Day","vt":"str"},{"t":"eq","v":"Evening","vt":"str"},{"t":"eq","v":"Night","vt":"str"},{"t":"eq","v":"Sleep","vt":"str"}],"checkall":"true","repair":false,"outputs":5,"x":270,"y":520,"wires":[["ed47b08.da09a5"],["791ab187.d10c8"],["791ab187.d10c8"],["791ab187.d10c8"],["ed47b08.da09a5"]]},{"id":"7307d0c9.fc803","type":"switch","z":"d30b65df.fdcd68","name":"active/inactive","property":"payload.value","propertyType":"msg","rules":[{"t":"eq","v":"active","vt":"str"},{"t":"eq","v":"inactive","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":700,"y":160,"wires":[["71bfb728.a12528"],["8ea3f3c0.afee9"]]},{"id":"71bfb728.a12528","type":"switch","z":"d30b65df.fdcd68","name":"Check Lux","property":"lux","propertyType":"global","rules":[{"t":"true"},{"t":"false"}],"checkall":"true","repair":false,"outputs":2,"x":930,"y":160,"wires":[["3e1ece7a.0f32e2"],["8ea3f3c0.afee9"]]},{"id":"3e1ece7a.0f32e2","type":"change","z":"d30b65df.fdcd68","name":"","rules":[{"t":"delete","p":"payload.value","pt":"msg"},{"t":"set","p":"payload","pt":"msg","to":"stop","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1180,"y":160,"wires":[["8ea3f3c0.afee9","90d13b7.35bacc8"]]},{"id":"2a32071e.547d68","type":"inject","z":"d30b65df.fdcd68","name":"","topic":"","payload":"true","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":110,"y":160,"wires":[["cb092691.c2c2e8","73aafd25.701524"]]},{"id":"90d13b7.35bacc8","type":"switch","z":"d30b65df.fdcd68","name":"Mode","property":"currentMode","propertyType":"global","rules":[{"t":"eq","v":"Early Morning","vt":"str"},{"t":"eq","v":"Day","vt":"str"},{"t":"eq","v":"Evening","vt":"str"},{"t":"eq","v":"Night","vt":"str"},{"t":"eq","v":"Sleep","vt":"str"}],"checkall":"true","repair":false,"outputs":5,"x":1170,"y":340,"wires":[["a3cf926d.07709"],["54f841fd.20329"],["54f841fd.20329"],["54f841fd.20329"],["a3cf926d.07709"]]},{"id":"a3cf926d.07709","type":"hubitat command","z":"d30b65df.fdcd68","name":"Set Master Bathroom LVL 3","server":"a3287340.7b34d","deviceId":"714","command":"setLevel","commandArgs":"3","x":1420,"y":360,"wires":[[]]},{"id":"54f841fd.20329","type":"hubitat command","z":"d30b65df.fdcd68","name":"Set Master Bathroom LVL 100","server":"a3287340.7b34d","deviceId":"714","command":"setLevel","commandArgs":"100","x":1430,"y":300,"wires":[[]]},{"id":"73aafd25.701524","type":"hubitat device","z":"d30b65df.fdcd68","name":"Master Bathroom","server":"a3287340.7b34d","deviceId":"714","attribute":"motion","sendEvent":true,"x":310,"y":120,"wires":[["7307d0c9.fc803"]]},{"id":"cb092691.c2c2e8","type":"hubitat device","z":"d30b65df.fdcd68","name":"Motion Master Bathroom - Zooz 4-in-1 Sensor","server":"a3287340.7b34d","deviceId":"1967","attribute":"motion","sendEvent":true,"x":380,"y":180,"wires":[["7307d0c9.fc803"]]},{"id":"57cc8a15.3f5bf4","type":"switch","z":"d30b65df.fdcd68","name":"switch is on","property":"payload.value","propertyType":"msg","rules":[{"t":"eq","v":"on","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":430,"y":320,"wires":[["bc53db97.7e0208"]]},{"id":"8ea3f3c0.afee9","type":"hubitat device","z":"d30b65df.fdcd68","name":"Master Bathroom","server":"a3287340.7b34d","deviceId":"714","attribute":"switch","sendEvent":true,"x":230,"y":320,"wires":[["57cc8a15.3f5bf4"]]},{"id":"7b2b19e8.dadea8","type":"comment","z":"d30b65df.fdcd68","name":"Motion Lighting","info":"","x":120,"y":60,"wires":[]},{"id":"ad72656e.bdef98","type":"comment","z":"d30b65df.fdcd68","name":"Motion Active and set LVL based on modes","info":"","x":1420,"y":260,"wires":[]},{"id":"a828bd76.95f1f","type":"comment","z":"d30b65df.fdcd68","name":"Master Bathroom is a GE dimmer w/motion sensor","info":"","x":470,"y":60,"wires":[]},{"id":"7c8c8cce.c3c2d4","type":"comment","z":"d30b65df.fdcd68","name":"If switch is already on then ignore send command","info":"","x":220,"y":280,"wires":[]},{"id":"955554c3.6207f8","type":"comment","z":"d30b65df.fdcd68","name":"Motion is inactive/lux is false/light is off","info":"","x":210,"y":440,"wires":[]},{"id":"a3287340.7b34d","type":"hubitat config","z":"","name":"Home HE","usetls":false,"host":"192.168.4.64","port":"80","appId":"5581","nodeRedServer":"http://192.168.4.83:1880","webhookPath":"/hubitat/webhook_","autoRefresh":true}]

Mode/Global Lux

[{"id":"4ece128d.82489c","type":"hubitat mode","z":"387d523b.2881de","name":"Mode Is","server":"a3287340.7b34d","sendEvent":true,"x":300,"y":120,"wires":[["d5f4119c.3d856"]]},{"id":"5533b247.ac5fbc","type":"change","z":"387d523b.2881de","name":"saveCurrentMode","rules":[{"t":"set","p":"currentMode","pt":"global","to":"payload.value","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":645,"y":120,"wires":[["6fff37df.01a968"]]},{"id":"d5f4119c.3d856","type":"rbe","z":"387d523b.2881de","name":"","func":"rbe","gap":"","start":"","inout":"out","property":"payload","x":465,"y":120,"wires":[["5533b247.ac5fbc"]]},{"id":"6fff37df.01a968","type":"debug","z":"387d523b.2881de","name":"SavedMode IS","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":1270,"y":121,"wires":[]},{"id":"9a316240.da00d","type":"comment","z":"387d523b.2881de","name":"set a global mode variable, flow.currentMode, useful everywhere in this Flow.","info":"","x":320,"y":58,"wires":[]},{"id":"2a1659c0.86d766","type":"inject","z":"387d523b.2881de","name":"","topic":"","payload":"Started!","payloadType":"str","repeat":"","crontab":"","once":true,"onceDelay":"0.1","x":140,"y":120,"wires":[["4ece128d.82489c","53155c7.033c6a4","c7b20b71.ad86f8"]]},{"id":"7a39fdb2.6f3ec4","type":"inject","z":"387d523b.2881de","name":"","topic":"","payload":"true","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":150,"y":340,"wires":[["c7b20b71.ad86f8","53155c7.033c6a4"]]},{"id":"53155c7.033c6a4","type":"hubitat device","z":"387d523b.2881de","name":"Weather","server":"a3287340.7b34d","deviceId":"3279","attribute":"illuminance","sendEvent":true,"x":340,"y":300,"wires":[["4515e50f.e89fac"]]},{"id":"c7b20b71.ad86f8","type":"hubitat device","z":"387d523b.2881de","name":"Motion Sensor - Kitchen Zooz","server":"a3287340.7b34d","deviceId":"1712","attribute":"illuminance","sendEvent":true,"x":410,"y":380,"wires":[["a02de1df.613b"]]},{"id":"4515e50f.e89fac","type":"switch","z":"387d523b.2881de","name":">= 2000","property":"payload.value","propertyType":"msg","rules":[{"t":"gte","v":"2000","vt":"str"},{"t":"lt","v":"2000","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":660,"y":300,"wires":[["c379e85d.cb9d88"],["4dc15b90.9aac44"]]},{"id":"a02de1df.613b","type":"switch","z":"387d523b.2881de","name":">=19","property":"payload.value","propertyType":"msg","rules":[{"t":"gte","v":"19","vt":"str"},{"t":"lt","v":"19","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":650,"y":380,"wires":[["c379e85d.cb9d88"],["4dc15b90.9aac44"]]},{"id":"4dc15b90.9aac44","type":"change","z":"387d523b.2881de","name":"Lux is True","rules":[{"t":"set","p":"lux","pt":"global","to":"true","tot":"bool"},{"t":"set","p":"payload","pt":"msg","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":830,"y":360,"wires":[["258566fa.e0f94a","ee25f475.1796d8","43604bba.40c384","28781f4d.ae4e7","b7da0ac0.b56f48","39c931e5.99c3ce"]]},{"id":"c379e85d.cb9d88","type":"change","z":"387d523b.2881de","name":"Lux is False","rules":[{"t":"set","p":"lux","pt":"global","to":"false","tot":"bool"},{"t":"set","p":"payload","pt":"msg","to":"false","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":410,"y":500,"wires":[[]]},{"id":"b548745a.9346a8","type":"hubitat command","z":"387d523b.2881de","name":"Upstairs Lights Off","server":"a3287340.7b34d","deviceId":"710","command":"off","commandArgs":"","x":1530,"y":300,"wires":[[]]},{"id":"a3973390.ccaeb","type":"hubitat command","z":"387d523b.2881de","name":"Living Room Lights Off","server":"a3287340.7b34d","deviceId":"1457","command":"off","commandArgs":"","x":1540,"y":600,"wires":[[]]},{"id":"778aacc3.3435e4","type":"hubitat command","z":"387d523b.2881de","name":"Kitchen Lights Off","server":"a3287340.7b34d","deviceId":"1649","command":"off","commandArgs":"","x":1530,"y":540,"wires":[[]]},{"id":"dfba7217.6f543","type":"hubitat command","z":"387d523b.2881de","name":"Kitchen Cabinet Lights Off","server":"a3287340.7b34d","deviceId":"637","command":"off","commandArgs":"","x":1550,"y":480,"wires":[[]]},{"id":"31281d33.000772","type":"hubitat command","z":"387d523b.2881de","name":"Dining Room Lights Off","server":"a3287340.7b34d","deviceId":"646","command":"off","commandArgs":"","x":1550,"y":420,"wires":[[]]},{"id":"45d69357.433fcc","type":"hubitat command","z":"387d523b.2881de","name":"Office Lights Off","server":"a3287340.7b34d","deviceId":"633","command":"off","commandArgs":"","x":1520,"y":360,"wires":[[]]},{"id":"f12226bc.11f378","type":"switch","z":"387d523b.2881de","name":"switch is on","property":"payload.value","propertyType":"msg","rules":[{"t":"eq","v":"on","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":1270,"y":300,"wires":[["b548745a.9346a8"]]},{"id":"258566fa.e0f94a","type":"hubitat device","z":"387d523b.2881de","name":"Upstairs Lights","server":"a3287340.7b34d","deviceId":"710","attribute":"switch","sendEvent":true,"x":1020,"y":300,"wires":[["f12226bc.11f378"]]},{"id":"ee25f475.1796d8","type":"hubitat device","z":"387d523b.2881de","name":"Office Lights","server":"a3287340.7b34d","deviceId":"633","attribute":"switch","sendEvent":true,"x":1010,"y":360,"wires":[["e40b46d1.c77da8"]]},{"id":"39c931e5.99c3ce","type":"hubitat device","z":"387d523b.2881de","name":"Living Room Lights","server":"a3287340.7b34d","deviceId":"1457","attribute":"switch","sendEvent":true,"x":1030,"y":600,"wires":[["ae381124.45b7b"]]},{"id":"b7da0ac0.b56f48","type":"hubitat device","z":"387d523b.2881de","name":"Kitchen Lights","server":"a3287340.7b34d","deviceId":"1649","attribute":"switch","sendEvent":true,"x":1020,"y":540,"wires":[["7bebecd0.750a04"]]},{"id":"28781f4d.ae4e7","type":"hubitat device","z":"387d523b.2881de","name":"Kitchen Cabinet Lights","server":"a3287340.7b34d","deviceId":"637","attribute":"switch","sendEvent":true,"x":1040,"y":480,"wires":[["442a15f0.ecd7cc"]]},{"id":"43604bba.40c384","type":"hubitat device","z":"387d523b.2881de","name":"Dining Room Lights","server":"a3287340.7b34d","deviceId":"646","attribute":"switch","sendEvent":true,"x":1030,"y":420,"wires":[["58398dda.f82ea4"]]},{"id":"e40b46d1.c77da8","type":"switch","z":"387d523b.2881de","name":"switch is on","property":"payload.value","propertyType":"msg","rules":[{"t":"eq","v":"on","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":1270,"y":360,"wires":[["45d69357.433fcc"]]},{"id":"58398dda.f82ea4","type":"switch","z":"387d523b.2881de","name":"switch is on","property":"payload.value","propertyType":"msg","rules":[{"t":"eq","v":"on","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":1270,"y":420,"wires":[["31281d33.000772"]]},{"id":"442a15f0.ecd7cc","type":"switch","z":"387d523b.2881de","name":"switch is on","property":"payload.value","propertyType":"msg","rules":[{"t":"eq","v":"on","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":1270,"y":480,"wires":[["dfba7217.6f543"]]},{"id":"7bebecd0.750a04","type":"switch","z":"387d523b.2881de","name":"switch is on","property":"payload.value","propertyType":"msg","rules":[{"t":"eq","v":"on","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":1270,"y":540,"wires":[["778aacc3.3435e4"]]},{"id":"ae381124.45b7b","type":"switch","z":"387d523b.2881de","name":"switch is on","property":"payload.value","propertyType":"msg","rules":[{"t":"eq","v":"on","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":1270,"y":600,"wires":[["a3973390.ccaeb"]]},{"id":"a3287340.7b34d","type":"hubitat config","z":"","name":"Home HE","usetls":false,"host":"192.168.4.64","port":"80","appId":"5581","nodeRedServer":"http://192.168.4.83:1880","webhookPath":"/hubitat/webhook_","autoRefresh":true}]

1 Like

I do something somewhat similar with bathroom vent fans... If humidity high turn on, turn off if humidity goes normal. But people also turn on bathroom fans for other reasons (toilet use).

What I do is set a node variable based on who turned it on (although level% could be done similarly). If the logic turns it on - variable="node", if it is turned on outside of the node then variable="manual", when off variable = "none".

Then I check that variable when I would norm ally want to turn off the fan. If "manual" then ignore humidity off commands, for example.

Could also use state machine, but for only 2 states it is overkill and a pain in the arse (my opinion having worked with state machines all the time at work).

4 Likes

I love this idea. Can you provide your humidity flow so I could review?

Nothing especially fancy, and not exactly what you are trying to do, but maybe it will give some ideas. Probably better/more efficient ways of doing it, but this way makes sense to me - and it works - so I left it alone. :slight_smile:

[
    {
        "id": "567a7751.a78008",
        "type": "tab",
        "label": "Flow 1",
        "disabled": true,
        "info": ""
    },
    {
        "id": "3f0ccdca.0338a2",
        "type": "comment",
        "z": "567a7751.a78008",
        "name": "Guest Bathroom Vent",
        "info": "",
        "x": 160,
        "y": 80,
        "wires": []
    },
    {
        "id": "fa734326.1126d",
        "type": "hubitat command",
        "z": "567a7751.a78008",
        "name": "Vent ON",
        "server": "c52b07ef.d92868",
        "deviceId": "71",
        "command": "on",
        "commandArgs": "",
        "x": 1720,
        "y": 120,
        "wires": [
            [
                "54dfb57e.f270ec"
            ]
        ]
    },
    {
        "id": "dd1e7030.e61a4",
        "type": "hubitat command",
        "z": "567a7751.a78008",
        "name": "Vent OFF",
        "server": "c52b07ef.d92868",
        "deviceId": "71",
        "command": "off",
        "commandArgs": "",
        "x": 1720,
        "y": 180,
        "wires": [
            []
        ]
    },
    {
        "id": "26e81a03.e38d06",
        "type": "hubitat device",
        "z": "567a7751.a78008",
        "name": "Guest Bathroom Vent",
        "server": "c52b07ef.d92868",
        "deviceId": "71",
        "attribute": "switch",
        "sendEvent": false,
        "x": 1380,
        "y": 120,
        "wires": [
            [
                "3af209da.e40206"
            ]
        ]
    },
    {
        "id": "f1150215.d516a",
        "type": "hubitat device",
        "z": "567a7751.a78008",
        "name": "Guest Bathroom Vent",
        "server": "c52b07ef.d92868",
        "deviceId": "71",
        "attribute": "switch",
        "sendEvent": false,
        "x": 1380,
        "y": 180,
        "wires": [
            [
                "f80fcc67.d934d"
            ]
        ]
    },
    {
        "id": "3af209da.e40206",
        "type": "switch",
        "z": "567a7751.a78008",
        "name": "off/on",
        "property": "payload.value",
        "propertyType": "msg",
        "rules": [
            {
                "t": "eq",
                "v": "off",
                "vt": "str"
            },
            {
                "t": "eq",
                "v": "on",
                "vt": "str"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 2,
        "x": 1570,
        "y": 120,
        "wires": [
            [
                "fa734326.1126d"
            ],
            []
        ]
    },
    {
        "id": "f80fcc67.d934d",
        "type": "switch",
        "z": "567a7751.a78008",
        "name": "off/on",
        "property": "payload.value",
        "propertyType": "msg",
        "rules": [
            {
                "t": "eq",
                "v": "off",
                "vt": "str"
            },
            {
                "t": "eq",
                "v": "on",
                "vt": "str"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 2,
        "x": 1570,
        "y": 180,
        "wires": [
            [],
            [
                "dd1e7030.e61a4"
            ]
        ]
    },
    {
        "id": "f45e3a6d.52dee8",
        "type": "hubitat device",
        "z": "567a7751.a78008",
        "name": "Guest Bathroom Humidity and Temperature",
        "server": "d0f5761.f707088",
        "deviceId": "1520",
        "attribute": "humidity",
        "sendEvent": true,
        "x": 230,
        "y": 120,
        "wires": [
            [
                "db99d60e.fd02d8"
            ]
        ]
    },
    {
        "id": "28abcc4a.cbccd4",
        "type": "hubitat device",
        "z": "567a7751.a78008",
        "name": "Guest Bedroom Humidity and Temperature",
        "server": "d0f5761.f707088",
        "deviceId": "1523",
        "attribute": "humidity",
        "sendEvent": true,
        "x": 230,
        "y": 180,
        "wires": [
            [
                "7ece911c.7b175"
            ]
        ]
    },
    {
        "id": "db99d60e.fd02d8",
        "type": "change",
        "z": "567a7751.a78008",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "#:(fs)::GBathHumidity",
                "pt": "flow",
                "to": "payload.value",
                "tot": "msg"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 550,
        "y": 120,
        "wires": [
            [
                "8d837ed1.1aa24"
            ]
        ]
    },
    {
        "id": "7ece911c.7b175",
        "type": "change",
        "z": "567a7751.a78008",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "#:(fs)::GBRHumidity",
                "pt": "flow",
                "to": "payload.value",
                "tot": "msg"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 540,
        "y": 180,
        "wires": [
            [
                "8d837ed1.1aa24"
            ]
        ]
    },
    {
        "id": "8d837ed1.1aa24",
        "type": "function",
        "z": "567a7751.a78008",
        "name": "calc",
        "func": "var newmsg = {};\n\nvar GBathHumidity = flow.get(\"GBathHumidity\", \"fs\");\nvar GBRHumidity = flow.get(\"GBRHumidity\", \"fs\");\n\nif (!GBathHumidity || !GBRHumidity) {\n    return;\n}\n\nif (GBathHumidity > (GBRHumidity + 10)) {\n    newmsg.payload = true;\n    return newmsg;\n}\n\nif (GBathHumidity < (GBRHumidity + 8)) {\n    newmsg.payload = false;\n    return newmsg;\n}",
        "outputs": 1,
        "noerr": 0,
        "x": 790,
        "y": 140,
        "wires": [
            [
                "edbe2363.6e517"
            ]
        ]
    },
    {
        "id": "edbe2363.6e517",
        "type": "switch",
        "z": "567a7751.a78008",
        "name": "true/false",
        "property": "payload",
        "propertyType": "msg",
        "rules": [
            {
                "t": "true"
            },
            {
                "t": "false"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 2,
        "x": 940,
        "y": 140,
        "wires": [
            [
                "e7667a98.d785f8"
            ],
            [
                "ffe6ec7a.87ed2"
            ]
        ]
    },
    {
        "id": "ccac1959.563d78",
        "type": "hubitat device",
        "z": "567a7751.a78008",
        "name": "Guest Bathroom Vent",
        "server": "c52b07ef.d92868",
        "deviceId": "71",
        "attribute": "switch",
        "sendEvent": true,
        "x": 160,
        "y": 260,
        "wires": [
            [
                "22aeaeac.62d2b2"
            ]
        ]
    },
    {
        "id": "7d86bab9.ab99b4",
        "type": "switch",
        "z": "567a7751.a78008",
        "name": "GBathVent != humidity",
        "property": "GBathVent",
        "propertyType": "flow",
        "rules": [
            {
                "t": "neq",
                "v": "humidity",
                "vt": "str"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 1,
        "x": 540,
        "y": 280,
        "wires": [
            [
                "967ad24f.09d77"
            ]
        ]
    },
    {
        "id": "967ad24f.09d77",
        "type": "change",
        "z": "567a7751.a78008",
        "name": "GBathVent = manual",
        "rules": [
            {
                "t": "set",
                "p": "GBathVent",
                "pt": "flow",
                "to": "manual",
                "tot": "str"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 780,
        "y": 280,
        "wires": [
            [
                "9ea4ea07.766f28"
            ]
        ]
    },
    {
        "id": "54dfb57e.f270ec",
        "type": "change",
        "z": "567a7751.a78008",
        "name": "GBathVent = humidity",
        "rules": [
            {
                "t": "set",
                "p": "GBathVent",
                "pt": "flow",
                "to": "humidity",
                "tot": "str"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 1920,
        "y": 120,
        "wires": [
            []
        ]
    },
    {
        "id": "ffe6ec7a.87ed2",
        "type": "switch",
        "z": "567a7751.a78008",
        "name": "GBathVent = humidity",
        "property": "GBathVent",
        "propertyType": "flow",
        "rules": [
            {
                "t": "eq",
                "v": "humidity",
                "vt": "str"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 1,
        "x": 1140,
        "y": 180,
        "wires": [
            [
                "f1150215.d516a"
            ]
        ]
    },
    {
        "id": "e7667a98.d785f8",
        "type": "switch",
        "z": "567a7751.a78008",
        "name": "GBathVent != manual",
        "property": "GBathVent",
        "propertyType": "flow",
        "rules": [
            {
                "t": "neq",
                "v": "manual",
                "vt": "str"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 1,
        "x": 1140,
        "y": 120,
        "wires": [
            [
                "26e81a03.e38d06"
            ]
        ]
    },
    {
        "id": "900a2f11.8560e",
        "type": "hubitat command",
        "z": "567a7751.a78008",
        "name": "Vent OFF",
        "server": "c52b07ef.d92868",
        "deviceId": "71",
        "command": "off",
        "commandArgs": "",
        "x": 1180,
        "y": 280,
        "wires": [
            []
        ]
    },
    {
        "id": "22aeaeac.62d2b2",
        "type": "switch",
        "z": "567a7751.a78008",
        "name": "off/on",
        "property": "payload.value",
        "propertyType": "msg",
        "rules": [
            {
                "t": "eq",
                "v": "off",
                "vt": "str"
            },
            {
                "t": "eq",
                "v": "on",
                "vt": "str"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 2,
        "x": 350,
        "y": 260,
        "wires": [
            [
                "bf80801a.89317"
            ],
            [
                "7d86bab9.ab99b4"
            ]
        ]
    },
    {
        "id": "bf80801a.89317",
        "type": "change",
        "z": "567a7751.a78008",
        "name": "GBathVent = none",
        "rules": [
            {
                "t": "set",
                "p": "GBathVent",
                "pt": "flow",
                "to": "none",
                "tot": "str"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 530,
        "y": 240,
        "wires": [
            []
        ]
    },
    {
        "id": "9ea4ea07.766f28",
        "type": "stoptimer-varidelay",
        "z": "567a7751.a78008",
        "duration": "10",
        "durationType": "num",
        "units": "Minute",
        "payloadtype": "num",
        "payloadval": "0",
        "name": "",
        "reporting": "last_minute_seconds",
        "x": 1000,
        "y": 280,
        "wires": [
            [
                "900a2f11.8560e"
            ],
            [],
            []
        ]
    },
    {
        "id": "c52b07ef.d92868",
        "type": "hubitat config",
        "z": "",
        "name": "160",
        "usetls": false,
        "host": "192.168.2.160",
        "port": "80",
        "appId": "1100",
        "nodeRedServer": "http://192.168.2.5:1880",
        "webhookPath": "/hubitat160/webhook",
        "autoRefresh": true
    },
    {
        "id": "d0f5761.f707088",
        "type": "hubitat config",
        "z": "",
        "name": "161",
        "usetls": false,
        "host": "192.168.2.161",
        "port": "80",
        "appId": "326",
        "nodeRedServer": "http://192.168.2.5:1880",
        "webhookPath": "/hubitat161/webhook",
        "autoRefresh": true
    }
]
1 Like

sheesh.. LOL

Yet another StopTimer :smiley:

I see 4 of them via search. I have to be honest, even after a quick read, I can't see the differences. Maybe I'll use DIFF to highlight the changes :smiley:

1 Like

Yeah, there are a bunch.

  • stoptimer was 1st
  • stoptimer2 picked up from stoptimer, since it stopped getting updated, and fixed some code issues and added a few minor features.
  • stoptimer3 added variable delay via environment variables (and later via incoming msg)
  • stoptimer-varidelay builds off stoptimer2 and adds a ton of new features (variable delay and units, shows countdown timer in status area, 3rd output with countdown time for use on dashboards). It is the only one I have installed.

At the time stoptimer-varidelay was made, it was the only one that could change delay via incoming msg (stoptimer3 added it later), which is a feature I use a lot in certain flows. And it is still the only one that shows a countdown of the time remaining in the status area. So its my mostest favorite (thanks @putch) .

2 Likes

I won't suggest it's as bulky as a Function might be but that's a lot of baggage for one countdown timer isn't it? :smiley:

On the other hand, I'm a big fan of one-and-only-one if that's an option. :smiley:

The features really didn't add much code. I went through it all as putch was updating it, and it is still pretty lean and mean. I really use the status display of the timer a lot, too, so that was worth it to me.

But in general I am the same way - I like the lightest node that can do the job.

2 Likes

Ok, I switched everything over to StopTimer-VariDelay... we'll see if it sticks :smiley:

One thing to keep in mind on all of the stoptimer variants - the timer does not survive a node-red reboot/restart - or even a flow re-load. That has bit me a few times on long timers (I had to add additional logic/nodes to work around that).

I submitted an issue on @putch 's github to see if he would consider making his varidelay version persist node-red restarts. Not sure how hard that would be to do, but it would be hugely helpful if it did.

1 Like

Maybe working with the memory file storage somehow if one has it configured.

That's how a number of nodes I've reviewed do it - if persistent storage is configured it will use it automatically, and then on node initialization pull the needed value from persistent storage and init.

1 Like

Is actually been noodling on this for a while -- flip flopping between doing it and not doing it. Now that somebody has asked for it, I'll do it (or die trying?). Out of town right now, but once I get back I'll dig into it.

Basically I see it as having 3 user options. (1) Keep current behaviour (2) persistent, restart at whatever delay was set and (3) petsistent, restart at whatever time was still remaining.

Of course until I dig into it I can't say for sure how it'll end up.

1 Like

Makes sense in general. Not sure what the use case for restart behavior 2 would be though - and it could be easily done with a one-shot inject node to the timer as well.

Anyway, no hurry as I have a workaround for now - take timer output 3 convert to seconds remaining and store it in a flow variable with persistent store, add one-shot inject node that on start checks for flow variable >0 and sends msg.delay and msg.units to timer. Also have $contains($uppercase(msg.payload), "STOP") expression to set flow variable to 0 on a stop.

Like this - a little messy, but works:

One node you could review is boolean logic ultimate. It has a simple checkbox to make the inputs persistent or not. Might be worth seeing if the code/method they used is borrowable.

I think this is the pertinent code section:

		if (node.config.persist == true) {
			try {
				var contents = fs.readFileSync("states/" + node.id.toString()).toString();
				if (typeof contents !== 'undefined') {
					node.jSonStates = JSON.parse(contents);
					setNodeStatus({ fill: "blue", shape: "ring", text: "Loaded persistent states (" + Object.keys(node.jSonStates).length + " total)." });
				}
			} catch (error) {
				setNodeStatus({ fill: "grey", shape: "ring", text: "No persistent states" });
			}

		} else {
			setNodeStatus({ fill: "yellow", shape: "dot", text: "Waiting for input states" });
		}
1 Like

Take a look at version 0.4.1 - persistence is good to go (note it is not enabled by default)

1 Like

I saw that on your git. I'll test it out (and take a peek at the code to see how you ended up doing it) this weekend.

Thanks - now it is for sure the undisputed best stoptimer node in node-red!

EDIT 1: I just turned it on for ~20 nodes. Here's hoping it works. :slight_smile:

EDIT 2: @putch On my dev system the timer will survive a flow reload, but not a node-red restart/docker container reboot due to where you are storing the stvd-timers directory. I opened an issue on your git with a suggestion on how to fix this for container based installs - should be an easy fix (store the folder in the user directory and not the node-red main/code directory).

1 Like

I'll take a look tonight!
0.4.2 posted to github (should be in the pallette soon).

2 Likes

Just to put a 'pin in this' for others - 0.4.2 is working perfectly for me through both flow reloads and node-red restarts.

Awesome work @putch !

1 Like

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.