Valve - NRCHKB/node-red-contrib-homekit-bridged GitHub Wiki
Properties
Available Properties
Valve item has 2 required properties: Active
and InUse
. Active
determines whether it is meant to be on and InUse
determines whether it is currently flowing water.
Characteristic | Optional/Required | Characteristic Properties (to enable property) |
---|---|---|
Active | Required | |
InUse | Required | |
SetDuration | Optional | {"SetDuration":{"minValue":300, "maxValue":1200} |
RemainingDuration | Optional | Incoming property only |
ValveType | Optional | {"ValveType":{"minValue":1,"maxValue":1} sets as "sprinkler" |
SetDuration will control and be set by this in the Home app:
RemainingDuration will control and be set by this in the Home app:
Details
Characteristic | Format | Accepted Values | Notes |
---|---|---|---|
Active | int | 0, 1 | {"Active":0} / {"Active":1} |
InUse | int | 0, 1 | {"InUse":0} / {"InUse":1} |
SetDuration | uint32 | 0 - 3600 | Seconds, step value = 1 |
RemainingDuration | uint32 | 0 - 3600 | Seconds, step value = 1 |
ValveType | int | 0 - 3 | Known values: 0=generic valve, 1=sprinkler; step value=1 |
Possible Combinations
The combination of Active
and InUse
characteristics will determine what the Home app shows for the valve item. Here is a table showing all combinations:
Active | InUse | Home app Shows |
---|---|---|
{"Active":0} |
{"InUse":0} |
Off |
{"Active":0} |
{"InUse":1} |
Stopping |
{"Active":1} |
{"InUse":0} |
Idle |
{"Active":1} |
{"InUse":1} |
Running |
Examples
These examples are meant to be copied into your Node-RED system and adapted to your setup.
I. 4 Zone Sprinkler connected to OpenSprinkler
This is a fully functional sprinkler system with 4 zones which is connected to OpenSprinkler running on the same Raspberry Pi as Node-RED. The example is set up so that each of 4 zones can be turned on independently. If any zone is running, the "whole yard" zone will also show that it is running. When turning on a zone, a default is set for 10 minutes (600 seconds). This can be changed with the Default Time
inject node.
Functions:
- "Hey Siri, turn on Front Yard for 15 minutes" will water the front yard for 15 minutes
- Turning on "Whole Yard" will run OpenSprinkler program number 1
- "Whole Yard" remaining duration is a sum of each queued zone
- Does not interfere with normal operation of OpenSprinkler, only shows status and allows control from HomeKit
Characteristic Properties
These properties define the sprinkler to show as a "sprinkler" in HomeKit (rather than a generic faucet) and define that the zone show with a "SetDuration" option (so the duration may be set from HomeKit).
{
"ValveType":
{
"minValue":1,
"maxValue":1
},
"SetDuration":
{
"minValue":300,
"maxValue":1800
}
}
Important notes:
The topic must be set in HomeKit to filter nodes based on incoming topic.
Copyable Node-RED flow:
[{"id":"972fe2e4.b830e8","type":"http request","z":"d58d7d15.df3be8","name":"GET all","method":"GET","ret":"obj","paytoqs":false,"url":"http://localhost:8080/ja","tls":"","proxy":"","authType":"basic","x":340,"y":460,"wires":["d94230d6.8aef9"]]},{"id":"d94230d6.8aef9","type":"function","z":"d58d7d15.df3be8","name":"Sprinkler -> HK","func":"var out = {};\nfor (i = 0; i < 4; i++) {\n out[i] = {\n \"payload\": {\n \"Active\":Math.min(1,msg.payload.settings.ps[i][0]),\n \"InUse\":msg.payload.status.sn[i],\n \"RemainingDuration\":msg.payload.settings.ps[i][1]\n },\n \"topic\": String(i)\n };\n}\nout[4] = {\n \"payload\": {\n \"Active\":Math.max(\n out[0].payload.Active,\n out[1].payload.Active,\n out[2].payload.Active,\n out[3].payload.Active\n ),\n \"InUse\":Math.max(\n out[0].payload.InUse,\n out[1].payload.InUse,\n out[2].payload.InUse,\n out[3].payload.InUse\n ),\n \"RemainingDuration\":(\n out[0].payload.RemainingDuration +\n out[1].payload.RemainingDuration +\n out[2].payload.RemainingDuration +\n out[3].payload.RemainingDuration\n )\n },\n \"topic\": String(4)\n};\nvar prevout = context.get(\"prevout\") ](/NRCHKB/node-red-contrib-homekit-bridged/wiki/|-{};\nreturn-[[out[0],-out[1],-out[2],-out[3],-out[4)];\n","outputs":1,"noerr":0,"x":520,"y":460,"wires":["aac7c238.08a87"]]},{"id":"c61a0975.d8116","type":"inject","z":"d58d7d15.df3be8","name":"Cron","topic":"","payload":"","payloadType":"date","repeat":"2","crontab":"","once":false,"onceDelay":0.1,"x":190,"y":460,"wires":[["972fe2e4.b830e8"]]},{"id":"aac7c238.08a87","type":"rbe","z":"d58d7d15.df3be8","name":"","func":"rbe","gap":"","start":"","inout":"out","property":"payload","x":720,"y":460,"wires":[["9f1112f8.bcec38","b4c04a5a.94dc6","4a61c969.7498e","41a98348.87c93c","af1afae5.f437f8"]]},{"id":"470fbc10.3b41b4","type":"function","z":"d58d7d15.df3be8","name":"Duration","func":"var out = {};\nfor (i = 0; i < 4; i++) {\n out[i] = {\n \"payload\": {\n \"SetDuration\": msg.payload\n },\n \"topic\": String(i)\n }\n}\nreturn [[out[0], out[1], out[2], out[3]]];\n","outputs":1,"noerr":0,"x":540,"y":400,"wires":[["aac7c238.08a87"]]},{"id":"9f1112f8.bcec38","type":"homekit-service","z":"d58d7d15.df3be8","isParent":true,"bridge":"6a8d3ef1.88061","parentService":"","name":"Butterfly Garden","serviceName":"Valve","topic":"0","filter":true,"manufacturer":"Default Manufacturer","model":"Default Model","serialNo":"Default Serial Number","characteristicProperties":"{\n \"ValveType\":\n {\n \"minValue\":1,\n \"maxValue\":1\n },\n \"SetDuration\":\n {\n \"minValue\":300,\n \"maxValue\":1800\n }\n}","x":940,"y":340,"wires":[["3f49c0d.c9f03c"]]},{"id":"b4c04a5a.94dc6","type":"homekit-service","z":"d58d7d15.df3be8","isParent":true,"bridge":"6a8d3ef1.88061","parentService":"","name":"Driveway","serviceName":"Valve","topic":"1","filter":true,"manufacturer":"Default Manufacturer","model":"Default Model","serialNo":"Default Serial Number","characteristicProperties":"{\n \"ValveType\":\n {\n \"minValue\":1,\n \"maxValue\":1\n },\n \"SetDuration\":\n {\n \"minValue\":300,\n \"maxValue\":1800\n }\n}","x":920,"y":400,"wires":[["3f49c0d.c9f03c"]]},{"id":"4a61c969.7498e","type":"homekit-service","z":"d58d7d15.df3be8","isParent":true,"bridge":"6a8d3ef1.88061","parentService":"","name":"Front Yard","serviceName":"Valve","topic":"2","filter":true,"manufacturer":"Rainbird 500","model":"Default Model","serialNo":"Zone 3","characteristicProperties":"{\n \"ValveType\":\n {\n \"minValue\":1,\n \"maxValue\":1\n },\n \"SetDuration\":\n {\n \"minValue\":300,\n \"maxValue\":1800\n }\n}","x":930,"y":460,"wires":[["3f49c0d.c9f03c"]]},{"id":"41a98348.87c93c","type":"homekit-service","z":"d58d7d15.df3be8","isParent":true,"bridge":"6a8d3ef1.88061","parentService":"","name":"Back Yard","serviceName":"Valve","topic":"3","filter":true,"manufacturer":"RainBird 500","model":"Default Model","serialNo":"Zone 4","characteristicProperties":"{\n \"ValveType\":\n {\n \"minValue\":1,\n \"maxValue\":1\n },\n \"SetDuration\":\n {\n \"minValue\":300,\n \"maxValue\":1800\n }\n}","x":930,"y":520,"wires":[["3f49c0d.c9f03c"]]},{"id":"af1afae5.f437f8","type":"homekit-service","z":"d58d7d15.df3be8","isParent":true,"bridge":"6a8d3ef1.88061","parentService":"","name":"Whole Yard","serviceName":"Valve","topic":"4","filter":true,"manufacturer":"Default Manufacturer","model":"Default Model","serialNo":"Default Serial Number","characteristicProperties":"{\n \"ValveType\":\n {\n \"minValue\":1,\n \"maxValue\":1\n }\n}","x":930,"y":580,"wires":[["3f49c0d.c9f03c"]]},{"id":"7437d718.0a2d98","type":"link in","z":"d58d7d15.df3be8","name":"Run program","links":["5bf24742.9efdf"],"x":530,"y":520,"wires":[["aac7c238.08a87"]],"l":true},{"id":"e5af1a32.c833c","type":"inject","z":"d58d7d15.df3be8","name":"10 minute default run time","topic":"","payload":"600","payloadType":"num","repeat":"","crontab":"00 22 * * *","once":false,"onceDelay":"10","x":280,"y":400,"wires":[["470fbc10.3b41b4"]]},{"id":"5d81641e.9b310c","type":"inject","z":"d58d7d15.df3be8","name":"5 minute runtime","topic":"","payload":"300","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":"10","x":320,"y":340,"wires":[["470fbc10.3b41b4"]]},{"id":"3f49c0d.c9f03c","type":"function","z":"d58d7d15.df3be8","name":"HK -> OS","func":"var Zone = parseInt(msg.topic, 10); // Zone = zone number - 1\n\nvar duration = flow.get(\"duration\") ](/NRCHKB/node-red-contrib-homekit-bridged/wiki/|-{\n----0:-300,\n----1:-300,\n----2:-300,\n----3:-300\n};\n\nif-(msg.payload.SetDuration)-{\n----duration[Zone]-=-msg.payload.SetDuration;\n}\n\nflow.set(\"duration\",-duration);\n\nif-(msg.hap-!==-undefined-&&-msg.hap.context-!==-undefined-&&-msg.payload.Active-!==-undefined)-{\n----var-ip-=-\"http://localhost:8080/\";\n----var-cmd;\n----var-msg2-=-null;\n----if-(Zone-!==-4)-{\n--------cmd-=-\"cm?sid=\"-+-Zone-+-\"&en=\"-+-msg.payload.Active-+-\"&t=\"-+-duration[Zone];\n----}-else-{\n--------if-(msg.payload.Active-===-1)-{\n------------cmd-=-\"mp?pid=1&uwt=1\";\n--------}-else-{\n------------cmd-=-\"cv?rsn=1\";\n--------}\n--------msg2-=-{\n------------\"payload\":-{\n----------------\"Active\":-msg.payload.Active\n------------},\n------------\"topic\":-String(Zone)\n--------};\n----}\n----return-[{\"url\":-ip-+-cmd},-msg2];\n}\n","outputs":2,"noerr":0,"x":1160,"y":460,"wires":[["73635ba2.3827c4"],["5bf24742.9efdf")},{"id":"73635ba2.3827c4","type":"http request","z":"d58d7d15.df3be8","name":"HTTP command","method":"GET","ret":"obj","paytoqs":false,"url":"","tls":"","proxy":"","authType":"basic","x":1340,"y":440,"wires":[](/NRCHKB/node-red-contrib-homekit-bridged/wiki/)},{"id":"5bf24742.9efdf","type":"link out","z":"d58d7d15.df3be8","name":"Run program","links":["7437d718.0a2d98"],"x":1330,"y":480,"wires":[],"l":true},{"id":"6a8d3ef1.88061","type":"homekit-bridge","z":"","bridgeName":"Garage","pinCode":"111-11-111","port":"","allowInsecureRequest":false,"manufacturer":"Garrett","model":"Pi HAT","serialNo":"3","customMdnsConfig":false,"mdnsMulticast":true,"mdnsInterface":"","mdnsPort":"","mdnsIp":"","mdnsTtl":"","mdnsLoopback":true,"mdnsReuseAddr":true}]
II. Sprinkler with LC Tech 4ch relay (including working timer)
Only default NodeRed modules used!
In this sample only one relay module is used. You should paste flow for each relay (1-4) of your module. Instruction to flash LC Tech ESP8266 modules: Tasmota.
[{"id":"3becee57.bd9272","type":"homekit-service","z":"2d469ba1.82003c","isParent":false,"bridge":"bdd4551c.5849d","parentService":"4fcab8b0.6fe368","name":"Sprinkler1","serviceName":"Valve","topic":"","filter":false,"manufacturer":"ptath","model":"ะ ะพัะพั Irritrol 550","serialNo":"00001","characteristicProperties":"{\n \"ValveType\":\n {\n \"minValue\":1,\n \"maxValue\":1\n },\n \"IsConfigured\":1,\n \"SetDuration\":\n {\n \"minValue\":300,\n \"maxValue\":3600,\n \"validValues\": [300,600,1200,2400,3600]\n }\n}","x":244,"y":288,"wires":["f4c45dca.981af8","8aacc164.a83628"](/NRCHKB/node-red-contrib-homekit-bridged/wiki/"f4c45dca.981af8","8aacc164.a83628")},{"id":"8aacc164.a83628","type":"function","z":"2d469ba1.82003c","name":"Timer Handler","func":"// if timer changes in Home.app, set new duration\n// WARNING!!! this is NOT persistent, settings will gone after nodered restart\n// you should store it somewhere to production use, for example in file or DB\n// or set default timer value in HomeKit node (SetDuration minValue > 0)\n\nvar SetDuration, Valve1 = global.get(\"Valve1\");\n\nif(msg.hap.context !== undefined){\n if (msg.payload.SetDuration) {\n SetDuration = msg.payload.SetDuration; // seconds\n Valve1.SetDuration = SetDuration; // seconds\n global.set(\"Valve1\", Valve1);\n\n node.warn(\"New SetDuration is set: \" + global.get(\"Valve1\").SetDuration)\n }\n}\n\n// no output","outputs":1,"noerr":0,"x":448,"y":256,"wires":[](/NRCHKB/node-red-contrib-homekit-bridged/wiki/)},{"id":"f4c45dca.981af8","type":"function","z":"2d469ba1.82003c","name":"On/Off Handler","func":"var RemainingDuration, newMsg, newpayload = {};\nvar Valve1 = global.get(\"Valve1\");\n\nif (msg.payload.Active === 1){\n\n if (Valve1.SetDuration) { // if duration is set while valve is turning on\n RemainingDuration = Valve1.SetDuration; // payload to HomeKit\n Valve1.StopTimer = Date.now() + RemainingDuration*1000; // milliseconds\n global.set(\"Valve1\", Valve1);\n\n node.warn(\"Turning ON Valve1 with timer \" + RemainingDuration + \" seconds\");\n // first output is MQTT node (Power1 ON), second โ HomeKit node (RemainingDuration)\n return [{\"payload\": 1}, {\"payload\": {\"RemainingDuration\": RemainingDuration}}];\n }\n\n node.warn(\"Turning ON Valve1 with NO timer\");\n return [{\"payload\": 1},null];\n \n} else if (msg.payload.Active === 0) {\n\n node.warn(\"Turning OFF Valve1\");\n return [{\"payload\": 0},null];\n}\n","outputs":2,"noerr":0,"x":448,"y":296,"wires":["309a41fa.97ce0e"],["1418cf19.aab189"](/NRCHKB/node-red-contrib-homekit-bridged/wiki/"309a41fa.97ce0e"],["1418cf19.aab189")},{"id":"309a41fa.97ce0e","type":"mqtt out","z":"2d469ba1.82003c","name":"Valve ON/OFF","topic":"cmnd/watering/POWER1","qos":"2","retain":"","broker":"119575ac.bc37e2","x":688,"y":296,"wires":[]},{"id":"736ec258.c7f4b4","type":"mqtt in","z":"2d469ba1.82003c","name":"Valve STAT","topic":"stat/watering/POWER1","qos":"2","datatype":"auto","broker":"119575ac.bc37e2","x":84,"y":192,"wires":["5547a9f2.837248"](/NRCHKB/node-red-contrib-homekit-bridged/wiki/"5547a9f2.837248")},{"id":"5547a9f2.837248","type":"function","z":"2d469ba1.82003c","name":"State to HomeKit","func":"// pulling state from MQTT to HomeKit\n\nvar newMsg, newpayload = {};\nvar Valve1 = global.get(\"Valve1\");\n\nif (msg.payload == \"ON\"){\n newpayload.InUse = true;\n //newpayload.Active = true;\n Valve1.InUse = true;\n global.set(\"Valve1\", Valve1)\n} else if (msg.payload == \"OFF\") {\n newpayload.InUse = false;\n newpayload.Active = false;\n Valve1.InUse = false;\n global.set(\"Valve1\", Valve1)\n}\n\nnewMsg = { \"payload\": newpayload }\nreturn newMsg;","outputs":1,"noerr":0,"x":458,"y":192,"wires":["3becee57.bd9272"](/NRCHKB/node-red-contrib-homekit-bridged/wiki/"3becee57.bd9272")},{"id":"2f61a5e4.75db3a","type":"link in","z":"2d469ba1.82003c","name":"","links":["1418cf19.aab189","bb840899.f99f8"],"x":119,"y":312,"wires":["3becee57.bd9272"](/NRCHKB/node-red-contrib-homekit-bridged/wiki/"3becee57.bd9272")},{"id":"1418cf19.aab189","type":"link out","z":"2d469ba1.82003c","name":"Timer data","links":["2f61a5e4.75db3a"],"x":623,"y":352,"wires":[]},{"id":"106c6f7c.9b3ae1","type":"inject","z":"2d469ba1.82003c","name":"Timer check","topic":"","payload":"","payloadType":"date","repeat":"1","crontab":"","once":false,"onceDelay":0.1,"x":256,"y":352,"wires":["a317f2c5.adb958"](/NRCHKB/node-red-contrib-homekit-bridged/wiki/"a317f2c5.adb958")},{"id":"a317f2c5.adb958","type":"function","z":"2d469ba1.82003c","name":"Timer OFF Handler","func":"var Valve1 = global.get(\"Valve1\");\n\nif ((global.get(\"Valve1\").StopTimer <= Date.now()) &&\n (global.get(\"Valve1\").InUse === true)) \n {\n node.warn(\"Turning OFF Valve1 by timer\");\n // first output is MQTT, second โ HomeKit\n return [{\"payload\": 0}, {\"payload\": {\"Active\": 0}}];\n} else {\n return [null, null];\n}\n","outputs":2,"noerr":0,"x":458,"y":336,"wires":["309a41fa.97ce0e"],["1418cf19.aab189"](/NRCHKB/node-red-contrib-homekit-bridged/wiki/"309a41fa.97ce0e"],["1418cf19.aab189")},{"id":"bca42b7f.b1e5d","type":"mqtt in","z":"2d469ba1.82003c","name":"Valve TELE","topic":"tele/watering/STATE","qos":"2","datatype":"json","broker":"119575ac.bc37e2","x":84,"y":96,"wires":["84958af.1eaa9f8"](/NRCHKB/node-red-contrib-homekit-bridged/wiki/"84958af.1eaa9f8")},{"id":"84958af.1eaa9f8","type":"change","z":"2d469ba1.82003c","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"POWER1","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":248,"y":144,"wires":["a70a02f2.385c6"](/NRCHKB/node-red-contrib-homekit-bridged/wiki/"a70a02f2.385c6")},{"id":"c70209be.7ddf1","type":"inject","z":"2d469ba1.82003c","name":"Global","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":true,"onceDelay":0.1,"x":74,"y":48,"wires":["cbbaf292.c55eb"](/NRCHKB/node-red-contrib-homekit-bridged/wiki/"cbbaf292.c55eb")},{"id":"cbbaf292.c55eb","type":"function","z":"2d469ba1.82003c","name":"Set global Valve1 (empty)","func":"// global variable Valve1 to store state and settings\n\nvar Valve1 = {};\nglobal.set(\"Valve1\", Valve1);","outputs":1,"noerr":0,"x":278,"y":48,"wires":[](/NRCHKB/node-red-contrib-homekit-bridged/wiki/)},{"id":"a70a02f2.385c6","type":"rbe","z":"2d469ba1.82003c","name":"","func":"rbe","gap":"","start":"","inout":"out","property":"payload","x":354,"y":96,"wires":["5547a9f2.837248"](/NRCHKB/node-red-contrib-homekit-bridged/wiki/"5547a9f2.837248")},{"id":"43304657.98a99","type":"rbe","z":"2d469ba1.82003c","name":"","func":"rbe","gap":"","start":"","inout":"out","property":"payload","x":266,"y":192,"wires":[](/NRCHKB/node-red-contrib-homekit-bridged/wiki/)},{"id":"bdd4551c.5849d","type":"homekit-bridge","z":"","bridgeName":"DRAGON-RED","pinCode":"111-11-111","port":"","allowInsecureRequest":false,"manufacturer":"ptath","model":"Raspberry Pi 3B+","serialNo":"0000","customMdnsConfig":false,"mdnsMulticast":true,"mdnsInterface":"","mdnsPort":"","mdnsIp":"","mdnsTtl":"","mdnsLoopback":true,"mdnsReuseAddr":true},{"id":"119575ac.bc37e2","type":"mqtt-broker","z":"","name":"LOCAL","broker":"192.168.1.10","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthRetain":"false","birthPayload":"","closeTopic":"","closeQos":"0","closeRetain":"false","closePayload":"","willTopic":"","willQos":"0","willRetain":"false","willPayload":""}]
III. Sprinkler using a simple outlet (e.g. Philips Hue)
- Duration is configurable and remaining duration time will be displayed in the Home App.
- Implementation in a simple loop
- My Osram Smart Plug attached to Philips Hue Bridge can be controlled by boolean characteristic "On", for other characteristics change function nodes as required
- Configure default duration (used each time after relaunching Node-red) in "Init" node
- Configure min/max and step characteristics in "Irrigation" node
[{"id":"28e78105.d1c456","type":"tab","label":"Irrigation","disabled":false,"info":""},{"id":"f02d025d.ae73d8","type":"homekit-service","z":"28e78105.d1c456","isParent":true,"bridge":"d18fb229.b6994","accessoryCategory":"SPRINKLER","parentService":"","name":"Irrigation","serviceName":"Valve","topic":"","filter":false,"manufacturer":"Default Manufacturer","model":"Default Model","serialNo":"Default Serial Number","cameraConfigVideoProcessor":"","cameraConfigSource":"","cameraConfigStillImageSource":"","cameraConfigMaxStreams":"","cameraConfigMaxWidth":"","cameraConfigMaxHeight":"","cameraConfigMaxFPS":"","cameraConfigMaxBitrate":"","cameraConfigVideoCodec":"","cameraConfigAudioCodec":"","cameraConfigAudio":false,"cameraConfigPacketSize":"","cameraConfigVerticalFlip":false,"cameraConfigHorizontalFlip":false,"cameraConfigMapVideo":"","cameraConfigMapAudio":"","cameraConfigVideoFilter":"","cameraConfigAdditionalCommandLine":"","cameraConfigDebug":false,"characteristicProperties":"{\n\"SetDuration\": {\n \"maxValue\":7200,\n \"minValue\":300,\n \"minStep\" :300\n }\n}","x":280,"y":200,"wires":["2a837370.d0b1d4"],[]]},{"id":"2a837370.d0b1d4","type":"function","z":"28e78105.d1c456","name":"Active2On","func":"if (\"SetDuration\" in msg.payload){\n flow.set(\"Duration\",msg.payload.SetDuration);\n}\n\nif (\"Active\" in msg.payload){\n return {\"payload\": {\"on\":msg.payload.Active}}\n}\nelse\n return null","outputs":1,"noerr":0,"x":450,"y":200,"wires":[["e9d2ec48.fa96c8"]]},{"id":"e9d2ec48.fa96c8","type":"hue-light","z":"28e78105.d1c456","name":"Outlet","bridge":"c590a68c.ba7cc","lightid":"12","colornamer":false,"x":610,"y":200,"wires":[["45dd146e.32be3c"]],"icon":"node-red/cog.png"},{"id":"45dd146e.32be3c","type":"trigger","z":"28e78105.d1c456","op1":"","op2":"0","op1type":"pay","op2type":"str","duration":"-10","extend":false,"units":"s","reset":"","bytopic":"all","name":"","x":790,"y":200,"wires":[["a828f8d7.85d198"]]},{"id":"363b177b.58b9","type":"inject","z":"28e78105.d1c456","name":"Init","topic":"","payload":"{\"SetDuration\": 1800, \"ValveType\":1, \"Active\":false}","payloadType":"json","repeat":"","crontab":"","once":true,"onceDelay":0.1,"x":130,"y":120,"wires":[["f02d025d.ae73d8"]]},{"id":"a828f8d7.85d198","type":"function","z":"28e78105.d1c456","name":"Update Time","func":"\nvar DURATION = flow.get(\"Duration\");\nvar WateringEndTime = context.get(\"WateringEndTime\")](/NRCHKB/node-red-contrib-homekit-bridged/wiki/|0;\nvar-RemainingDuration-=-0\n\nif-(msg.payload.on)-{\n//Just-switched-on-?----\n--if-(WateringEndTime-===--0)-{\n----WateringEndTime-=-new-Date(Date.now()-+-DURATION-*-1000)-\n----RemainingDuration--=-DURATION;\n--}-else-{\n//-Still-switched-on-?-Update-RemainingDuration-----\n----RemainingDuration-=-(WateringEndTime---Date.now())-/-1000\n//-WateringEndTime-reached-?-Switch-off\n----if-(RemainingDuration-<=-0)-{\n------WateringEndTime-=-0;\n------msg.payload.on--=-false;\n----}\n--}\n}-else-{\n//-Just-switched-off-or-still-off-?\n--RemainingDuration-=-0;\n--WateringEndTime---=-0;\n}\n\ncontext.set(\"WateringEndTime\",-WateringEndTime);\n\nreturn-{\n----\"payload\":-{\"InUse\"------------:-msg.payload.on-?-1-:-0,\n----------------\"Active\"-----------:-msg.payload.on-?-1-:-0,\n----------------\"RemainingDuration\":-RemainingDuration-}\n----\n};","outputs":1,"noerr":0,"x":110,"y":200,"wires":[["f02d025d.ae73d8")},{"id":"d18fb229.b6994","type":"homekit-bridge","z":"","bridgeName":"Node-Red","pinCode":"111-11-111","port":"","allowInsecureRequest":false,"manufacturer":"Default Manufacturer","model":"Default Model","serialNo":"Default Serial Number","customMdnsConfig":false,"mdnsMulticast":true,"mdnsInterface":"","mdnsPort":"","mdnsIp":"","mdnsTtl":"","mdnsLoopback":true,"mdnsReuseAddr":true,"allowMessagePassthrough":true},{"id":"c590a68c.ba7cc","type":"hue-bridge","z":"","name":"Andreas Hue","bridge":"Andreas-hue.local","key":"IkVE3KKWgDVmXB4FNu15AOSIpJMEPpp9gj2jDB-G","interval":"1000"}]