Page 1 of 1

Problem with a rule set if-statement

Posted: 09 Feb 2025, 20:35
by RonkA
Context:
I have an electric boiler to get hot water(duh..) manly for showering.
To reduce the electricity bill i added a heat exchanger to preheat the cold tapwater entering the boiler when it is being used.

The heat exchanger is getting its warm water from a buffertank that is being heated from a woodstove in my house.
I placed temperature sensors onto all the lines entering and leaving the heat exchanger and after the install time to test it working manually.. and its a success!!

But now to automate this..
In the tabwater-line i added a hall-effect flowmeter so i can sense when there is warm water being used installed this onto my esp8266 and after some callibration this is also working correct. the interval i set to 10 seconds

In my Domoticz setup i added a dummy-switch (idx 359)that i can use to see if there is hot water being used and i made a rule to get this done:

Code: Select all

On BoilerWarmWaterVraag#Count do
 if [BoilerWarmWaterVraag#Count]>0.010
   SendToHTTP,<user>:<password>@192.168.178.2,7080,/json.htm?type=command&param=switchlight&idx=359&switchcmd=On
 endif
 if [BoilerWarmWaterVraag#Count]=0
   SendToHTTP,<user>:<password>@192.168.178.2,7080,/json.htm?type=command&param=switchlight&idx=359&switchcmd=Off 
  endif
endon
and this works! Hurray!!
The only thing i don't like is that every 10 seconds these commands are sent cluttering the logs so i tried to expand on this rule..

Problem:
I added a Internal variable to get a counter going, the counter starts adding 1 to it when the flowmeter is measuring flow. and send the command to switch on the dummy swich. also 1 is added to the counter.
when the counter gets to 3 the command wil not send anymore to domoticz.

When the flow measured zero and the counter is more or equal to 2 the off command is sent and 1 is substracted from the counter until the counter hits 1 and every thing is paused until again water is flowing..
This reduces the commands beeing sent to 4 (double to be shure..) in stead of 360 an hour.

Code: Select all

On BoilerWarmWaterVraag#Count do
 if [BoilerWarmWaterVraag#Count]>0.010 and [var#1]>3
   SendToHTTP,<user>:<password>@192.168.178.2,7080,/json.htm?type=command&param=switchlight&idx=359&switchcmd=On
   Let,1,[var#1]+1
 endif
 if [BoilerWarmWaterVraag#Count]=0 and [var#1]>=2
   SendToHTTP,<user>:<password>@192.168.178.2,7080,/json.htm?type=command&param=switchlight&idx=359&switchcmd=Off 
   Let,1,[var#1]-1
  endif
endon
In (my) theory this should be working but it doesn't and i don't see why.. Some info into this failing is greatly appreciated.

Re: Problem with a rule set if-statement

Posted: 09 Feb 2025, 21:08
by ThomasB
Seems to me you want to do this instead (untested):

Code: Select all

On BoilerWarmWaterVraag#Count do
 if [BoilerWarmWaterVraag#Count]>0.010
   if[var#1]=3
     Let,1,4 // Prevent repeat http.
     SendToHTTP,<user>:<password>@192.168.178.2,7080,/json.htm?type=command&param=switchlight&idx=359&switchcmd=On
   elseif[var#1]<3
     Let,1,[var#1]+1
   endif
 endif
 
 if [BoilerWarmWaterVraag#Count]=0 AND [var#1]>0
     Let,1,0 // Prevent repeat http
     SendToHTTP,<user>:<password>@192.168.178.2,7080,/json.htm?type=command&param=switchlight&idx=359&switchcmd=Off 
 endif
endon
- Thomas

Re: Problem with a rule set if-statement

Posted: 09 Feb 2025, 21:59
by TD-er
And the bug in your code is that you will only increment the counter when the variable is > 3 (not >= 3)
It will decrement when >= 2.

See the issue? What is variable = 3?
Then it will only decrement and never increment anymore.

Re: Problem with a rule set if-statement

Posted: 10 Feb 2025, 00:40
by RonkA
Thanks both gentlemen for your input. I had code-blindness happen to me...

@ThomasB; your solution IS working but not as intended.
When rule is run and there is #count>0.010, it takes 3 cycles of 10 seconds before the SendToHTTP-on runs once.(so not 2 times..)
then if count=0 SendToHTTP-off it directly also runs once.

@TD-er; '>3' changed to '<3' and the script runs Purrfect...

ESPeasy is fun. when you get it to do wat's in your mind...