Delay, timer, throttle or trigger?

Hi,
I read out my digital electricity meter and I aim using this data to controle 4 heaters of 800 watt to use the injection/production of electricity.
Probleme I have is:
when I have 800 watt + delta 200 injection of electricity, heater one has to go in. Then the injection drops to 200 watt. Heater two must go in when the injection is rised again till 800 wat + 200 delta and heater one is in service. Heater 3 can go in when ....... The mesurement comming from the digital meter has a delay of 8 sec. Now, when heater one goes in, heater two thinks he can go in too because he sees for 8 sec the injection of 800 watt + 200 delta and heater one is also in already.
I used already delay, timer, throttle and best of all till now is the trigger to make a time gab of 10 or more sec.
When I use trigger: set to 10 sec, do nothing and after 10 sec send "the latest massage" or "send the original message"? I want to send after 10 sec a fresh message to the next nodes. What is the right choice? Or is there a better node? I notice that the trigger once in a while does not do the right thing and is messing up the proces....

Kris De Voecht

I would ask how does watts change, does it grow to 3200 watts when heater 4 is to come on line, If so there is a simpler way I think.

Little bit difficult to explane....Well, the first heater is controller by a kemo 4000watt with PID controller for capturing the 0 to 800 watts before a 800 watt heater goes in, then the kemo controller goes fast back to 0% output. After the first heater is in, the pid controllers output goes up to 100% when the sun is rising, till 100% (800 watts) then the second heater must come in and so on.. for the third heater....
Problem is the data from the digitale meter had a delay about 8 sec.

Do you not have access to total wattage being generated?

No, the power inverters are 13 years old...

Can you post your flow with the sample of a payload that would turn on a device and one that would turn it back off. I will then take a look.

Could you not fit a power monitor to the set up. This would simplify things.

