Created
August 11, 2016 18:54
Revisions
-
dsample created this gist
Aug 11, 2016 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1 @@ These Node-RED snippets accompany a blog post I wrote about using Docker and Node-RED on a Raspberry Pi to integrate IoT devices. This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1 @@ [{"id":"dd16f3d4.7795e","type":"inject","z":"b49e686d.c857c8","name":"Every 10s","topic":"","payload":"","payloadType":"date","repeat":"10","crontab":"","once":true,"x":110,"y":80,"wires":[["d37e6bf0.74ce18"]]},{"id":"cd44f2a5.b6f8e","type":"debug","z":"b49e686d.c857c8","name":"Bean temperature","active":false,"console":"false","complete":"payload","x":470,"y":140,"wires":[]},{"id":"d37e6bf0.74ce18","type":"bean temp","z":"b49e686d.c857c8","name":"","bean":"d17079df.e56568","x":270,"y":80,"wires":[["f846914.242427","cd44f2a5.b6f8e"]]},{"id":"f846914.242427","type":"change","z":"b49e686d.c857c8","name":"Set global temperature","rules":[{"t":"set","p":"temperature","pt":"global","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":480,"y":80,"wires":[[]]},{"id":"98c0da10.f54358","type":"http in","z":"b49e686d.c857c8","name":"","url":"/temperature","method":"get","swaggerDoc":"","x":110,"y":200,"wires":[["7e698a1d.2a95f4"]]},{"id":"2087e768.6f4de8","type":"http response","z":"b49e686d.c857c8","name":"","x":490,"y":200,"wires":[]},{"id":"7e698a1d.2a95f4","type":"change","z":"b49e686d.c857c8","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"temperature","tot":"global"}],"action":"","property":"","from":"","to":"","reg":false,"x":320,"y":200,"wires":[["2087e768.6f4de8"]]},{"id":"d17079df.e56568","type":"bean","z":"b49e686d.c857c8","name":"Bean","uuid":"","connectiontype":"timeout","connectiontimeout":"60"}] This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1 @@ [{"id":"22fad46.782fe2c","type":"function","z":"9da55e76.1dad7","name":"Owl Electricity Reading","func":"var elec = msg.payload['electricity']\n\nvar reading = {\n type: 'electricity',\n meta: {\n id: elec['$']['id'],\n signal: {\n rssi: elec['signal'][0]['$']['rssi'],\n lqi: elec['signal'][0]['$']['lqi']\n },\n battery: {\n units: \"percentage\",\n value: parseFloat(elec['battery'][0]['$']['level'])\n }\n },\n reading: {\n current: {\n units: elec['chan'][0]['curr'][0]['$']['units'],\n quantity: elec['chan'][0]['curr'][0]['_']\n },\n day: {\n units: elec['chan'][0]['day'][0]['$']['units'],\n quantity: elec['chan'][0]['day'][0]['_']\n }\n }\n}\n\nmsg.payload = reading\nreturn msg;","outputs":1,"noerr":0,"x":770,"y":140,"wires":[["699ff9f6.da7598","9ad9c425.e18c48","875ecb74.7e1cb8"]]},{"id":"699ff9f6.da7598","type":"debug","z":"9da55e76.1dad7","name":"Electricity","active":false,"console":"false","complete":"payload","x":980,"y":120,"wires":[]},{"id":"88184e44.ed9c5","type":"switch","z":"9da55e76.1dad7","name":"Which data?","property":"topic","propertyType":"msg","rules":[{"t":"eq","v":"electricity","vt":"str"},{"t":"eq","v":"heating","vt":"str"}],"checkall":"true","outputs":2,"x":570,"y":160,"wires":[["22fad46.782fe2c"],["c8f836fa.415568"]]},{"id":"d59010b1.8dc31","type":"function","z":"9da55e76.1dad7","name":"Set topic","func":"var readingType = Object.keys(msg.payload)[0]\nmsg.topic = readingType.toLowerCase()\nreturn msg;","outputs":1,"noerr":0,"x":420,"y":160,"wires":[["88184e44.ed9c5"]]},{"id":"c8f836fa.415568","type":"function","z":"9da55e76.1dad7","name":"Owl Heating Reading","func":"var heat = msg.payload['heating']\n\nvar reading = {\n type: 'heating',\n timestamp: parseInt(heat['timestamp'][0]),\n meta: {\n id: heat['$']['id'],\n version: heat['$']['ver']\n },\n zones: heat['zones'].map(mapZone)\n}\n\nfunction mapZone(zone) {\n var z = zone['zone'][0]\n var t = z['temperature'][0]\n\n var states = {\n \"0\": {\n code: 0,\n mode: \"standby\",\n desc: \"Standby\"\n },\n \"1\": {\n code: 1,\n mode: \"comfort\",\n desc: \"Comfort (Running)\"\n },\n \"4\": {\n code: 4,\n mode: \"comfort\",\n desc: \"Comfort (Up To Temperature)\"\n },\n \"5\": {\n code: 5,\n mode: \"comfort\",\n desc: \"Comfort (Warm Up)\"\n },\n \"6\": {\n code: 6,\n mode: \"comfort\",\n desc: \"Comfort (Cool Down)\"\n },\n \"7\": {\n code: 7,\n mode: \"standby\",\n desc: \"Standby (Running)\"\n }\n }\n \n return {\n meta: {\n zone: t['$']['zone'],\n id: z['$']['id'],\n secondsSinceLastReport: z['$']['last'],\n signal: {\n rssi: z['signal'][0]['$']['rssi'],\n lqi: z['signal'][0]['$']['lqi']\n },\n battery: {\n units: \"millivolts\",\n value: parseInt(z['battery'][0]['$']['level'])\n },\n configurationPending: z['conf'][0]['$']['flags']\n },\n reading: {\n state: states[t['$']['state']],\n stateUntil: parseInt(t['$']['until']),\n temperature: {\n current: parseFloat(t['current'][0]),\n required: parseFloat(t['required'][0])\n }\n }\n }\n}\n\nmsg.payload = reading\nreturn msg;","outputs":1,"noerr":0,"x":760,"y":180,"wires":[["23295f11.7ca7a","cfe098a.3826868","875ecb74.7e1cb8"]]},{"id":"79b09cef.986794","type":"xml","z":"9da55e76.1dad7","name":"","attr":"","chr":"","x":290,"y":160,"wires":[["d59010b1.8dc31"]]},{"id":"e06743a2.f8f03","type":"udp in","z":"9da55e76.1dad7","name":"Network Owl","iface":"0.0.0.0","port":"22600","ipv":"udp4","multicast":"true","group":"224.192.32.19","datatype":"utf8","x":130,"y":160,"wires":[["79b09cef.986794"]]},{"id":"1ca5598.e2281a7","type":"mqtt out","z":"9da55e76.1dad7","name":"","topic":"","qos":"0","retain":"false","broker":"a36924fc.2a0ba8","x":1170,"y":160,"wires":[]},{"id":"23295f11.7ca7a","type":"debug","z":"9da55e76.1dad7","name":"Heating","active":false,"console":"false","complete":"payload","x":980,"y":200,"wires":[]},{"id":"875ecb74.7e1cb8","type":"change","z":"9da55e76.1dad7","name":"Add topic prefix","rules":[{"t":"change","p":"topic","pt":"msg","from":"(.*)","fromt":"re","to":"home/$1","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1000,"y":160,"wires":[["1ca5598.e2281a7"]]},{"id":"c2571003.78cca","type":"influxdb out","z":"9da55e76.1dad7","influxdb":"53f5b97b.821568","name":"Heating","measurement":"home.heating","x":1220,"y":240,"wires":[]},{"id":"2bbe4125.4cb6ee","type":"debug","z":"9da55e76.1dad7","name":"H Metric","active":false,"console":"false","complete":"payload","x":1220,"y":280,"wires":[]},{"id":"cfe098a.3826868","type":"function","z":"9da55e76.1dad7","name":"Heating measurement","func":"msg.payload = [\n {\n time: msg.payload.timestamp * 1000,\n currentTemperature: msg.payload.zones[0].reading.temperature.current,\n requiredTemperature: msg.payload.zones[0].reading.temperature.required,\n batteryMillivolts: msg.payload.zones[0].meta.battery.value\n },\n {\n stateCode: msg.payload.zones[0].reading.state.code,\n stateMode: msg.payload.zones[0].reading.state.mode,\n stateDesc: msg.payload.zones[0].reading.state.desc\n }\n]\n\nreturn msg;","outputs":1,"noerr":0,"x":1020,"y":240,"wires":[["2bbe4125.4cb6ee","c2571003.78cca"]]},{"id":"9ad9c425.e18c48","type":"function","z":"9da55e76.1dad7","name":"Electricity Measurement","func":"msg.payload = {\n time: Date.now(),\n currentUsageWatts: parseFloat(msg.payload.reading.current.quantity),\n todayUsageWattHours: parseFloat(msg.payload.reading.day.quantity),\n batteryPercentage: msg.payload.meta.battery.value\n}\n\nreturn msg;","outputs":1,"noerr":0,"x":1030,"y":80,"wires":[["cebbd57a.9af128","7a170c75.896464"]]},{"id":"cebbd57a.9af128","type":"debug","z":"9da55e76.1dad7","name":"E Metric","active":false,"console":"false","complete":"payload","x":1220,"y":40,"wires":[]},{"id":"7a170c75.896464","type":"influxdb out","z":"9da55e76.1dad7","influxdb":"53f5b97b.821568","name":"Electricity","measurement":"home.electricity","x":1220,"y":80,"wires":[]},{"id":"a36924fc.2a0ba8","type":"mqtt-broker","z":"","broker":"localhost","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"willTopic":"","willQos":"0","willPayload":"","birthTopic":"","birthQos":"0","birthPayload":""},{"id":"53f5b97b.821568","type":"influxdb","z":"","hostname":"127.0.0.1","port":"8086","database":"home","name":"Home"}]