# Home battery charging logic

**URL:** <https://discourse.nodered.org/t/home-battery-charging-logic/74046>\
**Category:** Share Your Projects\
**Created:** [22 January 2023 10:18 UTC](https://discourse.nodered.org/t/home-battery-charging-logic/74046 "2023-01-22T10:18:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rhysgh](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/rhysgh/32/74195_2.png) [@Rhysgh](https://discourse.nodered.org/u/Rhysgh)\
**Post date:** [22 January 2023 10:18 UTC](https://discourse.nodered.org/t/home-battery-charging-logic/74046/1 "2023-01-22T10:18:45Z")

</div>

OK, I set this up in node-red.. i think I'm happy with it less a tidy-up and a better trigger.

Trigger - Charge  
Set force charge on via Modbus  
wait 4 min  
check the battery mode via API (hence 4 min wait)  
if battery mode force charge, then send notification success  
if battery mode is not forced, send force charge command again, then wait another 4 min before checking again. (this can repeat 4 times before failing and notifying of a failure)

Target - stop charge  
check battery mode is forced charge  
if it isn't, do nothing (it will have been on 30 min at least by this point, so I assume there's no need to check more than once)  
if it is then send stop force charge command  
wait 4 min  
check battery mode isn't forced charge  
if it is, then send the command again ( repeat up to 4 times before failing and sending a notification)  
if it is not force charge then send a notification successful.

Is my logic sound? have I missed anything?  
Can anyone give a better way than checking the battery state to check the command was successful?

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/8/7802b4b18a9ffe0807746cdec1e81f1dc58692cb.jpeg)

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [22 January 2023 14:31 UTC](https://discourse.nodered.org/t/home-battery-charging-logic/74046/2 "2023-01-22T14:31:59Z")

</div>

Loops are a no-no in node-red (unless all possible scenarios are properly captured).

What if you receive multiple "Price Drops" updates ? Your flow will get triggered multiple times, with multiple timers running with potentially various outcomes if states changes in the meantime.

---

<div class="post-metadata">

**Author:** ![Rhysgh](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/rhysgh/32/74195_2.png) [@Rhysgh](https://discourse.nodered.org/u/Rhysgh)\
**Post date:** [23 January 2023 12:22 UTC](https://discourse.nodered.org/t/home-battery-charging-logic/74046/3 "2023-01-23T12:22:58Z")

</div>

The trigger can only be on or off every 30 min max (price drops aren't the correct terminology)  
The trigger is true when there is an applicable 30 min window,, that window may stay open for 4 hours or it may only be 30 min but never less than 30 min.

The point was well taken though but I think I dodge that this time .. you can see I break the loops when success is passed so it's ready to start again.
