SergiuToporjinschi/node-red-contrib-heater-controller

View on GitHub
nodes/heater/FlowExamples.md

Summary

Maintainability
Test Coverage
#### [Exception examples](#Exception)
#### [Setting current temperature](#CurrentTemp)
#### [Change user settings via input messages](#userSettings)
### <a name="Exception"></a> Exception tests
```JSON
[{"id":"996f7038.9f7fe","type":"group","z":"9f075ea8.007b5","name":"Exceptions","style":{"label":true,"fill":"#d1d1d1","fill-opacity":"0.76","stroke":"#ff0000","color":"#ff0000"},"nodes":["abf89762.4ac078","429ffd9c.08b504","5a889a37.766e64","6dde0510.1a4e5c","7986b9fc.2bc868","981b12b2.41755","2cb8a206.8a984e","6f2515b0.5d239c","c2423493.0d9f78","2c4ac85.1aec938","6ab62e66.758b6","d6da7c0b.4e629","c73c4593.f7f388"],"x":34,"y":19,"w":852,"h":322},{"id":"abf89762.4ac078","type":"debug","z":"9f075ea8.007b5","g":"996f7038.9f7fe","name":"Heater Status","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":760,"y":160,"wires":[]},{"id":"429ffd9c.08b504","type":"inject","z":"9f075ea8.007b5","g":"996f7038.9f7fe","name":"curentTemp String","props":[{"p":"topic","vt":"str"},{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"currentTemp","payload":"str","payloadType":"str","x":170,"y":60,"wires":[["5a889a37.766e64"]]},{"id":"5a889a37.766e64","type":"ui_heater_controller","z":"9f075ea8.007b5","g":"996f7038.9f7fe","name":"Heater throws exceptions","group":"add64240.8d8c9","unit":"C","displayMode":"buttons","order":0,"width":6,"height":4,"topic":"heaterStatus","title":"Heater","logLengthType":"days","logLength":1,"sliderMinValue":10,"sliderMaxValue":35,"sliderStep":0.5,"threshold":0.5,"calendar":"{\n    \"Monday\": {\n        \"00:00\": 19,\n        \"06:20\": 22,\n        \"08:00\": 19,\n        \"16:40\": 22,\n        \"23:59\": 19\n    },\n    \"Tuesday\": {\n        \"00:00\": 19,\n        \"06:20\": 22,\n        \"08:00\": 19,\n        \"16:40\": 22,\n        \"23:59\": 19\n    },\n    \"Wednesday\": {\n        \"00:00\": 19,\n        \"06:20\": 22,\n        \"08:00\": 19,\n        \"16:40\": 22,\n        \"23:59\": 19\n    },\n    \"Thursday\": {\n        \"00:00\": 19,\n        \"06:20\": 22,\n        \"08:00\": 19,\n        \"16:40\": 22,\n        \"23:59\": 19\n    },\n    \"Friday\": {\n        \"00:00\": 19,\n        \"06:20\": 23,\n        \"08:00\": 19,\n        \"16:40\": 22,\n        \"23:59\": 19\n    },\n    \"Saturday\": {\n        \"00:00\": 19,\n        \"08:00\": 20,\n        \"20:00\": 22,\n        \"23:59\": 19\n    },\n    \"Sunday\": {\n        \"00:00\": 19,\n        \"08:00\": 20,\n        \"20:00\": 22,\n        \"23:59\": 19\n    }\n}","x":510,"y":180,"wires":[["abf89762.4ac078"],["6dde0510.1a4e5c"]],"outputLabels":["Heater status","Info"]},{"id":"6dde0510.1a4e5c","type":"debug","z":"9f075ea8.007b5","g":"996f7038.9f7fe","name":"Node Status","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":770,"y":200,"wires":[]},{"id":"7986b9fc.2bc868","type":"catch","z":"9f075ea8.007b5","g":"996f7038.9f7fe","name":"","scope":["5a889a37.766e64"],"uncaught":false,"x":450,"y":240,"wires":[["981b12b2.41755"]]},{"id":"981b12b2.41755","type":"debug","z":"9f075ea8.007b5","g":"996f7038.9f7fe","name":"Error messages","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":760,"y":240,"wires":[]},{"id":"2cb8a206.8a984e","type":"comment","z":"9f075ea8.007b5","g":"996f7038.9f7fe","name":"Doc","info":"# This should group is testing exception handling:\n  \n    - Every injected message from this group has to return an exception;\n    - All exceptions should be caught by the catch node","x":750,"y":60,"wires":[]},{"id":"6f2515b0.5d239c","type":"inject","z":"9f075ea8.007b5","g":"996f7038.9f7fe","name":"curentTemp Boolean","props":[{"p":"topic","vt":"str"},{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"currentTemp","payload":"true","payloadType":"bool","x":170,"y":100,"wires":[["5a889a37.766e64"]]},{"id":"c2423493.0d9f78","type":"inject","z":"9f075ea8.007b5","g":"996f7038.9f7fe","name":"curentTemp Object","props":[{"p":"topic","vt":"str"},{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"currentTemp","payload":"{\"test\":\"ss\"}","payloadType":"json","x":170,"y":140,"wires":[["5a889a37.766e64"]]},{"id":"2c4ac85.1aec938","type":"inject","z":"9f075ea8.007b5","g":"996f7038.9f7fe","name":"userConfig String","props":[{"p":"topic","vt":"str"},{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"userConfig","payload":"s","payloadType":"str","x":160,"y":180,"wires":[["5a889a37.766e64"]]},{"id":"6ab62e66.758b6","type":"inject","z":"9f075ea8.007b5","g":"996f7038.9f7fe","name":"userConfig Number","props":[{"p":"topic","vt":"str"},{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"userConfig","payload":"3","payloadType":"num","x":170,"y":220,"wires":[["5a889a37.766e64"]]},{"id":"d6da7c0b.4e629","type":"inject","z":"9f075ea8.007b5","g":"996f7038.9f7fe","name":"userConfig Boolean","props":[{"p":"topic","vt":"str"},{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"userConfig","payload":"true","payloadType":"bool","x":170,"y":260,"wires":[["5a889a37.766e64"]]},{"id":"c73c4593.f7f388","type":"inject","z":"9f075ea8.007b5","g":"996f7038.9f7fe","name":"userConfig Empty Obj","props":[{"p":"topic","vt":"str"},{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"userConfig","payload":"{}","payloadType":"json","x":180,"y":300,"wires":[["5a889a37.766e64"]]},{"id":"add64240.8d8c9","type":"ui_group","name":"Devices","tab":"b94da3c8.213ed","order":1,"disp":true,"width":"8","collapse":false},{"id":"b94da3c8.213ed","type":"ui_tab","name":"Tab 1","icon":"dashboard","order":1,"disabled":false,"hidden":false}]
```

