Delay, timer, throttle or trigger?

Well, I read the digital meter with P1monitor software and with mqtt activated he sends the data to my broker...I really don't now what the data rate is.

This will add a temporary delay of 10 secs to the incoming msg if a heater is turned on/off or function outputs on pid, and it only passes the latest msg. If the function runs with out returning a msg then no delay is set

If you want the kemo added i will need to know the payloads you send to the kemo unit.

[{"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":[["f47c9842.c0e398"]]},{"id":"f47c9842.c0e398","type":"change","z":"c74669a0.6a34f8","name":"","rules":[{"t":"set","p":"delay","pt":"msg","to":"delay","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":250,"y":4300,"wires":[["ccf15383.3648"]]},{"id":"ccf15383.3648","type":"trigger","z":"c74669a0.6a34f8","name":"delay","op1":"","op2":"","op1type":"nul","op2type":"payl","duration":"250","extend":false,"overrideDelay":true,"units":"ms","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":430,"y":4300,"wires":[["4c53645c.a7f41c"]]},{"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":[["f47c9842.c0e398"]]},{"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":[["f47c9842.c0e398"]]},{"id":"4c53645c.a7f41c","type":"function","z":"c74669a0.6a34f8","name":"","func":"var heater = flow.get(\"heater\") || 1;\nif (msg.E_load > 800 && heater < 4){\n    msg={};\n    msg.payload=\"on\";\n    msg.topic= `heater_${heater}_on`\n    heater++;\n}else if(msg.E_load < 0 && heater > 1){\n    msg={};\n    heater--;\n    msg.payload=\"off\"; \n    msg.topic= `heater_${heater}_on`\n}else if(msg.E_load > 0){\n    return [null,{payload: msg.E_load}];\n}else  {\n    return null;\n}\nflow.set(\"heater\", heater)\nreturn [msg, {payload: 0}] ;","outputs":2,"noerr":0,"initialize":"","finalize":"","x":570,"y":4300,"wires":[["9b8b2bd1.0f724"],["838bc6ef.d86f4","343a77ae.b9abf8"]]},{"id":"9b8b2bd1.0f724","type":"debug","z":"c74669a0.6a34f8","name":"turn on heaters","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":810,"y":4280,"wires":[]},{"id":"838bc6ef.d86f4","type":"debug","z":"c74669a0.6a34f8","name":"pid","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":770,"y":4340,"wires":[]},{"id":"343a77ae.b9abf8","type":"trigger","z":"c74669a0.6a34f8","name":"","op1":"10000","op2":"1","op1type":"num","op2type":"num","duration":"10","extend":false,"overrideDelay":false,"units":"s","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":360,"y":4240,"wires":[["45cea70.c2295d8"]]},{"id":"45cea70.c2295d8","type":"change","z":"c74669a0.6a34f8","name":"","rules":[{"t":"set","p":"delay","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":550,"y":4240,"wires":[[]]}]

[edit updated function to output to another output if E_load is above 0 but not higher than 800. Also changed delay to make it temporary.
So if a heater is turned on/off, the output to pid/kemo will be 0, but if E_load is above 0 and no heaters where switched the E_load value is outputted to pid.]

Had a bit of time this morning and thought that kemo output could be stored and used to check when to turn on/off static heaters and calculate new kemo setting
here is new revised flow

[{"id":"2b5533e9.fe51b4","type":"inject","z":"c74669a0.6a34f8","name":"-850","props":[{"p":"E_load","v":"-850","vt":"num"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":110,"y":4220,"wires":[["f47c9842.c0e398"]]},{"id":"f47c9842.c0e398","type":"change","z":"c74669a0.6a34f8","name":"","rules":[{"t":"set","p":"delay","pt":"msg","to":"delay","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":250,"y":4300,"wires":[["ccf15383.3648"]]},{"id":"f4b2f5bf.b5df18","type":"inject","z":"c74669a0.6a34f8","name":"850","props":[{"p":"E_load","v":"850","vt":"num"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":110,"y":4380,"wires":[["f47c9842.c0e398"]]},{"id":"a24bf6d2.6fda7","type":"inject","z":"c74669a0.6a34f8","name":"100","props":[{"p":"E_load","v":"100","vt":"num"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":110,"y":4340,"wires":[["f47c9842.c0e398"]]},{"id":"ccf15383.3648","type":"trigger","z":"c74669a0.6a34f8","name":"delay","op1":"","op2":"","op1type":"nul","op2type":"payl","duration":"250","extend":false,"overrideDelay":true,"units":"ms","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":430,"y":4300,"wires":[["4c53645c.a7f41c"]]},{"id":"64c267e1.16fd7","type":"inject","z":"c74669a0.6a34f8","name":"-50","props":[{"p":"E_load","v":"-50","vt":"num"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":110,"y":4260,"wires":[["f47c9842.c0e398"]]},{"id":"4c53645c.a7f41c","type":"function","z":"c74669a0.6a34f8","name":"","func":"let limit = 800, // heater 1-3 turn on limit\nkemolimit = 900, // max value to send to kemo\nheater = flow.get(\"heater\") || 1,\nkemo = flow.get(\"kemo\") || 0;\nif (msg.E_load + kemo >= limit && heater < 4){\n    kemo = msg.E_load + kemo - limit ;\n    msg={payload: \"on\", topic: `heater_${heater}_on`};\n    heater++;\n}else if(msg.E_load + kemo < 0 && heater > 1){\n    heater--;\n    kemo = msg.E_load + kemo + limit;\n    msg={payload: \"off\", topic: `heater_${heater}_on`};\n}else if(msg.E_load + kemo >= 0 || heater === 1){\n    kemo = msg.E_load + kemo\n    msg=null;\n}else  {\n    return null;\n}\nkemo = kemo < 0 ? 0 : (kemo > kemolimit ? kemolimit : kemo)\nflow.set([\"heater\", \"kemo\"], [heater, kemo])\nreturn [msg, {payload: kemo}] ;","outputs":2,"noerr":0,"initialize":"","finalize":"","x":570,"y":4300,"wires":[["9b8b2bd1.0f724"],["838bc6ef.d86f4","343a77ae.b9abf8"]]},{"id":"9b8b2bd1.0f724","type":"debug","z":"c74669a0.6a34f8","name":"turn on heaters 1-3","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":830,"y":4280,"wires":[]},{"id":"838bc6ef.d86f4","type":"debug","z":"c74669a0.6a34f8","name":"kemo","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":780,"y":4340,"wires":[]},{"id":"343a77ae.b9abf8","type":"trigger","z":"c74669a0.6a34f8","name":"","op1":"10000","op2":"1","op1type":"num","op2type":"num","duration":"10","extend":false,"overrideDelay":false,"units":"s","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":360,"y":4240,"wires":[["45cea70.c2295d8"]]},{"id":"45cea70.c2295d8","type":"change","z":"c74669a0.6a34f8","name":"","rules":[{"t":"set","p":"delay","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":550,"y":4240,"wires":[[]]}]


I'm already trying to understand your flows for a couple of hours , first how it is working and second trying to inplement this in my system. With my 3 months experience in programming and node red, it is very hard to do. I appreciate your effort! So it takes some time for me to accumulate..... not only try to fix it but I also want to learn it too!
I will do some test here to understand everything, thanks.
grtz Kris

You need to feed my flow the msg.E_load. It will then take that and add the last use kemo output, If this is greater than the limit it will turn on a heater and store a new heater position. It the works out the remaining power, that is then sent to the kemo output and also stored for next run of the function.
You need to add your mqtt node to the heater on/off output. On the kemo output you would then use the output(which will be 0- 900) to work out how you set the kemo heater. i.e. 0 is 0% and 900 is 100%..
The flow also sets a temporary delay for 10 seconds to allow your meter to update and do it's thing.

If you need to ask what a line does, do not hesitate to ask.

Today I did a life test with your first flow of 02/06, without the Kemo controller.
It works wel, without shattering one heater after one comes in and goes out, nice!
One thing I don't understand is, how does it come that with a delay of 250 msec you can cover the 8 sec delay of the meter? When the mesuremets becomes negatief, the second heater immidiately goes off but the first heater stays in .... very good but strange for me.
Next, I will do a life test of your second flow with the Kemo controller, give me some time :slight_smile:. The sun has to shine for testing, the heaters are already outside the house at this moment..


The delay of 250ms is overridden by msg.delay. So the delay is either 10000ms or 1ms


Today I tested the second flow with the Kemo heater. It is working goog so far! With external factors like washing machine, waterpump and the sun up and does the job very well. I can not believe you dit this good from the first time, amazing! I have made a screenshot:

The chart at the right is the output to the Kemo heater.
One thing, when starting the flow and the hearters are not yet ready (connected), the function starts immediately the heaters one after on other. They get no second start puls when they were connected after the flow started so the heaters don't go on.
Can you provide a reboot/reset of the flow after startup? From then the heaters can folowing to proces. Better then to plug out the raspi and reboot again.
In the mean time I try to understand your second flow to learn more of node-red.
Thanks alot for your help, my goal was to devolop it by myself but like you dit it, it is way to high for me!
Thanks Kris

A simple inject set to fire once at start up that connects to a change node, that sets flow.heater to 1 and flow.kemo to 0. You may also have to send off to all heaters to.
You may also get the second message to the heaters if you set retained to true for each heater, that way when the devices connect to mqtt the broker will send the last message received. so if last was on, it should turn on the mqtt heaters.

I have provided a "reset" button which sets the heater and kemo flow variable in de function to 1 and 0, the same button sets the heaters off and the kemo output to 0, works fine! Had to do a little search on how to do it but it works.
So now, for the next few weeks evaluating the working of the steering.....

Thanks again!

grtz kris


Very interested in this heater module of yours that you are using

I assume that you have removed the POT that it comes with the regulate the output and are instead doing that with through th RPi ?

Can i ask how you did that interfacing ?


Aah its OK read it more thoroughly and i see you are using a servo to control it - nice out of the box thinking - this looks like it would be a good solution for a variable dump load for solar to heat hot water



The setup of the servo and POT.

Grtz Kris

1 Like

nice setup - thanks for the photos


Just wondering how this actually works in operation - i know that many people who try this have issues with the regulation creating flicker in fluorescent lights and LEDs etc.

Have you experienced anything like this ??



Hi craigcurtin,

I was powering the 1500 watt heater, so no flickering :wink:.
Don’t know what it will be with lights….you have to try it!
Grtz Kris

1 Like

Hi Kris,

No sorry i think you misunderstood - i meant when you are running this do you find it has any effect on the lights in your house - due to the rapid switching on and off ?


Hy Graig,
Sorry for the wrong answer.
I have not seen any effect on LED lights when the switch goes on and off. We don’t have any fluorisent lights. So no problem with this.
Grtz Kris

Thanks Kris,

much appreciated - definitely worth a try then