Problem with the Delay Node. Project: Smart EV Charging with a Small PV System Using a Binary ON/OFF Switch

Hallo Community,

I have a small PV system on my balcony, and I am looking for a smart, automated solution to turn the switch ON when there is excess energy and OFF when the energy level is low for a certain time period. The main idea is to create three power levels for charging, depending on the battery level.

The battery’s first level is called “Fast charging for battery level.” When the battery level is below this threshold, the charging relay should turn ON when the PV energy level is above the set “charge low-level battery threshold power charging start.” Since power levels tend to oscillate, I have planned to use delays.

For example: When the variables are:

  • “Fast charging for battery level” = 20%
  • “Charge low-level battery threshold power charging start” = 200W
  • “Actual battery level” = 0%

Then, the charging should start after a delay of 30 seconds if the power level remains above 200W during this time. Once charging has started, if the excess power drops below 200W, the charging should stop after a delay of 15 minutes.

This behavior should change when the battery level exceeds the “Fast charging for battery level” threshold. When the battery level is above this value, the PV energy required to start charging should be higher. In my example, this threshold is now: “Charge normal-level battery threshold power charging start” = 300W.

After reaching the third level of battery the power level also raises higher.

Here is the Visu page:

I have managed to set up everything and distinguish the different settings. However, I am now facing a problem that I cannot solve. The delay nodes do not behave as I initially expected. When one of these conditions is true, the delay node turns ON and OFF at the same time.

I have read about implementing a reset with the delays, but I do not know how to do it.

Hopefully somene can help me solving my problem. I am pretty new at this stuff, so a a more detailed explanation for beginners would be greate!

Thank in advance!

Here are the nodes which i have planed to use.

[{"id":"c140ee9d9cbde4a4","type":"tab","label":"Flow 1","disabled":false,"info":"","env":[]},{"id":"39a28766783f674e","type":"api-current-state","z":"c140ee9d9cbde4a4","name":"Charge Faster level","server":"2744c3c.e3faf3c","version":3,"outputs":2,"halt_if":"$entities('input_number.faster_charging_at_battery_percent').state","halt_if_type":"jsonata","halt_if_compare":"lte","entity_id":"sensor.audi_a3_sportback_tfsi_e_state_of_charge","state_type":"num","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"for":"0","forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":670,"y":380,"wires":[["91202e344b14c5d7"],["8830f424062ff79e"]]},{"id":"aa158d1cb1c86797","type":"api-current-state","z":"c140ee9d9cbde4a4","name":"Stop charging level","server":"2744c3c.e3faf3c","version":3,"outputs":2,"halt_if":"$entities('input_number.stop_charging_at_battery_percent').state","halt_if_type":"jsonata","halt_if_compare":"gt","entity_id":"sensor.audi_a3_sportback_tfsi_e_state_of_charge","state_type":"num","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"for":"0","forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":610,"y":620,"wires":[["59a960987079bed5"],[]]},{"id":"02b8abc08ad6542f","type":"inject","z":"c140ee9d9cbde4a4","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"true","payloadType":"bool","x":150,"y":480,"wires":[["95250916e2016547"]]},{"id":"8830f424062ff79e","type":"api-current-state","z":"c140ee9d9cbde4a4","name":"Under stop charging level","server":"2744c3c.e3faf3c","version":3,"outputs":2,"halt_if":"$entities('input_number.stop_charging_at_battery_percent').state","halt_if_type":"jsonata","halt_if_compare":"lte","entity_id":"sensor.audi_a3_sportback_tfsi_e_state_of_charge","state_type":"num","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"for":"0","forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":710,"y":520,"wires":[["6f49e7f99927c37d"],[]]},{"id":"a8f2c947871b0910","type":"delay","z":"c140ee9d9cbde4a4","name":"","pauseType":"delay","timeout":"30","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":1350,"y":360,"wires":[["9903f0ace90191e8"]]},{"id":"569156d3da776fe3","type":"delay","z":"c140ee9d9cbde4a4","name":"","pauseType":"delay","timeout":"15","timeoutUnits":"minutes","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":1350,"y":440,"wires":[["850c48a116bb537f"]]},{"id":"5c5b3c9cb54b76ee","type":"delay","z":"c140ee9d9cbde4a4","name":"","pauseType":"delay","timeout":"7","timeoutUnits":"minutes","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":1340,"y":580,"wires":[["850c48a116bb537f"]]},{"id":"8211c0a0bfe1395e","type":"delay","z":"c140ee9d9cbde4a4","name":"","pauseType":"delay","timeout":"45","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":1350,"y":520,"wires":[["9903f0ace90191e8"]]},{"id":"95250916e2016547","type":"api-current-state","z":"c140ee9d9cbde4a4","name":"Select Charging Mode","server":"2744c3c.e3faf3c","version":3,"outputs":2,"halt_if":"Smartes Sonnen laden","halt_if_type":"str","halt_if_compare":"is","entity_id":"input_select.charging_mode","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"for":"","forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":400,"y":480,"wires":[["39a28766783f674e","aa158d1cb1c86797"],["2352f2df04899093"]]},{"id":"2352f2df04899093","type":"api-call-service","z":"c140ee9d9cbde4a4","name":"Turn ON charging switch","server":"2744c3c.e3faf3c","version":5,"debugenabled":true,"domain":"input_boolean","service":"turn_on","areaId":[],"deviceId":[],"entityId":["input_boolean.tst_dev_out"],"data":"","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":590,"y":720,"wires":[[]]},{"id":"91202e344b14c5d7","type":"api-current-state","z":"c140ee9d9cbde4a4","name":"Power solar available for charge low level","server":"2744c3c.e3faf3c","version":3,"outputs":2,"halt_if":"$entities('input_number.fast_charg_min_p_for_start').state\t","halt_if_type":"jsonata","halt_if_compare":"gte","entity_id":"sensor.solarpower_power","state_type":"num","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"for":"0","forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":980,"y":360,"wires":[["a8f2c947871b0910"],["569156d3da776fe3"]]},{"id":"6f49e7f99927c37d","type":"api-current-state","z":"c140ee9d9cbde4a4","name":"Power solar available for charge mid level","server":"2744c3c.e3faf3c","version":3,"outputs":2,"halt_if":"$entities('input_number.normal_charg_min_p_for_start').state","halt_if_type":"jsonata","halt_if_compare":"gte","entity_id":"sensor.solarpower_power","state_type":"num","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"for":"0","forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":1020,"y":520,"wires":[["8211c0a0bfe1395e"],["5c5b3c9cb54b76ee"]]},{"id":"59a960987079bed5","type":"api-current-state","z":"c140ee9d9cbde4a4","name":"Power solar available for charge ultra high level","server":"2744c3c.e3faf3c","version":3,"outputs":2,"halt_if":"$entities('input_number.charg_high_min_p_for_start').state","halt_if_type":"jsonata","halt_if_compare":"gte","entity_id":"input_number.dummy_power","state_type":"num","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entityState"}],"for":"0","forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":920,"y":700,"wires":[["3c40a0e08f6c6048"],["be10bf4738af3d9e"]]},{"id":"9903f0ace90191e8","type":"api-call-service","z":"c140ee9d9cbde4a4","name":"Turn ON charging devPort","server":"2744c3c.e3faf3c","version":5,"debugenabled":true,"domain":"input_boolean","service":"turn_on","areaId":[],"deviceId":[],"entityId":["input_boolean.tst_dev_out"],"data":"","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1730,"y":400,"wires":[[]]},{"id":"850c48a116bb537f","type":"api-call-service","z":"c140ee9d9cbde4a4","name":"Turn OFF charging switch devPort","server":"2744c3c.e3faf3c","version":5,"debugenabled":true,"domain":"input_boolean","service":"turn_off","areaId":[],"deviceId":[],"entityId":["input_boolean.tst_dev_out"],"data":"","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1700,"y":680,"wires":[[]]},{"id":"3c40a0e08f6c6048","type":"delay","z":"c140ee9d9cbde4a4","name":"","pauseType":"delay","timeout":"30","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":1350,"y":680,"wires":[["9903f0ace90191e8"]]},{"id":"be10bf4738af3d9e","type":"delay","z":"c140ee9d9cbde4a4","name":"","pauseType":"delay","timeout":"4","timeoutUnits":"minutes","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":1340,"y":740,"wires":[["850c48a116bb537f"]]},{"id":"2744c3c.e3faf3c","type":"server","name":"Home Assistant","addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"","connectionDelay":false,"cacheJson":false,"heartbeat":false,"heartbeatInterval":"","statusSeparator":"","enableGlobalContextStore":false}]