### <a name="CurrentTemp"></a> Setting current temperature
```JSON
[{"id":"9cb8c092.e091a","type":"group","z":"9f075ea8.007b5","name":"Setting current temperature","style":{"label":true,"fill":"#c8e7a7","fill-opacity":"0.76","stroke":"#000000","color":"#000000"},"nodes":["4f8a40e9.13dd5","4b92cb31.f4b2b4","21cdb04c.88a56","4144f456.f62f1c","ec02fb19.2b1ba8","bb62c62c.8ddd28","4448f427.0d7c1c","9ae49c58.e2ad1","b943a634.050568"],"x":34,"y":359,"w":852,"h":222},{"id":"4f8a40e9.13dd5","type":"debug","z":"9f075ea8.007b5","g":"9cb8c092.e091a","name":"Heater Status","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":760,"y":460,"wires":[]},{"id":"4b92cb31.f4b2b4","type":"inject","z":"9f075ea8.007b5","g":"9cb8c092.e091a","name":"curentTemp -10 C","props":[{"p":"topic","vt":"str"},{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"currentTemp","payload":"-10","payloadType":"num","x":170,"y":440,"wires":[["21cdb04c.88a56"]]},{"id":"21cdb04c.88a56","type":"ui_heater_controller","z":"9f075ea8.007b5","g":"9cb8c092.e091a","name":"Heater setting currentTemp","group":"add64240.8d8c9","unit":"C","displayMode":"buttons","order":0,"width":6,"height":4,"topic":"heaterStatus","title":"Heater","logLengthType":"days","logLength":1,"sliderMinValue":10,"sliderMaxValue":35,"sliderStep":0.5,"threshold":0.5,"calendar":"{\n    \"Monday\": {\n        \"00:00\": 19,\n        \"06:20\": 22,\n        \"08:00\": 19,\n        \"16:40\": 22,\n        \"23:59\": 19\n    },\n    \"Tuesday\": {\n        \"00:00\": 19,\n        \"06:20\": 22,\n        \"08:00\": 19,\n        \"16:40\": 22,\n        \"23:59\": 19\n    },\n    \"Wednesday\": {\n        \"00:00\": 19,\n        \"06:20\": 22,\n        \"08:00\": 19,\n        \"16:40\": 22,\n        \"23:59\": 19\n    },\n    \"Thursday\": {\n        \"00:00\": 19,\n        \"06:20\": 22,\n        \"08:00\": 19,\n        \"16:40\": 22,\n        \"23:59\": 19\n    },\n    \"Friday\": {\n        \"00:00\": 19,\n        \"06:20\": 23,\n        \"08:00\": 19,\n        \"16:40\": 22,\n        \"23:59\": 19\n    },\n    \"Saturday\": {\n        \"00:00\": 19,\n        \"08:00\": 20,\n        \"20:00\": 22,\n        \"23:59\": 19\n    },\n    \"Sunday\": {\n        \"00:00\": 19,\n        \"08:00\": 20,\n        \"20:00\": 22,\n        \"23:59\": 19\n    }\n}","x":520,"y":480,"wires":[["4f8a40e9.13dd5"],["4144f456.f62f1c"]],"outputLabels":["Heater status","Info"]},{"id":"4144f456.f62f1c","type":"debug","z":"9f075ea8.007b5","g":"9cb8c092.e091a","name":"Node Status","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":770,"y":500,"wires":[]},{"id":"ec02fb19.2b1ba8","type":"catch","z":"9f075ea8.007b5","g":"9cb8c092.e091a","name":"","scope":["21cdb04c.88a56"],"uncaught":false,"x":450,"y":540,"wires":[["bb62c62c.8ddd28"]]},{"id":"bb62c62c.8ddd28","type":"debug","z":"9f075ea8.007b5","g":"9cb8c092.e091a","name":"Error messages","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":760,"y":540,"wires":[]},{"id":"4448f427.0d7c1c","type":"comment","z":"9f075ea8.007b5","g":"9cb8c092.e091a","name":"Doc","info":"**Shows how the current temperature is set.**\n    \n    This \"msg\" should come, from time to time, from some temperature sensor;\n    \n**Actions**:\n * recompute the heater status and output's the value on the first output link;\n    *   _topic_:  the value set as topic in heater properties;\n    *   _payload_: [\\<on>,\\<off>] **on** if heater should be on, **off** if the heater should be off\n  \n \n ","x":750,"y":400,"wires":[]},{"id":"9ae49c58.e2ad1","type":"inject","z":"9f075ea8.007b5","g":"9cb8c092.e091a","name":"curentTemp 0 C","props":[{"p":"topic","vt":"str"},{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"currentTemp","payload":"0","payloadType":"num","x":160,"y":480,"wires":[["21cdb04c.88a56"]]},{"id":"b943a634.050568","type":"inject","z":"9f075ea8.007b5","g":"9cb8c092.e091a","name":"curentTemp +10 C","props":[{"p":"topic","vt":"str"},{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"currentTemp","payload":"10","payloadType":"num","x":170,"y":520,"wires":[["21cdb04c.88a56"]]},{"id":"add64240.8d8c9","type":"ui_group","name":"Devices","tab":"b94da3c8.213ed","order":1,"disp":true,"width":"8","collapse":false},{"id":"b94da3c8.213ed","type":"ui_tab","name":"Tab 1","icon":"dashboard","order":1,"disabled":false,"hidden":false}]
```

