Control ESPEasy-thermostat -> Rules problem

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
hvdwolf
Normal user
Posts: 46
Joined: 09 Jun 2016, 12:37

Control ESPEasy-thermostat -> Rules problem

#1 Post by hvdwolf » 05 Feb 2020, 11:25

I control my thermostat via an ESPEasy with a relais. This ESPEasy is controlled from Pimatic (could also be Domotics/OpenHAB/Home Assitant/etc.) with an extensive rule set which works really nice.
However, during my wintersports holiday, the SD-card in my RapberryPi got corrupted -> No more thermostat control. So my house went from the "fixed" temperature of 15 C to 9.5 C.

The ESPEasy itself is of course capable enough to do this all by itself, so I wanted a backup option which I could control directly..
So I wrote an Android app (see attached reduced images) and created a number of dummy devices.
The ESPEasy is connected to my central heating. The livingroom temperature (via event livingroomtemp) is sent by another ESPEasy with a ds18b20. Both are running on the normal 20191208 ESPEasy version.
This can all be controlled from the webGuid, but I also wanted to be able to do it from my phone, hence the Android app (which I can share by the way).

Devices:
cv-control_Devices.png
cv-control_Devices.png (74.31 KiB) Viewed 658 times
And I created a 3 Rules Sets:
Rules Set 1:

Code: Select all

On System#Boot do    //When the ESP boots, do
  event InitSettings
  timerSet,1,20      //Set Timer 1 for the next event in 20 seconds
endon

