Page 1 of 1

Looping the Loop without getting dizzy

Posted: 04 Feb 2019, 03:24
by gregoinc
Hello,

Have been developing the rules code below to activate an air conditioner. I have limited exposure to ESPEasy, and I am not totally comfortable with the various if, then, else type loops. The code below works, but I wouldn't say it was an 'elegant' way to do the job.

So I am looking for your advice... what suggestions do you have to improve my rules code?

Code: Select all

On Temp2#Temperature do
   if [Temp2#Temperature] > [Temp1#Temperature] and [Temp1#Temperature] > 25
   Event,StartHP
   endif
endon

On Temp2#Temperature do
   if [Temp2#Temperature] < [Temp1#Temperature] and [Temp2#Temperature] = 21
   Event,StopHP
   endif
endon

on Temp1#Temperature do
   if [Temp1#Temperature] > 27
    Event,StartHP
   endif
endon

On StartHP Do
If [counter#dummy]=0
 heatpumpir,daikin,1,3,0,24,4,2
 TaskValueSet 4,1,1
EndIf
EndOn

On StopHP Do
If [counter#dummy]=1
 heatpumpir,daikin,0,3,0,24,4,2
 TaskValueSet 4,1,0
EndIf
EndOn

Re: Looping the Loop without getting dizzy

Posted: 04 Feb 2019, 05:48
by grovkillen
Why isn't it elegant you'd say? I find it as good as can be considering that the rules engine is not a complete programming language.

Re: Looping the Loop without getting dizzy

Posted: 04 Feb 2019, 06:36
by gregoinc
Hi Grovkillen,

The non-elegant reference was a critique of my coding skills, not in any way being critical of the rules engine (which has been the best I've found for low level beginners like me). I thought my efforts were average at best, which is why I posted seeking some guidance. Apology for any confusion if I caused it :)

Thanks, Mark

Re: Looping the Loop without getting dizzy

Posted: 04 Feb 2019, 07:15
by grovkillen
No problem. I approve your rules.

Re: Looping the Loop without getting dizzy

Posted: 04 Feb 2019, 10:28
by gregoinc
Hi Grovkillen,

Thank you. One section of the code I wanted to improve is this area below...

Code: Select all

On Temp2#Temperature do
   if [Temp2#Temperature] < [Temp1#Temperature] and [Temp2#Temperature] = 21
   Event,StopHP
   endif
endon
- I wanted to perform the temperature check as a range instead of just 21 degrees i.e. the StopHP executes when the temperature is between 20 to 21 degrees.

Code: Select all

if [Temp2#Temperature] < [Temp1#Temperature] and [Temp2#Temperature] = 21
Can the and [Temp2#Temperature] = 21 be written in such a way to check for a range?

- The other thing I wanted to solve, was once the temperature range is met (i.e. 20 - 21) and the StopHP has been executed, the endif stops... because right now as long as the temperature stays at 21 the rule keeps executing in the log. Yes the StopHP section has a TaskValueSet so the heatpumpir on executes once, but I would like to stop the looping in the code above.

Hope I have explained this correctly?

Thanks, Mark

Re: Looping the Loop without getting dizzy

Posted: 04 Feb 2019, 19:42
by grovkillen
I don't understand why the log entries are a problem for you? We could off course get it to do the AND/OR but that would not make the rule any better. So if the current rule are behaving as expected, I'd suggest you leave it. Don't you worry about the log.

Re: Looping the Loop without getting dizzy

Posted: 05 Feb 2019, 14:43
by iron
gregoinc wrote: 04 Feb 2019, 10:28 Hi Grovkillen,

Thank you. One section of the code I wanted to improve is this area below...

Code: Select all

On Temp2#Temperature do
   if [Temp2#Temperature] < [Temp1#Temperature] and [Temp2#Temperature] = 21
   Event,StopHP
   endif
endon
- I wanted to perform the temperature check as a range instead of just 21 degrees i.e. the StopHP executes when the temperature is between 20 to 21 degrees.

Code: Select all

if [Temp2#Temperature] < [Temp1#Temperature] and [Temp2#Temperature] = 21
Can the and [Temp2#Temperature] = 21 be written in such a way to check for a range?

- The other thing I wanted to solve, was once the temperature range is met (i.e. 20 - 21) and the StopHP has been executed, the endif stops... because right now as long as the temperature stays at 21 the rule keeps executing in the log. Yes the StopHP section has a TaskValueSet so the heatpumpir on executes once, but I would like to stop the looping in the code above.

Hope I have explained this correctly?

Thanks, Mark
Why just =21 ?
What will happen if for some/any reason Temp2 drops to 19 prior to getting in the event ?

-D

Re: Looping the Loop without getting dizzy

Posted: 05 Feb 2019, 22:57
by gregoinc
iron wrote: 05 Feb 2019, 14:43
Why just =21 ?
What will happen if for some/any reason Temp2 drops to 19 prior to getting in the event ?

-D
Hi Iron,

You are correct, and to be honest I am still finding my way forward, which is why I sought feedback.

In a nutshell, the code...

Code: Select all

if [Temp2#Temperature] < [Temp1#Temperature] and [Temp2#Temperature] = 21
Was my first attempt at saying.... if the outside temperature is lower than the indoors temperature then we should look at turning off the air conditioner. The last part is a final check to the first part... if the outside temp is lower than inside and the outside temp is at 21 degrees celcius, then turn off the air conditioner.

We've had situations where the outside temp dips below the inside temp, but doesn't get low enough to allow the inside temp to remain at a reasonable temperature without air conditioning. So the 21 check is an attempt to make sure the inside temp will stay at a reasonable level without the air conditioner running.

And you are correct... if the outside temp drops below 21 before the event then we are potentially in trouble... which is something I have been worried about, and was why I was wondering if that 'check' could be done on a temperature range and not a single figure.

I am new to all this... so open to other ideas if there's a better way to do it :)