Looping the Loop without getting dizzy

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
gregoinc
Normal user
Posts: 65
Joined: 21 Jan 2019, 06:08
Location: Australia

Looping the Loop without getting dizzy

#1 Post by gregoinc » 04 Feb 2019, 03:24

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

User avatar
grovkillen
Core team member
Posts: 3621
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: Looping the Loop without getting dizzy

#2 Post by grovkillen » 04 Feb 2019, 05:48

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.
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you :idea: :idea: :idea:

gregoinc
Normal user
Posts: 65
Joined: 21 Jan 2019, 06:08
Location: Australia

Re: Looping the Loop without getting dizzy

#3 Post by gregoinc » 04 Feb 2019, 06:36

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

User avatar
grovkillen
Core team member
Posts: 3621
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: Looping the Loop without getting dizzy

#4 Post by grovkillen » 04 Feb 2019, 07:15

No problem. I approve your rules.
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you :idea: :idea: :idea:

gregoinc
Normal user
Posts: 65
Joined: 21 Jan 2019, 06:08
Location: Australia

Re: Looping the Loop without getting dizzy

#5 Post by gregoinc » 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

User avatar
grovkillen
Core team member
Posts: 3621
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: Looping the Loop without getting dizzy

#6 Post by grovkillen » 04 Feb 2019, 19:42

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.
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you :idea: :idea: :idea:

User avatar
iron
Normal user
Posts: 221
Joined: 24 Sep 2016, 08:37
Location: Greece
Contact:

Re: Looping the Loop without getting dizzy

#7 Post by iron » 05 Feb 2019, 14:43

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
-D

gregoinc
Normal user
Posts: 65
Joined: 21 Jan 2019, 06:08
Location: Australia

Re: Looping the Loop without getting dizzy

#8 Post by gregoinc » 05 Feb 2019, 22:57

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 :)

Post Reply

Who is online

Users browsing this forum: No registered users and 33 guests