### <a name="userSettings"></a> Change user settings via input messages
```JSON
[{"id":"7f681af9.79b564","type":"group","z":"9f075ea8.007b5","name":"Setting user configuration","style":{"label":true,"fill":"#c8e7a7","fill-opacity":"0.76","stroke":"#000000","color":"#000000"},"nodes":["63465299.6a01cc","9282bd1d.c7742","5ca20f5b.708e2","34ad27f5.e73838","bda17bab.9f2c98","71b89ff1.f7556","4128a31b.2119fc","e8f94792.132f18","e11dd3fd.1ea46","6baad334.9e717c","42639604.8f6bc8"],"x":34,"y":599,"w":852,"h":242},{"id":"63465299.6a01cc","type":"debug","z":"9f075ea8.007b5","g":"7f681af9.79b564","name":"Heater Status","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":760,"y":700,"wires":[]},{"id":"9282bd1d.c7742","type":"inject","z":"9f075ea8.007b5","g":"7f681af9.79b564","name":"userConfig isLocked:true","props":[{"p":"topic","vt":"str"},{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"userConfig","payload":"{\"isLocked\":true}","payloadType":"json","x":190,"y":680,"wires":[["5ca20f5b.708e2"]]},{"id":"5ca20f5b.708e2","type":"ui_heater_controller","z":"9f075ea8.007b5","g":"7f681af9.79b564","name":"Heater setting userConfig","group":"add64240.8d8c9","unit":"C","displayMode":"buttons","order":0,"width":6,"height":4,"topic":"heaterStatus","title":"Heater","logLengthType":"days","logLength":1,"sliderMinValue":10,"sliderMaxValue":35,"sliderStep":0.5,"threshold":0.5,"calendar":"{\n    \"Monday\": {\n        \"00:00\": 19,\n        \"06:20\": 22,\n        \"08:00\": 19,\n        \"16:40\": 22,\n        \"23:59\": 19\n    },\n    \"Tuesday\": {\n        \"00:00\": 19,\n        \"06:20\": 22,\n        \"08:00\": 19,\n        \"16:40\": 22,\n        \"23:59\": 19\n    },\n    \"Wednesday\": {\n        \"00:00\": 19,\n        \"06:20\": 22,\n        \"08:00\": 19,\n        \"16:40\": 22,\n        \"23:59\": 19\n    },\n    \"Thursday\": {\n        \"00:00\": 19,\n        \"06:20\": 22,\n        \"08:00\": 19,\n        \"16:40\": 22,\n        \"23:59\": 19\n    },\n    \"Friday\": {\n        \"00:00\": 19,\n        \"06:20\": 23,\n        \"08:00\": 19,\n        \"16:40\": 22,\n        \"23:59\": 19\n    },\n    \"Saturday\": {\n        \"00:00\": 19,\n        \"08:00\": 20,\n        \"20:00\": 22,\n        \"23:59\": 19\n    },\n    \"Sunday\": {\n        \"00:00\": 19,\n        \"08:00\": 20,\n        \"20:00\": 22,\n        \"23:59\": 19\n    }\n}","x":510,"y":720,"wires":[["63465299.6a01cc"],["34ad27f5.e73838"]],"outputLabels":["Heater status","Info"]},{"id":"34ad27f5.e73838","type":"debug","z":"9f075ea8.007b5","g":"7f681af9.79b564","name":"NodeStatus","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":770,"y":740,"wires":[]},{"id":"bda17bab.9f2c98","type":"catch","z":"9f075ea8.007b5","g":"7f681af9.79b564","name":"","scope":["5ca20f5b.708e2"],"uncaught":false,"x":450,"y":780,"wires":[["71b89ff1.f7556"]]},{"id":"71b89ff1.f7556","type":"debug","z":"9f075ea8.007b5","g":"7f681af9.79b564","name":"Error messages","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":760,"y":780,"wires":[]},{"id":"4128a31b.2119fc","type":"comment","z":"9f075ea8.007b5","g":"7f681af9.79b564","name":"Doc","info":"**Shows how user settings can be changed via messages**\n    \n    All interface actions can be done via message with topic \"userConfig\"\n    \n**Actions**:\n * Sets the user specific value;\n * Triggers recomputation of heater status and output the new calculated value **if there was at least one previously `currentTemp` message received**;\n * `userConfig` message following format:\n````\n{\n    topic: 'userConfig', \n    payload: {\n        [isLocked: <<true> | <false>>],\n        [isUserCustom: <<true> | <false>>],\n        [userTargetValue: <number>]\n    }\n}\n````\n    * `isLocked` - similar with pressing padlock icon in interface. If it's true, blocks the current target temperature (`status.currentTargetValue`) to a specific value and it can be changed only by user.\n        *  `true` - locks a target value;\n        *  `false` - unlocks a target value;\n    * `isUserCustom` - is set automatically on `true` if the user has changed the target value; even if is not specified in the incoming message;\n        *  `true` - is setting current target value as a user target value and locks this value until the next schedule changes the value;\n        *  `false` - resets the user target value with te current scheduled value;\n    * `userTargetValue` - user desired target value;\n    ","x":770,"y":640,"wires":[]},{"id":"e8f94792.132f18","type":"inject","z":"9f075ea8.007b5","g":"7f681af9.79b564","name":"curentTemp +10 C","props":[{"p":"topic","vt":"str"},{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"currentTemp","payload":"10","payloadType":"num","x":170,"y":640,"wires":[["5ca20f5b.708e2"]]},{"id":"e11dd3fd.1ea46","type":"inject","z":"9f075ea8.007b5","g":"7f681af9.79b564","name":"userConfig userTargetValue: 22","props":[{"p":"topic","vt":"str"},{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"userConfig","payload":"{\"userTargetValue\":22}","payloadType":"json","x":210,"y":720,"wires":[["5ca20f5b.708e2"]]},{"id":"6baad334.9e717c","type":"inject","z":"9f075ea8.007b5","g":"7f681af9.79b564","name":"userConfig isUserCustom:false","props":[{"p":"topic","vt":"str"},{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"userConfig","payload":"{\"isUserCustom\":false}","payloadType":"json","x":210,"y":800,"wires":[["5ca20f5b.708e2"]]},{"id":"42639604.8f6bc8","type":"inject","z":"9f075ea8.007b5","g":"7f681af9.79b564","name":"curentTemp +25 C","props":[{"p":"topic","vt":"str"},{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"currentTemp","payload":"25","payloadType":"num","x":170,"y":760,"wires":[["5ca20f5b.708e2"]]},{"id":"add64240.8d8c9","type":"ui_group","name":"Devices","tab":"b94da3c8.213ed","order":1,"disp":true,"width":"8","collapse":false},{"id":"b94da3c8.213ed","type":"ui_tab","name":"Tab 1","icon":"dashboard","order":1,"disabled":false,"hidden":false}]
```