I don’t understand what is meant by the delay sends on and off. Could you elaborate a little more?

1 Like

Thank you very much for your response. For sure, i will try to explain it over an example.

If we look on the upper brunch. There is a query. If the “charge fast level” is TRUE the signal goes to the “Power solar available for charge low level”. Since the if-else statement is also true the signal goes to the delay node and after 30s the signal Turn ON.

As far as good at this point.
So if we now look the oposite case. The “power solar available for charge low level” drops bellow the if-else statement change to FALSE. As shown in the picture below.
Then after 15s delay i will get an OFF signal and another 15s there will be an ON signal at the same time. Since the delay of the upper brunch is still active.

This behaviour is visible in the logger there i will receive at the same time ON and OFF
I am not sure is it visible at all, so i marked it with a red pointer.
Below the image
image

So my main problem is that this first delay of 30s still hits events although the other delay also hits events.
For my opinion it would be logical that the upper part, doesn’t hit that event, since the brunch isn’t TRUE at all.

Below is a picture with ON and in between are OFF events. So therefore you will see “AN”=“ON” few times. .

image

I have read something about a reset of the timer, but i am not sure how to implement it in my particular example.

Thanks in advance for your time and help.
I am very thankful about every idea.

Just in general when you have any node open on the workspace, clicking the help tab will bring up the nodes instructions.

If we look there, there is the option to reset the node.

If the received message has this property set to any value, all outstanding messages held by the node are cleared without being sent.

What this means is if the incoming message has msg.reset, the delay will be cleared. We can add that msg.reset with a change node like so

image

Thnx a lot for your quick response and also for the advice.
As i am pretty new on node red, a bit detailed explanation would be very helpfull.

I have test it with the inject node. That seems to working.
But the problem is i need to do it by pressing the button. How can it perform automatically?

How can i implement it in my Flow?

This is my “current state” node which is located right before the timer. Plese see image below

And this node has two outputs.
The upper one is TRUE if the IF-Statement is fulfilled. → lower one is FALSE.

The lower one is TRUE if the IF-Statement is not fulfilled. → upper one is FALSE
So how can i fit this option inside this current state?

For example:

Thank you in advance for your support!

You can connect it to the lower output and it will cancel the delay from the top. So if the lower delay is activated it will cancel the top delay.

1 Like

Thank you very much Mikefila!

The project is now working. Have a nice Evening