On Rules#Timer=1 do  //When Timer1 expires, do
  if [Thermostat#Enabled]=1 and [Thermostat#Automatic]=0 //active and on manual
      if [Thermostat#Setpoint]>[Thermostat#Temperature]
          TaskValueSet,3,1,1
      else
          TaskValueSet,3,1,0
      endif
  endif
  if [Thermostat#Enabled]=1 and [Thermostat#Automatic]=1 //active and on auto
      if %sysweekday_s%=Sat or %sysweekday_s%=Sun
          event weekend
      else
          event weekday
     endif
  timerSet,1,15      //Set Timer 1 for the next event in 15 seconds
endon

on weekend do
  if %systime% > 07:45:00 and %systime% < 07:45:10
      TaskValueSet,2,3,[InitSetpoints#weday]
  endif
  if %systime% > 07:45:10 and %systime% < 22:30:00
      event CheckOnOff
  endif
  if %systime% < 07:45:00 or %systime% < 22:30:00
      TaskValueSet,2,3,[InitSetpoints#wenight]
      event CheckOnOff
  endif
  //timerSet,1,30      //Set Timer 1 for the next event in 30 seconds
endon

on livingroomtemp do
  TaskValueSet,2,2,%eventvalue%
endon
Rules set 2:

Code: Select all

on weekday do
  if %systime% > 06:45:00 and %systime% < 06:45:20
      TaskValueSet 2,3,[InitSetPointsWeekday#wdmorning]
  endif
  if %systime% > 06:45:20 and %systime% < 08:00:00
      event CheckOnOff
  endif
  if %systime% > 08:00:00 and %systime% < 08:00:20
      TaskValueSet 2,3,[InitSetPointsWeekday#wdday]
  endif
  if %systime% > 08:00:20 and %systime% < 16:45:00
      event CheckOnOff
  endif
  if %systime% > 16:45:00 and %systime% < 16:45:20
      TaskValueSet 2,3,[InitSetPointsWeekday#wdevening]
  endif
  if %systime% > 16:45:20 and %systime% < 22:15:00
      event CheckOnOff
  endif
  if %systime% < 06:45:00 or %systime% > 22:15:01
      TaskValueSet 2,3,[InitSetPointsWeekday#wdnight]
      event CheckOnOff
  endif
  //timerSet,1,30      //Set Timer 1 for the next event in 30 seconds
endon

on CheckOnOff
  if Thermostat#Setpoint>Thermostat#Temperature 
      //TaskValueSetAndRun,3,1,1
      GPIO,13,1
  else
      //TaskValueSetAndRun,3,1,0
      GPIO,13,0
  endif
endon
Rules set 3:

Code: Select all

On InitSettings do
  TaskValueSet 2,1,1  //enabled
  //TaskValueSet 2,1,0  //disabled
  TaskValueSet 2,3,18.0 //Setpoint
  TaskValueSet 2,4,1 //Auto=1, manual=0
  Let,1,15  //wdnight
  Let,2,19.5 //wdmorning
  Let,3,18.5 //wdday
  Let,4,20 //wdevening
  TaskValueSet 4,1,[VAR#1]
  TaskValueSet 4,2,[VAR#2]
  TaskValueSet 4,3,[VAR#3]
  TaskValueSet 4,4,[VAR#4]
  // weekend
  Let,5,15.5  //wenight
  Let,6,20 //wemorning
  Let,7,20 //weday
  Let,8,20.5 //weevening
  TaskValueSet 5,1,[VAR#5]
  TaskValueSet 5,2,[VAR#6]
  TaskValueSet 5,3,[VAR#7]
  TaskValueSet 5,4,[VAR#8]

  if %sysweekday_s%=Sat or %sysweekday_s%=Sun
      event initweekend
  else
      event initweekday
  endif
endon


on initweekend do
    if %systime% > 07:45:00 and %systime% < 22:30:00
      TaskValueSetAndRun,2,3,[InitSetPointsWeekend#weday]
    else
      TaskValueSetAndRun,2,3,[InitSetPointsWeekend#wenight]
    endif
endon


on initweekday do
    if %systime% > 06:45:00 and %systime% < 08:00:00
      TaskValueSetAndRun,2,3,[InitSetPointsWeekday#wdmorning]
    endif
    if %systime% > 08:00:00 and %systime% < 16:45:00
      TaskValueSetAndRun,2,3,[InitSetPointsWeekday#wdday]
    endif
    if %systime% > 16:45:00 and %systime% < 22:15:00
      TaskValueSetAndRun,2,3,[InitSetPointsWeekday#wdevening]
    endif
    if %systime% < 06:45:00 or %systime% > 22:15:01
      TaskValueSetAndRun,2,3,[InitSetPointsWeekday#wdnight]
    endif
endon
Everything works fine including my Android app, but for one very essential thing: the heating itself.

Code: Select all

on CheckOnOff
  if Thermostat#Setpoint>Thermostat#Temperature 
      //TaskValueSetAndRun,3,1,1
      GPIO,13,1
  else
      //TaskValueSetAndRun,3,1,0
      GPIO,13,0
  endif
endon
The GPIO command doesn't switch on the heating (I also tried tthe TaskValueSetAndRun command without success and even the sendTo command as in sendTo,30,13,1 or sendTo,30,13,0 where 30 is my unit number).
What am I doing wrong?

And for those seeing the external address in the Settings: I know it is very dangerous, but I can ssh tunnel via my server with an extra encryption on top of it)
Attachments
001-Main.png
001-Main.png (72.71 KiB) Viewed 658 times
002-Main.png
002-Main.png (76.19 KiB) Viewed 658 times
003-WebSettings.png
003-WebSettings.png (167.51 KiB) Viewed 658 times
004-VariablesSettings.png
004-VariablesSettings.png (121.89 KiB) Viewed 658 times

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

Re: Control ESPEasy-thermostat -> Rules problem

#2 Post by grovkillen » 05 Feb 2020, 11:47

Thanks for posting! Good job.
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:

hvdwolf
Normal user
Posts: 46
Joined: 09 Jun 2016, 12:37

Re: Control ESPEasy-thermostat -> Rules problem

#3 Post by hvdwolf » 05 Feb 2020, 12:08

Thanks.

But did you see my question in the last part? ;)
Once that has been fixed I will post it as a project and attach the Android app for those who want to try it themselves.

Everything works fine including my Android app, but for one very essential thing: the heating itself.

Code: Select all

on CheckOnOff
  if Thermostat#Setpoint>Thermostat#Temperature 
      //TaskValueSetAndRun,3,1,1
      GPIO,13,1
  else
      //TaskValueSetAndRun,3,1,0
      GPIO,13,0
  endif
endon
The GPIO command doesn't switch on the heating (I also tried tthe TaskValueSetAndRun command without success and even the sendTo command as in sendTo,30,13,1 or sendTo,30,13,0 where 30 is my unit number).
What am I doing wrong?

TD-er
Core team member
Posts: 2099
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Control ESPEasy-thermostat -> Rules problem

#4 Post by TD-er » 05 Feb 2020, 12:47

Have you added a logitem command in there to see if it does try to set the value?

And if I'm not mistaken, you should also enable gpio monitoring (at boot).
Maybe you can also add a task "switch" which you then run?

hvdwolf
Normal user
Posts: 46
Joined: 09 Jun 2016, 12:37

Re: Control ESPEasy-thermostat -> Rules problem

#5 Post by hvdwolf » 05 Feb 2020, 13:39

I added the monitor,13 to the System#boot.
When pimatic controls it, I see it changing. 2 snippets from the log:

Code: Select all

211228: Command: gpio
211230: SW   : GPIO 13 Set to 1
211318: SW  : GPIO=13 State=1 Output value=1
211325: EVENT: ThermostatState#HeatingStatus=1.00

228385: Command: gpio
228387: SW   : GPIO 13 Set to 0
228543: SW  : GPIO=13 State=0 Output value=0
228546: EVENT: ThermostatState#HeatingStatus=0.00
When I add the LogEntry to the CheckOnOff

Code: Select all

on CheckOnOff
  LogEntry,"In CheckOnOff"
  if Thermostat#Setpoint>Thermostat#Temperature 
      LogEntry,"Setpoint > Temperature"
      //TaskValueSetAndRun,3,1,1
      GPIO,13,1
  else
      //TaskValueSetAndRun,3,1,0
      GPIO,13,0
      LogEntry,"Setpoint <= Temperature"
  endif
endon
I see nothing added to the log, for example:

Code: Select all

133012: Command: event
133019: EVENT: livingroomtemp=20.0
133046: ACT : TaskValueSet,2,2,20.0
133048: Command: TaskValueSet
135389: EVENT: Rules#Timer=1
135474: ACT : event weekday
135475: Command: event
135476: EVENT: weekday
[b]135569: ACT : event CheckOnOff
135570: Command: event
135571: EVENT: CheckOnOff[/b]
135814: ACT : timerSet,1,15
135815: Command: timerSet
139771: HTTP: status,gpio,13
139773: Command: status
but no gpio changes. What is, or what am I doing wrong?

And the question
Maybe you can also add a task "switch" which you then run?
is not clear to me. Can you please explain?

Domosapiens
Normal user
Posts: 300
Joined: 06 Nov 2016, 13:45

Re: Control ESPEasy-thermostat -> Rules problem

#6 Post by Domosapiens » 05 Feb 2020, 16:55

on CheckOnOff
Must be
on CheckOnOff do
30+ ESP units for production and test. Ranging from control of heating equipment, flow sensing, floor temp sensing, energy calculation, floor thermostat, water usage, to an interactive "fun box" for my grandson. Mainly Wemos D1.

hvdwolf
Normal user
Posts: 46
Joined: 09 Jun 2016, 12:37

Re: Control ESPEasy-thermostat -> Rules problem

#7 Post by hvdwolf » 05 Feb 2020, 17:05

Unbelievable that I overlooked that for so long. :shock:

Thanks a lot. That did it.

hvdwolf
Normal user
Posts: 46
Joined: 09 Jun 2016, 12:37

Re: Control ESPEasy-thermostat -> Rules problem

#8 Post by hvdwolf » 08 Feb 2020, 12:51

Well, I needed some more changes.

In my first post you can see in Rules Set 1 that I have nested if commands. That is not allowed and therefore doesn't work (and was also overlooked by the gurus on this forum ;)), which I just discovered this weekend as it remained on weekday.

Secondly, which is my stupid fault: On every Timerset1 I check setpoint and switch on/off the relay.
Coincidence or not: my relay was broken this morning. The nodemcu/EspEasy nicely switched on/off but the relay did not activate. I replaced the relay and everything works again.
I will build another if-else: if already on (or off) do not switch again on (or off).

I could not find anything about this, but perhaps a pulse every 15-20 seconds for 6 days (~ 25900 pulses) is too much, also after 3~4 years "normal" use via pimatic. Should these (cheap Chinese) relays be able to cope with that?

TD-er
Core team member
Posts: 2099
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Control ESPEasy-thermostat -> Rules problem

#9 Post by TD-er » 08 Feb 2020, 22:21

Please also check to see if you have a diode over the relay to protect the switching electronics.
The coil of the relay may cause a voltage spike when it is deactivated, which may destroy the transistor switching it.

Post Reply

Who is online

Users browsing this forum: No registered users and 11 guests