[{"id":"7d07adf3.860fb4","type":"comment","z":"664a81a4.aeb01","name":"Reading out and controlling heaters with the digital electricity meter","info":"","x":560,"y":40,"wires":[]},{"id":"40072d90.c2ac44","type":"ui_gauge","z":"664a81a4.aeb01","name":"Consumption/Productie","group":"84cb27a7.18e288","order":1,"width":7,"height":3,"gtype":"gage","title":"Consumption/Production electricity","label":"kWatt","format":"{{value}}","min":"-5","max":"5","colors":["#f75959","#0fe600","#10cb26"],"seg1":"-0.1","seg2":"3","x":330,"y":1400,"wires":[]},{"id":"59a92226.a05a4c","type":"join","z":"664a81a4.aeb01","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":true,"timeout":"","count":"1","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":750,"y":280,"wires":[["4b77747.038178c"]]},{"id":"d0b89db0.5a7a8","type":"ui_numeric","z":"664a81a4.aeb01","name":"Delta kWatt","label":"Delta kWatt","tooltip":"","group":"f95af1f4.f770f","order":9,"width":"3","height":1,"wrap":false,"passthru":true,"topic":"delta","format":"{{value}}","min":0,"max":"0.5","step":"0.1","x":470,"y":480,"wires":[["59a92226.a05a4c","1b16d3da.ccc98c","94079aab.1fbb78","f1fb8ddc.ee144","e8de599b.d8f258","6ee87bae.868f64"]]},{"id":"f1667af0.fd9d38","type":"tradfri-out","z":"664a81a4.aeb01","name":"Tweede verbruiker","dtype":"device","tradfri_id":"65655","hub":"ae8834b9.079c48","output":true,"x":1610,"y":580,"wires":[]},{"id":"f040d03a.aaef9","type":"ui_text","z":"664a81a4.aeb01","group":"f95af1f4.f770f","order":6,"width":"4","height":1,"name":"Heater1","label":"Heater1   on:","format":"<font color={{msg.color}} ><i class=\"fa fa-circle\" style=\"font-size:24px;\"></i></font>","layout":"row-left","x":1360,"y":280,"wires":[]},{"id":"249f3654.62768a","type":"function","z":"664a81a4.aeb01","name":"LED","func":"msg.color = (msg.payload === \"on\")?\"lime\":\"red\";\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":1210,"y":280,"wires":[["f040d03a.aaef9"]]},{"id":"c26803e9.9440d","type":"ui_text","z":"664a81a4.aeb01","group":"f95af1f4.f770f","order":7,"width":"4","height":1,"name":"Heater 2","label":"Heater 2    on:","format":"<font color={{msg.color}} ><i class=\"fa fa-circle\" style=\"font-size:24px;\"></i></font>","layout":"row-left","x":1360,"y":620,"wires":[]},{"id":"2d6dfc6b.ed4174","type":"tradfri-out","z":"664a81a4.aeb01","name":"Eerste verbruiker","dtype":"device","tradfri_id":"65583","hub":"ae8834b9.079c48","output":true,"x":1610,"y":240,"wires":[]},{"id":"1b16d3da.ccc98c","type":"join","z":"664a81a4.aeb01","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":true,"timeout":"","count":"1","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":750,"y":240,"wires":[["bca5eb16.011948"]]},{"id":"bca5eb16.011948","type":"function","z":"664a81a4.aeb01","name":"Aan","func":"var E_load = msg.payload[\"p1monitor/smartmeter/E_load\"];\nvar heater01 = msg.payload.heater01;\nvar delta = msg.payload.delta;\n  msg.topic = \"heat_1_on\";\nif (E_load >= (heater01 + delta)) {\n  \n    msg.payload = \"on\";\n    return msg;\n}\n\nelse {\n    null;\n}\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":890,"y":240,"wires":[["249f3654.62768a","2d6dfc6b.ed4174","eb66bb32.55fa28","a4646c5e.ecc49","3e442766.928058","179b07ae.19ed78"]]},{"id":"4b77747.038178c","type":"function","z":"664a81a4.aeb01","name":"Af","func":"var E_load = msg.payload[\"p1monitor/smartmeter/E_load\"];\n    msg.topic = \"heat_1_on\";\nif (E_load <= -0.22) {\n\n    msg.payload = \"off\";\n    return msg;\n}\nelse;\n{\n    null;\n}\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":890,"y":280,"wires":[["249f3654.62768a","2d6dfc6b.ed4174","eb66bb32.55fa28","3e442766.928058","179b07ae.19ed78"]]},{"id":"6ee87bae.868f64","type":"join","z":"664a81a4.aeb01","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":true,"timeout":"","count":"1","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":750,"y":620,"wires":[["17ba6d7.47c2693"]]},{"id":"17ba6d7.47c2693","type":"function","z":"664a81a4.aeb01","name":"Af","func":"var E_load = msg.payload[\"p1monitor/smartmeter/E_load\"];\nvar delta = msg.payload.delta;\n    msg.topic = \"heat_2_on\";\nif (E_load < -0.18) {\n\n    msg.payload = \"off\";\n    return msg;\n}\nelse;\n{\n    null\n}","outputs":1,"noerr":0,"initialize":"","finalize":"","x":890,"y":620,"wires":[["f1667af0.fd9d38","f1fb8ddc.ee144","9145f4e0.2ffa88","85c96bc5.778818","179b07ae.19ed78"]]},{"id":"66cc5613.58ace8","type":"function","z":"664a81a4.aeb01","name":"aan","func":"var E_load = msg.payload[\"p1monitor/smartmeter/E_load\"];\nvar heater02 = msg.payload.heater02;\nvar delta = msg.payload.delta;\nvar heat_1_on = msg.payload.heat_1_on;\n    msg.topic = \"heat_2_on\";\nif (E_load >= (heater02 + (delta * 1.3)) && (heat_1_on == \"on\")) {\n\n    msg.payload = \"on\";\n    return msg;\n}\nelse {\n    null;\n}\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":890,"y":580,"wires":[["f1667af0.fd9d38","278864f6.55889c","9145f4e0.2ffa88","85c96bc5.778818","179b07ae.19ed78"]]},{"id":"85c96bc5.778818","type":"function","z":"664a81a4.aeb01","name":"LED","func":"msg.color = (msg.payload === \"on\")?\"lime\":\"red\";\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":1210,"y":620,"wires":[["c26803e9.9440d"]]},{"id":"82115a5b.5b9f78","type":"ui_chart","z":"664a81a4.aeb01","name":"1ste heater 0.8 kWatt","group":"f596e3f5.2093e","order":1,"width":"5","height":"5","label":"1ste heater 0.8 kWatt","chartType":"line","legend":"true","xformat":"HH:mm:ss","interpolate":"step","nodata":"","dot":false,"ymin":"0","ymax":"1.5","removeOlder":"8","removeOlderPoints":"","removeOlderUnit":"3600","cutout":0,"useOneColor":false,"useUTC":false,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"outputs":1,"useDifferentColor":false,"x":1340,"y":320,"wires":[[]]},{"id":"eb66bb32.55fa28","type":"change","z":"664a81a4.aeb01","name":"on = 1","rules":[{"t":"change","p":"payload","pt":"msg","from":"on","fromt":"str","to":"1","tot":"num"},{"t":"change","p":"payload","pt":"msg","from":"off","fromt":"str","to":"0","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1170,"y":320,"wires":[["82115a5b.5b9f78"]]},{"id":"15c390fa.52c68f","type":"ui_chart","z":"664a81a4.aeb01","name":"2de heater 0.8 kWatt","group":"f596e3f5.2093e","order":2,"width":"5","height":"5","label":"2de heater 1 kWatt","chartType":"line","legend":"true","xformat":"HH:mm:ss","interpolate":"step","nodata":"","dot":false,"ymin":"0","ymax":"1.5","removeOlder":"8","removeOlderPoints":"","removeOlderUnit":"3600","cutout":0,"useOneColor":false,"useUTC":false,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"outputs":1,"useDifferentColor":false,"x":1340,"y":660,"wires":[[]]},{"id":"9145f4e0.2ffa88","type":"change","z":"664a81a4.aeb01","name":"on = 1","rules":[{"t":"change","p":"payload","pt":"msg","from":"on","fromt":"str","to":"1","tot":"num"},{"t":"change","p":"payload","pt":"msg","from":"off","fromt":"str","to":"0","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1170,"y":660,"wires":[["15c390fa.52c68f"]]},{"id":"1053f5f9.1361da","type":"comment","z":"664a81a4.aeb01","name":"Controlling heater 1","info":"","x":810,"y":180,"wires":[]},{"id":"6c19e803.2ef358","type":"comment","z":"664a81a4.aeb01","name":"Controlling heater 2","info":"","x":810,"y":480,"wires":[]},{"id":"94079aab.1fbb78","type":"join","z":"664a81a4.aeb01","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":true,"timeout":"","count":"1","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":750,"y":580,"wires":[["66cc5613.58ace8"]]},{"id":"f692345c.b3e458","type":"tradfri-out","z":"664a81a4.aeb01","name":"Derde verbruiker","dtype":"device","tradfri_id":"65577","hub":"ae8834b9.079c48","output":true,"x":1610,"y":840,"wires":[]},{"id":"d3ac9732.6bb4d8","type":"ui_text","z":"664a81a4.aeb01","group":"f95af1f4.f770f","order":8,"width":"4","height":1,"name":"Heater 3","label":"Heater 3    on:","format":"<font color={{msg.color}} ><i class=\"fa fa-circle\" style=\"font-size:24px;\"></i></font>","layout":"row-left","x":1360,"y":900,"wires":[]},{"id":"e8de599b.d8f258","type":"join","z":"664a81a4.aeb01","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":true,"timeout":"","count":"1","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":750,"y":900,"wires":[["137d8a51.0b3566"]]},{"id":"137d8a51.0b3566","type":"function","z":"664a81a4.aeb01","name":"Af","func":"var E_load = msg.payload[\"p1monitor/smartmeter/E_load\"];\nvar delta = msg.payload.delta;\n    msg.topic = \"heat_3_on\";\nif (E_load <= -0.1) {\n\n    msg.payload = \"off\";\n    return msg;\n}\nelse;\n{\n    null;\n}","outputs":1,"noerr":0,"initialize":"","finalize":"","x":890,"y":900,"wires":[["f692345c.b3e458","c14a96e7.cabf48","612706d7.5b19e8","179b07ae.19ed78"]]},{"id":"1904a9c6.350b06","type":"function","z":"664a81a4.aeb01","name":"aan","func":"var E_load = msg.payload[\"p1monitor/smartmeter/E_load\"];\nvar heater03= msg.payload.heater03;\nvar delta = msg.payload.delta;\nvar heat_1_on = msg.payload.heat_1_on;\nvar heat_2_on = msg.payload.heat_2_on;\n    msg.topic = \"heat_3_on\";\nif (E_load >= (heater03 + (delta * 1.1)) && (heat_1_on === \"on\") && (heat_2_on === \"on\")) {\n\n    msg.payload = \"on\";\n    return msg;\n}\nelse {\n   null;\n}\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":890,"y":860,"wires":[["f692345c.b3e458","612706d7.5b19e8","c14a96e7.cabf48","179b07ae.19ed78"]]},{"id":"612706d7.5b19e8","type":"function","z":"664a81a4.aeb01","name":"LED","func":"msg.color = (msg.payload === \"on\")?\"lime\":\"red\";\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":1210,"y":900,"wires":[["d3ac9732.6bb4d8"]]},{"id":"d2f2956c.096178","type":"ui_chart","z":"664a81a4.aeb01","name":"3de heater 1 kWatt","group":"f596e3f5.2093e","order":3,"width":"5","height":"5","label":"3de heater1 kWatt","chartType":"line","legend":"true","xformat":"HH:mm:ss","interpolate":"step","nodata":"","dot":false,"ymin":"0","ymax":"1.5","removeOlder":"8","removeOlderPoints":"","removeOlderUnit":"3600","cutout":0,"useOneColor":false,"useUTC":false,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"outputs":1,"useDifferentColor":false,"x":1330,"y":940,"wires":[[]]},{"id":"c14a96e7.cabf48","type":"change","z":"664a81a4.aeb01","name":"on = 1","rules":[{"t":"change","p":"payload","pt":"msg","from":"on","fromt":"str","to":"1","tot":"num"},{"t":"change","p":"payload","pt":"msg","from":"off","fromt":"str","to":"0","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1150,"y":940,"wires":[["d2f2956c.096178"]]},{"id":"33e7ae41.8b6092","type":"comment","z":"664a81a4.aeb01","name":"Controlling heater 3","info":"","x":810,"y":740,"wires":[]},{"id":"f1fb8ddc.ee144","type":"join","z":"664a81a4.aeb01","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":true,"timeout":"","count":"1","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":750,"y":860,"wires":[["1904a9c6.350b06"]]},{"id":"727e13ec.53781c","type":"trigger","z":"664a81a4.aeb01","name":"T 20 sec","op1":"","op2":"on","op1type":"nul","op2type":"str","duration":"20","extend":false,"overrideDelay":false,"units":"s","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":880,"y":520,"wires":[["94079aab.1fbb78"]],"info":"Geeft een 1 door bij inschakelen van heat_on_1 en dit zal niets doen maar na 15 sec geeft de trigger wel een \"on\" door met payload \"heat_on_1\".\nDit om de traagheid van de meting te kunnen compenseren en zodat heat_on_2 niet mee ingaat!!"},{"id":"a4646c5e.ecc49","type":"trigger","z":"664a81a4.aeb01","name":"T 30 sec","op1":"","op2":"on","op1type":"nul","op2type":"str","duration":"30","extend":false,"overrideDelay":false,"units":"s","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":800,"y":780,"wires":[["f1fb8ddc.ee144"]],"info":"Geeft een 1 door bij inschakelen van heat_on_1 en dit zal niets doen maar na 15 sec geeft de trigger wel een \"on\" door met payload \"heat_on_1\".\nDit om de traagheid van de meting te kunnen compenseren en zodat heat_on_3 niet onmiddelijk mee ingaat!!"},{"id":"278864f6.55889c","type":"trigger","z":"664a81a4.aeb01","name":"T15 sec","op1":"","op2":"on","op1type":"nul","op2type":"str","duration":"15","extend":false,"overrideDelay":false,"units":"s","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":800,"y":820,"wires":[["f1fb8ddc.ee144"]],"info":"Geeft een 1 door bij inschakelen van heat_on_2 en dit zal niets doen maar na 15 sec geeft de trigger wel een \"on\" door met payload \"heat_on_1\".\nDit om de traagheid van de meting te kunnen compenseren en zodat heat_on_3 niet onmiddelijk mee ingaat!!"},{"id":"6f5f76ba.0c0cd8","type":"ui_numeric","z":"664a81a4.aeb01","name":"","label":"Heater 1: set in kWatt","tooltip":"","group":"f95af1f4.f770f","order":10,"width":"5","height":"1","wrap":false,"passthru":true,"topic":"heater01","format":"{{value}}","min":0,"max":"2","step":"0.05","x":280,"y":240,"wires":[["1b16d3da.ccc98c"]]},{"id":"f6efb199.a502e","type":"ui_numeric","z":"664a81a4.aeb01","name":"","label":"Heater 2: set in kWatt","tooltip":"","group":"f95af1f4.f770f","order":11,"width":"5","height":"1","wrap":false,"passthru":true,"topic":"heater02","format":"{{value}}","min":0,"max":"2","step":"0.05","x":280,"y":580,"wires":[["94079aab.1fbb78"]]},{"id":"729743d6.dcf8dc","type":"ui_numeric","z":"664a81a4.aeb01","name":"","label":"Heater 3: set in kWatt","tooltip":"","group":"f95af1f4.f770f","order":12,"width":"5","height":"1","wrap":false,"passthru":true,"topic":"heater03","format":"{{value}}","min":0,"max":"2","step":"0.1","x":300,"y":860,"wires":[["f1fb8ddc.ee144"]]},{"id":"9d1fd5ff.b5eac8","type":"ui_chart","z":"664a81a4.aeb01","name":"verbruik/productie","group":"84cb27a7.18e288","order":6,"width":"8","height":"3","label":"Verbruik/productie van -1 kWatt tot 1 kWatt","chartType":"line","legend":"false","xformat":"HH:mm:ss","interpolate":"linear","nodata":"","dot":false,"ymin":"-1","ymax":"1","removeOlder":"8","removeOlderPoints":"","removeOlderUnit":"3600","cutout":0,"useOneColor":false,"useUTC":false,"colors":["#309ce8","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"outputs":1,"useDifferentColor":false,"x":350,"y":1440,"wires":[[]]},{"id":"5ad2d3a9.be057c","type":"ui_button","z":"664a81a4.aeb01","name":"On","group":"f95af1f4.f770f","order":13,"width":"2","height":"1","passthru":false,"label":"On","tooltip":"","color":"","bgcolor":"","icon":"","payload":"on","payloadType":"str","topic":"","x":1110,"y":120,"wires":[["249f3654.62768a","2d6dfc6b.ed4174"]]},{"id":"b75e413.d81d3c","type":"ui_button","z":"664a81a4.aeb01","name":"On","group":"f95af1f4.f770f","order":17,"width":"2","height":"1","passthru":false,"label":"On","tooltip":"","color":"","bgcolor":"","icon":"","payload":"on","payloadType":"str","topic":"","x":1110,"y":760,"wires":[["f692345c.b3e458","612706d7.5b19e8"]]},{"id":"1b9ba291.55852d","type":"ui_button","z":"664a81a4.aeb01","name":"Off","group":"f95af1f4.f770f","order":14,"width":"2","height":"1","passthru":false,"label":"Off","tooltip":"","color":"","bgcolor":"","icon":"","payload":"off","payloadType":"str","topic":"","x":1110,"y":160,"wires":[["249f3654.62768a","2d6dfc6b.ed4174"]]},{"id":"d523df8b.c5ff1","type":"ui_button","z":"664a81a4.aeb01","name":"Off","group":"f95af1f4.f770f","order":16,"width":"2","height":"1","passthru":false,"label":"Off","tooltip":"","color":"","bgcolor":"","icon":"","payload":"off","payloadType":"str","topic":"","x":1130,"y":500,"wires":[["f1667af0.fd9d38","85c96bc5.778818"]]},{"id":"d13b3c3f.35115","type":"ui_button","z":"664a81a4.aeb01","name":"Off","group":"f95af1f4.f770f","order":18,"width":"2","height":"1","passthru":false,"label":"Off","tooltip":"","color":"","bgcolor":"","icon":"","payload":"off","payloadType":"str","topic":"","x":1110,"y":800,"wires":[["f692345c.b3e458","612706d7.5b19e8"]]},{"id":"10f207d7.f6f938","type":"comment","z":"664a81a4.aeb01","name":"Ikea smart switch 3","info":"","x":1330,"y":820,"wires":[]},{"id":"d1606eec.3cac","type":"comment","z":"664a81a4.aeb01","name":"Ikea smart switch 2","info":"","x":1350,"y":540,"wires":[]},{"id":"463357a1.193fe8","type":"comment","z":"664a81a4.aeb01","name":"Ikea smart switch 1","info":"","x":1350,"y":200,"wires":[]},{"id":"3967d9bf.375b56","type":"mqtt out","z":"664a81a4.aeb01","name":"","topic":"ClientServoKemo_01/Positie","qos":"","retain":"","broker":"e2ed99fb.aa45d8","x":1300,"y":1260,"wires":[]},{"id":"ac7b325f.d59a8","type":"mqtt in","z":"664a81a4.aeb01","name":"Injectie","topic":"p1monitor/smartmeter/production_kw","qos":"0","datatype":"auto","broker":"e2ed99fb.aa45d8","x":210,"y":1220,"wires":[["ca8c81df.c2697"]]},{"id":"26463d67.8ef202","type":"ui_chart","z":"664a81a4.aeb01","name":"","group":"84cb27a7.18e288","order":7,"width":"8","height":"3","label":"Signaal-> Kemo: 0=min, 100=max","chartType":"line","legend":"false","xformat":"HH:mm:ss","interpolate":"linear","nodata":"","dot":false,"ymin":"0","ymax":"100","removeOlder":"8","removeOlderPoints":"","removeOlderUnit":"3600","cutout":0,"useOneColor":false,"useUTC":false,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"outputs":1,"useDifferentColor":false,"x":1280,"y":1360,"wires":[[]]},{"id":"f7c190fc.01f41","type":"PID","z":"664a81a4.aeb01","name":"","setpoint":"0.2","pb":"35","ti":"1","td":"0","integral_default":"1","smooth_factor":"0","max_interval":"60","enable":1,"disabled_op":"0.6","x":730,"y":1280,"wires":[["e0bd5cd1.d1855","29cdb54c.6ad86a"]]},{"id":"7fa5a95c.c532c8","type":"ui_text","z":"664a81a4.aeb01","group":"f95af1f4.f770f","order":2,"width":"5","height":"1","name":"%Output naar PID controller heater Kemo","label":"% Output heater Kemo :","format":"{{msg.payload}}","layout":"row-left","x":1260,"y":1320,"wires":[]},{"id":"e0bd5cd1.d1855","type":"range","z":"664a81a4.aeb01","minin":"0","maxin":"1","minout":"50","maxout":"0","action":"clamp","round":true,"property":"payload","name":"Map pid->Kemo","x":940,"y":1280,"wires":[["3967d9bf.375b56","f753f7cc.abeba8","e2a3e171.fdb17"]]},{"id":"cc3ad2a6.78966","type":"ui_numeric","z":"664a81a4.aeb01","name":"Set max injection","label":"Set max injection in kWatt:","tooltip":"","group":"f95af1f4.f770f","order":5,"width":"6","height":"1","wrap":false,"passthru":true,"topic":"setpoint","format":"{{value}}","min":0,"max":"0.5","step":"0.1","x":430,"y":1160,"wires":[["f7c190fc.01f41"]]},{"id":"1f10a5b.eb33a5a","type":"mqtt in","z":"664a81a4.aeb01","name":"Consumption","topic":"p1monitor/smartmeter/consumption_kw","qos":"2","datatype":"auto","broker":"e2ed99fb.aa45d8","x":230,"y":1340,"wires":[["714eab3f.822d84"]]},{"id":"24bbe3d3.bbffac","type":"function","z":"664a81a4.aeb01","name":"Cons/prod","func":"var injectie = msg.payload[\"p1monitor/smartmeter/production_kw\"];\nvar consumption = msg.payload[\"p1monitor/smartmeter/consumption_kw\"];\nif (injectie > 0) {\n    msg.payload = injectie;\n    return msg;\n}\n\nelse;\n{\n    consumption = consumption *-1;\n    msg.payload = consumption;\n    return msg;\n}","outputs":1,"noerr":0,"initialize":"","finalize":"","x":370,"y":1280,"wires":[["40072d90.c2ac44","9d1fd5ff.b5eac8","8996ab21.fa9328"]]},{"id":"ca8c81df.c2697","type":"function","z":"664a81a4.aeb01","name":"str->nr","func":"msg.payload = Number(msg.payload);\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":370,"y":1220,"wires":[["7461619f.d1cba"]]},{"id":"714eab3f.822d84","type":"function","z":"664a81a4.aeb01","name":"Str->nr","func":"msg.payload = Number(msg.payload);\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":370,"y":1340,"wires":[["7461619f.d1cba"]]},{"id":"7461619f.d1cba","type":"join","z":"664a81a4.aeb01","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":true,"timeout":"","count":"2","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":210,"y":1280,"wires":[["24bbe3d3.bbffac"]]},{"id":"bc435e13.5feea","type":"function","z":"664a81a4.aeb01","name":"Heat extra in","func":"var E_load = msg.payload[\"p1monitor/smartmeter/E_load\"];\nvar kemo = msg.payload.kemo;\n\nvar heat_1_on = msg.payload.heat_1_on;\nvar heat_2_on = msg.payload.heat_2_on;\nvar heat_3_on = msg.payload.heat_3_on;\nif ((kemo === 0) && (E_load >= 0.3))\n{\n         if (heat_1_on == \"off\")\n            {\n                msg.topic = \"heat_extra_01\";\n                msg.payload = \"on\";\n                return [msg, null, null];\n            }\n         else if\n            (heat_2_on == \"off\")\n            {\n                msg.topic = \"heat_extra_02\";\n                msg.payload = \"on\";\n                return [null, msg, null];\n            }\n        else if \n            (heat_3_on == \"off\")\n            {\n                msg.topic = \"heat_extra_03\";\n                msg.payload = \"on\";\n                return [null, null, msg];\n            }\n}\nelse;\n{\n   return null;\n}","outputs":3,"noerr":0,"initialize":"","finalize":"","x":1350,"y":1020,"wires":[["249f3654.62768a","2d6dfc6b.ed4174"],["f1667af0.fd9d38","85c96bc5.778818"],["f692345c.b3e458","612706d7.5b19e8"]]},{"id":"f7d36ee7.3be9e","type":"inject","z":"664a81a4.aeb01","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"0","payloadType":"num","x":230,"y":1160,"wires":[["cc3ad2a6.78966"]]},{"id":"bc0271b6.da4c6","type":"ui_text","z":"664a81a4.aeb01","group":"f95af1f4.f770f","order":4,"width":"4","height":1,"name":"Heater 4","label":"Heater Kemo on:","format":"<font color={{msg.color}} ><i class=\"fa fa-circle\" style=\"font-size:24px;\"></i></font>","layout":"row-left","x":1360,"y":1220,"wires":[]},{"id":"ad001103.83fac","type":"function","z":"664a81a4.aeb01","name":"LED","func":"msg.color = (msg.payload === \"on\")?\"lime\":\"red\";\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":1230,"y":1220,"wires":[["bc0271b6.da4c6"]]},{"id":"f753f7cc.abeba8","type":"function","z":"664a81a4.aeb01","name":"","func":"var kemo = msg.payload;\nif (kemo > 0) {\n    msg.payload = \"on\";\n    return msg;\n}\nelse;\n{\n    msg.payload = \"off\";\n    return msg;\n}","outputs":1,"noerr":0,"initialize":"","finalize":"","x":1100,"y":1220,"wires":[["ad001103.83fac"]]},{"id":"e2a3e171.fdb17","type":"range","z":"664a81a4.aeb01","minin":"0","maxin":"50","minout":"0","maxout":"100","action":"scale","round":true,"property":"payload","name":"Map Kemo ->100%","x":950,"y":1340,"wires":[["26463d67.8ef202","7fa5a95c.c532c8"]]},{"id":"dc2074e9.3005d8","type":"comment","z":"664a81a4.aeb01","name":"Kemo power control 4000 KV sturing","info":"","x":300,"y":1100,"wires":[]},{"id":"cd891255.6a27e","type":"comment","z":"664a81a4.aeb01","name":"Map ESP8266","info":"","x":930,"y":1240,"wires":[]},{"id":"5035c40c.f339ac","type":"ui_button","z":"664a81a4.aeb01","name":"On","group":"f95af1f4.f770f","order":15,"width":"2","height":"1","passthru":false,"label":"On","tooltip":"","color":"","bgcolor":"","icon":"","payload":"on","payloadType":"str","topic":"","x":1130,"y":460,"wires":[["f1667af0.fd9d38","85c96bc5.778818"]]},{"id":"7389eb63.5f0824","type":"trigger","z":"664a81a4.aeb01","name":"T on 26 sec","op1":"","op2":"","op1type":"nul","op2type":"pay","duration":"26","extend":false,"overrideDelay":false,"units":"s","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":550,"y":560,"wires":[["94079aab.1fbb78"]],"info":"When triggerd, wait x sec and then send the value to the join node to start heaater02.\nwhitout the delay, heater02 wil start at the same moment as heater01. Heater02 may only start when heater01 is in and the injection is decreased with 850 watt."},{"id":"3e442766.928058","type":"function","z":"664a81a4.aeb01","name":"1 x on/off","func":"var payload=msg.payload;\nvar alarm_flag=context.get(\"alarm_flag\");\n\nif(typeof alarm_flag==\"undefined\")\nalarm_flag=false;\nif (payload==\"on\" && !alarm_flag)\n{\n    alarm_flag=true;\n    msg.alarm=\"on\";\n    context.set(\"alarm_flag\",alarm_flag);\n    return msg;\n}\nif (payload==\"off\" && alarm_flag)\n{\n   alarm_flag=false;\n   msg.alarm=\"off\";\n   context.set(\"alarm_flag\",alarm_flag);\n   return msg;\n}","outputs":1,"noerr":0,"initialize":"","finalize":"","x":740,"y":520,"wires":[["727e13ec.53781c"]]},{"id":"b75d06c6.086d18","type":"trigger","z":"664a81a4.aeb01","name":"T off 25 sec","op1":"","op2":"","op1type":"nul","op2type":"payl","duration":"25","extend":false,"overrideDelay":false,"units":"s","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":570,"y":620,"wires":[["6ee87bae.868f64"]],"info":"When triggerd, wait x sec and then send the value to the join node to start heaater02.\nwhitout the delay, heater02 wil start at the same moment as heater01. Heater02 may only start when heater01 is in and the injection is decreased with 850 watt."},{"id":"269796a2.00962a","type":"trigger","z":"664a81a4.aeb01","name":"T off 35 sec","op1":"","op2":"","op1type":"nul","op2type":"payl","duration":"35","extend":false,"overrideDelay":false,"units":"s","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":570,"y":280,"wires":[["59a92226.a05a4c"]],"info":"When triggerd, wait x sec and then send the value to the join node to start heaater02.\nwhitout the delay, heater02 wil start at the same moment as heater01. Heater02 may only start when heater01 is in and the injection is decreased with 850 watt."},{"id":"8996ab21.fa9328","type":"change","z":"664a81a4.aeb01","name":"E_load","rules":[{"t":"change","p":"topic","pt":"msg","from":"consumption_kw","fromt":"str","to":"E_load","tot":"str"},{"t":"change","p":"topic","pt":"msg","from":"production_kw","fromt":"str","to":"E_load","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":530,"y":1280,"wires":[["f1fb8ddc.ee144","f7c190fc.01f41","7389eb63.5f0824","b75d06c6.086d18","269796a2.00962a","c41b91d5.3c3d2","179b07ae.19ed78","d1a451ec.11d22"]]},{"id":"d1a451ec.11d22","type":"trigger","z":"664a81a4.aeb01","name":"T on 8 sec","op1":"","op2":"","op1type":"nul","op2type":"pay","duration":"8","extend":false,"overrideDelay":false,"units":"s","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":570,"y":200,"wires":[["1b16d3da.ccc98c"]],"info":"When triggerd, wait x sec and then send the value to the join node to start heaater02.\nwhitout the delay, heater02 wil start at the same moment as heater01. Heater02 may only start when heater01 is in and the injection is decreased with 850 watt."},{"id":"c41b91d5.3c3d2","type":"trigger","z":"664a81a4.aeb01","name":"T off 14 sec","op1":"","op2":"","op1type":"nul","op2type":"pay","duration":"14","extend":false,"overrideDelay":false,"units":"s","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":570,"y":900,"wires":[["e8de599b.d8f258"]],"info":"When triggerd, wait x sec and then send the value to the join node to start heaater02.\nwhitout the delay, heater02 wil start at the same moment as heater01. Heater02 may only start when heater01 is in and the injection is decreased with 850 watt."},{"id":"179b07ae.19ed78","type":"join","z":"664a81a4.aeb01","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":true,"timeout":"","count":"1","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":1170,"y":1020,"wires":[["bc435e13.5feea"]]},{"id":"29cdb54c.6ad86a","type":"function","z":"664a81a4.aeb01","name":"","func":"msg.topic = \"kemo\";\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":740,"y":1340,"wires":[["179b07ae.19ed78"]]},{"id":"84cb27a7.18e288","type":"ui_group","name":"Consumption and Procution of electricity in kWatt","tab":"16694e6c.5ee9e2","order":1,"disp":true,"width":"16","collapse":true},{"id":"f95af1f4.f770f","type":"ui_group","name":"Overview recuperation of electricity in heat","tab":"16694e6c.5ee9e2","order":2,"disp":true,"width":"16","collapse":true},{"id":"ae8834b9.079c48","type":"tradfri-config","name":"Gateway","hubip":"192.168.1.31","sid":"UGmbXswPjpqHn9iT","coap":"/home/pi/.node-red/node_modules/node-tradfri-argon/lib/coap-client-raspbian","identity":"R0BoUAGsbHc7U","preshared_key":"MvgthsFe2a2JdqWh"},{"id":"f596e3f5.2093e","type":"ui_group","name":"Logging  of recuperation electricity to heat","tab":"16694e6c.5ee9e2","order":3,"disp":true,"width":"16","collapse":true},{"id":"e2ed99fb.aa45d8","type":"mqtt-broker","name":"","broker":"localhost","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"16694e6c.5ee9e2","type":"ui_tab","name":"De Voecht","icon":"Zonneboiler","disabled":false,"hidden":false}]

Sorry have to post the hole flow to see what is happening....

E1cid, I’m a 3 month old newbie, so the code will be a little bit strange to you :wink:

That is a vast jumble. I will suggest a rethink.

Let's start with the incoming data from the meter/inverters, until I see that I can not really tell what your flow is doing. I could guess but that would be time wasting.

So to move froward please supply examples of incoming data that will be used to work out when and which heaters to turn on. Also an example of the data that would be sent to turn off/on the heaters.
so
what the data looks like when all should be off.
What the data should be when you decide to turn heater 1 one.
what the data looks like after you turn heater 1 on.
what the data then should look like when the decision to turn heater 2 occurs

Place debugs at incoming data points, set the debugs to capture the complete msg.
Then use the copy value option in the debug panel, you will find it to the right of the object name when you hover mouse. Then post the data using paste.

Once I or others understand your data we can then offer a better option or how to fix what you have.

The 2 incomming data's from the digital meter:

{"topic":"p1monitor/smartmeter/consumption_kw","payload":"0.0","qos":0,"retain":false,"_topic":"p1monitor/smartmeter/consumption_kw","_msgid":"5bee197.f9393e8"}
{"topic":"p1monitor/smartmeter/production_kw","payload":"3.439","qos":0,"retain":false,"_topic":"p1monitor/smartmeter/production_kw","_msgid":"4cf4d553.8a601c"}

I have joined the 2 mesurements to 1 mesurements + and -, so E_load can go from +5 kwatt (production) till -5 kWatt (consumption).
This for a better reaction on the PID controller. This E_load goes to the PID controller (setpoint = 0 kWatt, = no production and no consumption) to control the Kemo heater 900 watt.
When the output of the PID is 100% (900 watt heater Kemo) + a 200 watt production, heater 1 (850 watt) must come in (at that moment the E_load goes to -650 watt)
and the PID must decrease heater Kemo to maintaine his setpunt of 0 kWatt. The activation off heater 1 is not yet working (funktion "Heat extra in").
At this moment Heater 1 comes in when the production increase till 850 watt + delta. Heater 2 comes in when the production is again 850 + delta, the timer prevents that 1 and 2 goes in at the same time.

{"topic":"p1monitor/smartmeter/E_load","payload":3.434,"qos":0,"retain":false,"_topic":"p1monitor/smartmeter/consumption_kw","_msgid":"e6688e5b.cbc37"}
{"topic":"p1monitor/smartmeter/E_load","payload":3.457,"qos":0,"retain":false,"_topic":"p1monitor/smartmeter/production_kw","_msgid":"d7ece680.24f498"}

Output heater 1 on:
The relais to switch on/off is an Ikea smart plug, via the ikea node.
{"payload":"on","topic":"heat_1_on","_msgid":"d024d361.c2f41","qos":0,"retain":false,"_topic":"p1monitor/smartmeter/consumption_kw","socketid":"piG1DyM1ygT462q1AAAH"}

Output heater 1 off:
{"payload":"off","topic":"heat_1_on","_msgid":"8115689d.259fd8","qos":0,"retain":false,"_topic":"p1monitor/smartmeter/production_kw","socketid":"piG1DyM1ygT462q1AAAH"}

Ok iI think I get it.
Try something like this, when E_load exceeds set point it will turn on a heater and when it falls below it will turn one off. I have set no delta. If heater one is already on it will move to heater 2 etc. it stores the heater it is on in context storage.

[{"id":"2b5533e9.fe51b4","type":"inject","z":"c74669a0.6a34f8","name":"less than 0","props":[{"p":"E_load","v":"-850","vt":"num"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":130,"y":4380,"wires":[["4c53645c.a7f41c"]]},{"id":"4c53645c.a7f41c","type":"function","z":"c74669a0.6a34f8","name":"","func":"var heater = flow.get(\"heater\") || 1;\nif (msg.E_load > 800){\n    if(heater >= 5) return null;\n    heater++;\n    flow.set(\"heater\", heater)\n    msg.payload=\"on\";\n    msg.topic= `heater_${heater - 1}_on`\n}else if(msg.E_load < 0){\n    if(heater <= 1) return null;\n    heater--;\n    flow.set(\"heater\", heater)\n    msg.payload=\"off\"; \n    msg.topic= `heater_${heater}_on`\n}else{\n    return null;\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":470,"y":4400,"wires":[["9b8b2bd1.0f724"]]},{"id":"f4b2f5bf.b5df18","type":"inject","z":"c74669a0.6a34f8","name":"more than 800","props":[{"p":"E_load","v":"850","vt":"num"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":150,"y":4460,"wires":[["4c53645c.a7f41c"]]},{"id":"a24bf6d2.6fda7","type":"inject","z":"c74669a0.6a34f8","name":"more than 0 but less than 800","props":[{"p":"E_load","v":"100","vt":"num"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":210,"y":4420,"wires":[["4c53645c.a7f41c"]]},{"id":"9b8b2bd1.0f724","type":"debug","z":"c74669a0.6a34f8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":670,"y":4400,"wires":[]}]

[edit
So this will turn on heater when E_load is greater than 800 (you may wish to add a delta to this) and turn off heaters when below 0. ]

E1cid,
This is a nice and clean function to start the heaters one after the other! Thanks.
But:
the setup is, heater 1, heater 2, heater 3 and a heater who is controlled by a variable kemo power control, I call him the Kemo heater controlled by a PID node. The last one has to take the kwatts between the heaters. The probleme is, I have to wait from 0 till 850 watt before a heater can start, so in the morning and the evening with less sun power, the production will not rise above 850 watts, no heater can start. Also when heater 1 and heater 2 is already on and there is still 500 watts left, the Kemo heater can take that 500 watts with the variable PID controller and setpoint = 0 watt. So in between the Kemo heater with variable load can take those watts. Once the Kemo heater is max (900 watts), we can bring in a heater of 850 watt, the Kemo controller wil bring down again the Kemo heater till the setpoint 0 watts. So between the heaters 1/2/3 go on, the Kemo heater takes what is left over...
Not so easy to explain....

Grtz Kris

I see it's not easy to explain

so you want a variable heater to start if the generated power is less than 800 but above 0

Does this kemo heater have any input/output variables?

I was thinking, the mesurement from the digital meter has a delay of 8 sec. (thats my probleme).
With your funtion, when you reached 850 watt, heater 1 goes in. The mesurement stays for 8 sec on 850 watt.... I think, heater 2 wil come in also and maybe heater 3 and after 8 sec we have a E-load of -1700 watts :frowning: ...and all heaters go off.

Kris

My function will bring only one heater at a time, then it waits till next input from e_load before it decides what to do. I will have a think about bring in this variable heater, but will need to know if it has any input or output that decides what variance it will heat at.

The E-load output goes directly to the PID node controller with setpoint 0. Output PID from 0 till 1. I do a mapping of the output (mqtt) to a servo and connected to a potentiometer of the kemo controller.

The pid is probably not needed, I just need to know what the kemo input message is so i can handle it in the function

Your function is ok but the measurement from the digital meter to the E-load has a delay of 8 sec, so when heater 1 starts, E-load will have still 8 sec the 850 watt en after 8 sec the E-load drops...

How often does E_load message get passed What rate?
The 8 second delay could be handle with a simple rate limit