Simulation - cflurin/node-red-contrib-ramp-thermostat GitHub Wiki

This flow simulates the temperature trend depending on the profile and the time for a day period. It also uses the hysteresis setting to avoid frequently turning on/off.

Note: you need to install node-red-dashboard and node-red-contrib-dsm

The charts data are persistent, see also: Persist-chart-data-over-Node-Red-restart

simulation

charts

Flow

[{"id":"b09105b7.1e7b68","type":"ramp-thermostat","z":"6da90f72.dff58","name":"office","profile":"456075b4.05240c","hysteresisplus":"0.5","hysteresisminus":"0.5","x":150,"y":520,"wires":["3fca2077.558f2","d3cc1e06.7017d"],["7ac01db5.679c94"],["7ac01db5.679c94"]]},{"id":"7ac01db5.679c94","type":"ui_chart","z":"6da90f72.dff58","name":"office","group":"c72a8a5.c6a7378","order":1,"width":"0","height":"0","label":"office","chartType":"line","legend":"false","xformat":"HH:mm","interpolate":"linear","nodata":"","dot":false,"ymin":"","ymax":"","removeOlder":1,"removeOlderPoints":"","removeOlderUnit":"86400","cutout":"","useOneColor":false,"colors":["#1f77b4","#ff7f0e","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"useOldStyle":false,"x":410,"y":620,"wires":[["cfeebc0.b0fbc48"],[]]},{"id":"3fca2077.558f2","type":"dsm","z":"6da90f72.dff58","name":"simulation","sm_config":"{\n    \"currentState\": \"off\",\n    \"states\": {\n        \"off\": {\n            \"start\": \"on\"\n        },\n        \"on\": {\n            \"stop\": \"off\"\n        }\n    },\n    \"data\": {\n        \"temp_init\": 20.0,\n        \"inc\": 0.05,\n        \"dec\": 0.01,\n        \"interval\": 60\n    },\n    \"methods\": {\n        \"init\": [\n            \"sm.calc_current = function(msg) {\",\n            \"   if (msg.payload) {\",\n            \"       sm.current += Math.random() * sm.data.inc;\",\n            \"       sm.fill = 'yellow';\",\n            \"   } else {\",\n            \"       sm.current -= Math.random() * sm.data.dec;\",\n            \"       sm.fill = 'blue';\",\n            \"   }\",\n            \"   sm.current = Math.round(sm.current * 100) / 100;\",\n            \"   context.set('current', sm.current);\",\n            \"   context.set('state', msg.payload);\",\n            \"   sm.text = sm.current;\",\n            \"}\"\n        ],\n\t\t\"start\": [\n\t\t    \"msg.payload = context.get('state') ](/cflurin/node-red-contrib-ramp-thermostat/wiki/|-false;\",\n\t\t----\"sm.current-=-context.get('current')-||-sm.data.temp_init;\",\n------------\"sm.fill-=-'green';\",\n\t\t----\"sm.text-=-'interval-'-+-sm.data.interval;\",\n\t\t----\"resume('state',-msg);\"\n\t\t],\n\t\t\"stop\":-[\n\t\t----\"clearTimeout(timeout.interval);\",\n\t\t----\"sm.fill-=-'grey';\",\n\t\t----\"sm.text-=-'off';\",\n\t\t----\"output-=-false;\"\n\t\t],\n--------\"state\":-[\n------------\"timeout.interval-=-setTimeout(function()-{\",\n------------\"---sm.calc_current(msg);\",\n------------\"---msg.topic-=-'setCurrent';\",\n------------\"---msg.payload-=-sm.current;\",\n------------\"---node.send(msg);\",\n------------\"},-sm.data.interval*1000);\"\n--------],\n--------\"status\":-{\n------------\"fill\":-{\n----------------\"get\":-\"sm.fill-||-'grey';\"\n------------},\n------------\"shape\":-\"dot\",\n------------\"text\":-{\n----------------\"get\":-\"sm.text-||-'off';\"\n------------}\n--------}\n----}\n}","x":430,"y":360,"wires":[["b09105b7.1e7b68")},{"id":"ce92d198.0c2ce","type":"inject","z":"6da90f72.dff58","name":"","topic":"start","payload":"","payloadType":"str","repeat":"","crontab":"","once":true,"onceDelay":0.1,"x":170,"y":360,"wires":["3fca2077.558f2"](/cflurin/node-red-contrib-ramp-thermostat/wiki/"3fca2077.558f2")},{"id":"8e4cd6b9.ad5bd8","type":"inject","z":"6da90f72.dff58","name":"","topic":"stop","payload":"","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":170,"y":400,"wires":["3fca2077.558f2"](/cflurin/node-red-contrib-ramp-thermostat/wiki/"3fca2077.558f2")},{"id":"90a06c05.c462a","type":"ui_chart","z":"6da90f72.dff58","name":"","group":"c72a8a5.c6a7378","order":2,"width":"7","height":"3","label":"office state","chartType":"line","legend":"false","xformat":"HH:mm","interpolate":"step","nodata":"","dot":false,"ymin":"","ymax":"","removeOlder":1,"removeOlderPoints":"","removeOlderUnit":"86400","cutout":0,"useOneColor":false,"colors":["#424242","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"useOldStyle":false,"x":430,"y":500,"wires":["78b46324.602f8c"],[](/cflurin/node-red-contrib-ramp-thermostat/wiki/"78b46324.602f8c"],[)},{"id":"d3cc1e06.7017d","type":"change","z":"6da90f72.dff58","name":"parse","rules":[{"t":"change","p":"payload","pt":"msg","from":"true","fromt":"bool","to":"1","tot":"num"},{"t":"change","p":"payload","pt":"msg","from":"false","fromt":"bool","to":"0","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":430,"y":440,"wires":["90a06c05.c462a"](/cflurin/node-red-contrib-ramp-thermostat/wiki/"90a06c05.c462a")},{"id":"78b46324.602f8c","type":"dsm","z":"6da90f72.dff58","name":"memory","sm_config":"{\n    \"currentState\": \"retrieved\",\n    \"states\": {\n        \"retrieved\": {\n            \"retrieve\": \"retrieved\",\n            \"store\": \"stored\",\n            \"clear\": \"cleared\"\n        },\n        \"stored\": {\n            \"retrieve\": \"retrieved\",\n            \"store\": \"stored\",\n            \"clear\": \"cleared\"\n        },\n        \"cleared\": {\n            \"retrieve\": \"retrieved\",\n            \"store\": \"stored\",\n            \"clear\": \"cleared\"\n        }\n    },\n    \"data\": {\n        \"name\": \"chart_data\"\n    },\n    \"methods\": {\n        \"init\": [\n            \"msg = {};\",\n            \"msg.payload = context.get(sm.data.name);\",\n            \"if (typeof msg.payload !== 'undefined') {\",\n            \"   msg.token = 'skip';\",\n            \"   node.send(msg);\",\n            \"}\"\n        ],\n        \"retrieve\": [\n            \"msg.payload = context.get(sm.data.name);\",\n            \"if (typeof msg.payload !== 'undefined') {\",\n            \"   msg.token = 'skip';\",\n            \"} else {\",\n            \"   output = false;\",\n            \"}\"\n        ],\n        \"store\": [\n            \"context.set(sm.data.name, msg.payload);\",\n            \"output = false;\"\n        ],\n        \"clear\": [\n            \"msg.payload = [];\",\n            \"msg.token = 'skip';\"\n        ],\n        \"default\": [\n            \"if (msg.token !== 'skip') {\",\n            \"   resume('store', msg);\",\n            \"}\"\n        ],\n        \"status\": {\n            \"fill\": {\n                \"get\": \"sm.currentState === 'cleared' ? 'yellow' : 'green';\"\n            },\n            \"shape\": {\n                \"get\": \"sm.currentState === 'cleared' ? 'ring' : 'dot';\"\n            },\n            \"text\": {\n                \"get\": \"sm.currentState;\"\n            }\n        }\n    }\n}","x":430,"y":560,"wires":["90a06c05.c462a"](/cflurin/node-red-contrib-ramp-thermostat/wiki/"90a06c05.c462a")},{"id":"cfeebc0.b0fbc48","type":"dsm","z":"6da90f72.dff58","name":"memory","sm_config":"{\n    \"currentState\": \"retrieved\",\n    \"states\": {\n        \"retrieved\": {\n            \"retrieve\": \"retrieved\",\n            \"store\": \"stored\",\n            \"clear\": \"cleared\"\n        },\n        \"stored\": {\n            \"retrieve\": \"retrieved\",\n            \"store\": \"stored\",\n            \"clear\": \"cleared\"\n        },\n        \"cleared\": {\n            \"retrieve\": \"retrieved\",\n            \"store\": \"stored\",\n            \"clear\": \"cleared\"\n        }\n    },\n    \"data\": {\n        \"name\": \"chart_data\"\n    },\n    \"methods\": {\n        \"init\": [\n            \"msg = {};\",\n            \"msg.payload = context.get(sm.data.name);\",\n            \"if (typeof msg.payload !== 'undefined') {\",\n            \"   msg.token = 'skip';\",\n            \"   node.send(msg);\",\n            \"}\"\n        ],\n        \"retrieve\": [\n            \"msg.payload = context.get(sm.data.name);\",\n            \"if (typeof msg.payload !== 'undefined') {\",\n            \"   msg.token = 'skip';\",\n            \"} else {\",\n            \"   output = false;\",\n            \"}\"\n        ],\n        \"store\": [\n            \"context.set(sm.data.name, msg.payload);\",\n            \"output = false;\"\n        ],\n        \"clear\": [\n            \"msg.payload = [];\",\n            \"msg.token = 'skip';\"\n        ],\n        \"default\": [\n            \"if (msg.token !== 'skip') {\",\n            \"   resume('store', msg);\",\n            \"}\"\n        ],\n        \"status\": {\n            \"fill\": {\n                \"get\": \"sm.currentState === 'cleared' ? 'yellow' : 'green';\"\n            },\n            \"shape\": {\n                \"get\": \"sm.currentState === 'cleared' ? 'ring' : 'dot';\"\n            },\n            \"text\": {\n                \"get\": \"sm.currentState;\"\n            }\n        }\n    }\n}","x":410,"y":680,"wires":["7ac01db5.679c94"](/cflurin/node-red-contrib-ramp-thermostat/wiki/"7ac01db5.679c94")},{"id":"456075b4.05240c","type":"profile","z":"","name":"office","time1":"00:00","temp1":"18","time2":"04:00","temp2":"18","time3":"08:00","temp3":"20.5","time4":"12:00","temp4":"20.5","time5":"12:00","temp5":"19","time6":"12:30","temp6":"19","time7":"13:30","temp7":"20.5","time8":"19:00","temp8":"20.5","time9":"19:00","temp9":"18","time10":"23:59","temp10":"18"},{"id":"c72a8a5.c6a7378","type":"ui_group","z":"","name":"Charts","tab":"a8b1385e.93cb58","order":1,"disp":true,"width":"7","collapse":true},{"id":"a8b1385e.93cb58","type":"ui_tab","z":"","name":"ramp-themostat","icon":"dashboard"}]