Rules in ESPeasy

Moderators: grovkillen, Stuntteam, TD-er

Message
Author
Frank0972
New user
Posts: 1
Joined: 16 Nov 2019, 19:52

Rules in ESPeasy

#1 Post by Frank0972 » 25 Jan 2021, 20:25

Hello Everybody,

i would like to do the following thing with the ESPeasy. I would like to build a thermostat which should have a fixed value when starting and when the connection to the mqtt server is lost. I would then like to be able to change the setpoint via mqtt. The actual value comes from a DS18b20 temp sensor. I could build this in node red without problems, but I would like the control to be on the ESP, because if the connection to node red is lost, I will not have hot water to shower the next morning. and that could cause problems with my wife. Can someone give me a suggestion on how best to start this? Or where is there a good tutorial on rules?

many Greetings

Frank

User avatar
Ath
Normal user
Posts: 3417
Joined: 10 Jun 2018, 12:06
Location: NL

Re: Rules in ESPeasy

#2 Post by Ath » 25 Jan 2021, 21:09

A few questions:
- Can we assume the DB18b20 is directly connected to the ESP?
- How are you going to validate/check the current setpoint value when MQTT or WiFi isn't available?
- How are you manually going to change the setpoint value in a disconnected situation?
/Ton (PayPal.me)

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

Re: Rules in ESPeasy

#3 Post by TD-er » 25 Jan 2021, 21:59

The "level" plugin allows to set a threshold, but it does write the settings every time you change the value.
So I would rather not change it too often or you run into issues.

You can also store the set value in a dummy, which will be kept even after a reboot or crash. As long as you don't have a power cycle... but then you probably also would have lost the settings on your thermostat, so your wife will probably accept that as an excuse :)

kimot
Normal user
Posts: 190
Joined: 12 Oct 2017, 20:46

Re: Rules in ESPeasy

#4 Post by kimot » 04 Mar 2021, 21:52

Look here:

https://www.youtube.com/watch?v=1ef6tRinOQ4

You can define fixed value for thermostat in boot section ( TaskValueSet,2,2 ) :

Code: Select all

On System#Boot do
 gpio,13,1
 gpio,12,0 
 TaskValueSet,2,2,10  // initial Setpoint
 TaskValueSet,2,3,0   
 TaskValueSet,2,4,0  //mode
 TaskValueSet,2,1,0  //HDO
  timerSet,1,60
endon

In case of controller failure, it will remember last received value.
And if you need change it, then simply connect to rules tab on web page of your ESP, change initial setpoint
to required value and reboot.

igorka
Normal user
Posts: 74
Joined: 17 Jul 2022, 13:41
Location: Ukraine

Re: Rules in ESPeasy

#5 Post by igorka » 02 Dec 2022, 19:43

TD-er wrote: 25 Jan 2021, 21:59 You can also store the set value in a dummy, which will be kept even after a reboot or crash. As long as you don't have a power cycle... but then you probably also would have lost the settings on your thermostat, so your wife will probably accept that as an excuse :)
You can explain in more detail how to configure and maintain a value in a fictitious mode. I, too, would be a hotel to change the settings of the margin through MQTT. And so that after turning off the power, they remain on the ESP.
This is what the code looks like now. There is an alarm, with an uncontrolled decrease and temperature increase. In case the contacts of the relay are sticking or vice versa, contact will disappear.
In principle, everything suits me. But to make it perfect, I would like to change values through MQTT.

Code: Select all

On System#Boot do
  let,1,0
  tone,3,1500,500
  loopTimerSet,1,60
  loopTimerSet,2,1
endon
on sensor#temperature do
  if %eventvalue1% < 22.00
      let,1,1
  endif
  if %eventvalue1% < 27.00
  gpio,0,0
  endif
  if %eventvalue1% > 28.15
  gpio,0,1
  let,1,0
  endif
if %eventvalue1% > 30.0
  let,1,2
  endif
endon
on Rules#Timer=1 do
 if [int#1]=1
   tone,3,1000,50
     endif
endon
on Rules#Timer=2 do
 if [int#1]=2
   tone,3,1000,100
     endif
endon
It would be possible to stop timers more correctly when they are not needed, but this can be quickly fixed.

User avatar
Ath
Normal user
Posts: 3417
Joined: 10 Jun 2018, 12:06
Location: NL

Re: Rules in ESPeasy

#6 Post by Ath » 02 Dec 2022, 20:07

You should have a look at P109: Display - ThermoOLED, that does exactly what you need, but requires a 128x64 pixel SSD1306/SH1106 OLed display (I2C) to be used. Using the MQTT Import plugin you can use the "thermo,setpoint,<temperature>" command to change the setpoint.
Documentation for that plugin is quite slim (non-existent), but configuration is quite straightforward. It saves the setpoint temp. as few times as possible to reduce the Flash wearing out. Settings can easily be changed using a few push buttons.
This PR #4098 has a lot of info about that plugin and how to use/configure it.
/Ton (PayPal.me)

igorka
Normal user
Posts: 74
Joined: 17 Jul 2022, 13:41
Location: Ukraine

Re: Rules in ESPeasy

#7 Post by igorka » 07 Dec 2022, 11:16

Ath wrote: 02 Dec 2022, 20:07 You should have a look at P109
Thank you friend!
To be honest, for my solution of my problem, this approach is redundant. It's more visual and informative with the display, but I don't need it, the mqtt app on the MQTT Dash phone is enough. It is very simple and probably this is its minus, at the same time it is also a plus.
I am puzzling over the fact that the changed values are not written immediately to the flash, but with a time delay (later I will check whether the value has changed, to allow or prohibit re-recording). I tried this rule. Yes, it doesn't work and I guessed it. But how to do this right?

Code: Select all

On heater#ustlow do
 logentry,"MQTT import ustlow: %eventvalue1%"
 loopTimerSet,3,10
 //TaskValueSet 3,1,[floor#temperature]%eventvalue1%
endon
on Rules#Timer=3 do
TaskValueSet 3,1,[floor#temperature]%eventvalue1%
loopTimerSet,3,0
endon

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

Re: Rules in ESPeasy

#8 Post by TD-er » 07 Dec 2022, 11:30

Code: Select all

On heater#ustlow do
 logentry,"MQTT import ustlow: %eventvalue1%"
 loopTimerSet,3,10
 //TaskValueSet 3,1,[floor#temperature]%eventvalue1%
endon
on Rules#Timer=3 do
TaskValueSet 3,1,[floor#temperature]%eventvalue1%
loopTimerSet,3,0
endon
You're using the looptimer, so no need to reset the looptimer inside the Rules#Timer=3 block.

Code: Select all

On heater#ustlow do
 logentry,"MQTT import ustlow: %eventvalue1%"
 loopTimerSet,3,10
 //TaskValueSet 3,1,[floor#temperature]%eventvalue1%
endon
on Rules#Timer=3 do
TaskValueSet 3,1,[floor#temperature]%eventvalue1%
// loopTimerSet,3,0 // TD-er: Not needed
endon
Then this part:

Code: Select all

TaskValueSet 3,1,[floor#temperature]%eventvalue1%
The rules timer doesn't have the same eventvalue as you got from the MQTT import.

Also the "[floor#temperature]%eventvalue1%" is probably not what you would want.

Imagine "[floor#temperature]" is "20.0" and "%eventvalue1%" (or more likely you want [heater#ustlow] ) is "10"
Then [floor#temperature]%eventvalue1% would be replaced with 20.010 before it is being parsed.

igorka
Normal user
Posts: 74
Joined: 17 Jul 2022, 13:41
Location: Ukraine

Re: Rules in ESPeasy

#9 Post by igorka » 07 Dec 2022, 12:56

Please excuse me, I didn't understand you well (Google translit). Or I don't speak well... I need to set thresholds for turning on and off the thermostat from the application in the phone, using the mqtt protocol. To do this, I created a dummy device where two variables are low and high, how can I substitute these variables into the rules where I have 27.00 and 28.00?

Code: Select all

On System#Boot do
  let,1,0
  tone,3,1000,250
  loopTimerSet,1,60
  loopTimerSet,2,1
endon
on sensor#temperature do
  if %eventvalue1% < 22.00
      let,1,1
  endif
  if %eventvalue1% <27.00//how can I substitute the value from the low variable, a dummy device, here?
  gpio,0,0
  endif
  if %eventvalue1% > 28.00//how can I substitute the value from the high variable, a dummy device, here?
  gpio,0,1
  let,1,0
  endif
if %eventvalue1% > 30.00
  let,1,2
  endif
endon
on Rules#Timer=1 do
 if [int#1]=1
   tone,3,1000,50
     endif
endon
on Rules#Timer=2 do
 if [int#1]=2
   tone,3,1000,100
     endif
endon
On heater#ustlow do
 logentry,"MQTT import ustlow: %eventvalue1%"
 TaskValueSet 3,1,[floor#temperature]%eventvalue1%
endon
On heater#usthigh do
 logentry,"MQTT import usthigh: %eventvalue1%"
 TaskValueSet 3,2,[floor#temperature]%eventvalue1%
endon
I hope I was able to explain what I want to do. I would like to do it... :D
Last edited by igorka on 07 Dec 2022, 15:24, edited 1 time in total.

User avatar
Ath
Normal user
Posts: 3417
Joined: 10 Jun 2018, 12:06
Location: NL

Re: Rules in ESPeasy

#10 Post by Ath » 07 Dec 2022, 13:31

That should be something like this:

Code: Select all

On System#Boot do
  let,1,0
  tone,3,1000,250
  loopTimerSet,1,60
  loopTimerSet,2,1
endon
on sensor#temperature do
  if %eventvalue1% < 22.00
    let,1,1
  endif
  if %eventvalue1% < [telephone#low]
    gpio,0,0
  endif
  if %eventvalue1% > [telephone#high]
    gpio,0,1
    let,1,0
  endif
  if %eventvalue1% > 30.00
    let,1,2
  endif
endon
on Rules#Timer=1 do
  if [int#1]=1
    tone,3,1000,50
  endif
endon
on Rules#Timer=2 do
  if [int#1]=2
    tone,3,1000,100
  endif
endon
On heater#ustlow do
  logentry,"MQTT import ustlow: %eventvalue1%"
  TaskValueSet telephone,low,%eventvalue1%
endon
On heater#usthigh do
  logentry,"MQTT import usthigh: %eventvalue1%"
  TaskValueSet telephone,high,%eventvalue1%
endon
/Ton (PayPal.me)

igorka
Normal user
Posts: 74
Joined: 17 Jul 2022, 13:41
Location: Ukraine

Re: Rules in ESPeasy

#11 Post by igorka » 07 Dec 2022, 16:32

Ath wrote: 07 Dec 2022, 13:31 That should be something like this:
Thanks! That's exactly what I wanted.
So I made a re-write protection if the value has not changed:

Code: Select all

On heater#ustlow do
 logentry,"MQTT import ustlow: %eventvalue1%"
 if [telephone#low] = %eventvalue1%
      tone,3,150,100
	else
	TaskValueSet 3,1,[floor#temperature]%eventvalue1%
	tone,3,1000,100
  endif
 endon
On heater#usthigh do
 logentry,"MQTT import usthigh: %eventvalue1%"
 if [telephone#high] = %eventvalue1%
      tone,3,150,100
	else
	TaskValueSet 3,2,[floor#temperature]%eventvalue1%
	tone,3,1000,100
  endif
endon
How to correctly implement a delay for re-recording (for example, once every 60 seconds)? That's what I'm having a hard time with so far...

User avatar
Ath
Normal user
Posts: 3417
Joined: 10 Jun 2018, 12:06
Location: NL

Re: Rules in ESPeasy

#12 Post by Ath » 07 Dec 2022, 17:16

igorka wrote: 07 Dec 2022, 16:32

Code: Select all

On heater#ustlow do
	TaskValueSet 3,1,[floor#temperature]%eventvalue1%
That's not correct (I corrected it in my sample code), should be:

Code: Select all

	TaskValueSet 3,1,%eventvalue1%
Similar for 3,2 (or telephone,high as you can also use the names in TaskValueSet)
/Ton (PayPal.me)

User avatar
Ath
Normal user
Posts: 3417
Joined: 10 Jun 2018, 12:06
Location: NL

Re: Rules in ESPeasy

#13 Post by Ath » 07 Dec 2022, 17:16

igorka wrote: 07 Dec 2022, 16:32 How to correctly implement a delay for re-recording (for example, once every 60 seconds)? That's what I'm having a hard time with so far...
Not sure what you mean with "re-recording" ?
/Ton (PayPal.me)

igorka
Normal user
Posts: 74
Joined: 17 Jul 2022, 13:41
Location: Ukraine

Re: Rules in ESPeasy

#14 Post by igorka » 07 Dec 2022, 18:26

Ath wrote: 07 Dec 2022, 17:16 That's not correct (I corrected it in my sample code), should be:
I have corrected according to your example. Now everything is correct.
Ath wrote: 07 Dec 2022, 17:16 Not sure what you mean with "re-recording" ?
This is the right question! I mistakenly assumed that after the power was turned off, the contents of the variables low [telephone#low] and high [telephone#high] would remain in flash memory. It turned out that it works only after a reboot, and if you completely remove the power, the data will disappear! And since I thought that the values of variables are stored in flash, I made a rule from unnecessary entries... I am very disappointed with this fact. You will have to set the temperature again every time after a power outage, or prescribe it rigidly in the rules as you did from the very beginning. Maybe I'm wrong, correct me?

User avatar
chromo23
Normal user
Posts: 821
Joined: 10 Sep 2020, 16:02
Location: germany

Re: Rules in ESPeasy

#15 Post by chromo23 » 07 Dec 2022, 18:36

I can recommend the Level-Control plugin to you.
You can set a temperature. It get´s stored permanently and you can change the setpoint with a command like you already did.
The only downside is, that you can set the hysteresis only in the plugin itself. Usually this is not an issues but maybe you have some special needs.
https://espeasy.readthedocs.io/en/lates ... #p021-page

igorka
Normal user
Posts: 74
Joined: 17 Jul 2022, 13:41
Location: Ukraine

Re: Rules in ESPeasy

#16 Post by igorka » 07 Dec 2022, 18:56

Thanks. I will definitely try to test this plugin!
Another question: I have reverse control, logical zero is included, logical unit is disabled. Is it possible to set these parameters in this plugin? Or will I have to do an inversion at the output through the rules?

User avatar
chromo23
Normal user
Posts: 821
Joined: 10 Sep 2020, 16:02
Location: germany

Re: Rules in ESPeasy

#17 Post by chromo23 » 07 Dec 2022, 19:15

Another question: I have reverse control, logical zero is included, logical unit is disabled. Is it possible to set these parameters in this plugin? Or will I have to do an inversion at the output through the rules?
Can you elaborate? I don’t understand what you mean.

User avatar
Ath
Normal user
Posts: 3417
Joined: 10 Jun 2018, 12:06
Location: NL

Re: Rules in ESPeasy

#18 Post by Ath » 07 Dec 2022, 19:16

That power off issue doesn't exist when using P109, ThermoOLED, that seems to do what you want, and you can still control from MQTT states via rules...
/Ton (PayPal.me)

igorka
Normal user
Posts: 74
Joined: 17 Jul 2022, 13:41
Location: Ukraine

Re: Rules in ESPeasy

#19 Post by igorka » 08 Dec 2022, 09:05

chromo23 wrote: 07 Dec 2022, 19:15 Can you elaborate? I don’t understand what you mean.
It's very simple. I use the ESP-01S module, with an expansion board for it (relay module). By default, the relay is controlled by GPIO.0, and the circuit design of the relay module is such that in order to turn on the relay, on the GPIO.0 you need to submit "0". In my understanding, this is the reverse control logic (inverse). On, it's "0", off, it's "1". I hope you understand me. You can ask a question why I use these modules. I answer, I have "a lot" of them and their "power" is more than enough for me, so everything in the house works for them... In general, it turned out as I thought, if you enable direct GPIO control in the plugin settings.0, everything works the other way around.
ESP-01S.jpg
ESP-01S.jpg (36.11 KiB) Viewed 9448 times
I wrote a simple rule and now it works correctly:

Code: Select all

on thermostat#relay do
if %eventvalue1% = 1
GPIO,0,0
else
GPIO,0,1
endif
if %eventvalue1% = 0
GPIO,0,1
else
GPIO,0,0
endif
endon
I assume that Google translit distorts what I really want to say - write. :oops:
Ath wrote: 07 Dec 2022, 19:16 That power off issue doesn't exist when using P109, ThermoOLED, that seems to do what you want, and you can still control from MQTT states via rules...
My build ESPEasy_ESP82xx_mega-20220616 does not have this plugin.Or not for a 1 MB flash. :roll:
Last edited by igorka on 08 Dec 2022, 09:23, edited 1 time in total.

User avatar
Ath
Normal user
Posts: 3417
Joined: 10 Jun 2018, 12:06
Location: NL

Re: Rules in ESPeasy

#20 Post by Ath » 08 Dec 2022, 09:13

igorka wrote: 08 Dec 2022, 09:05
Ath wrote: 07 Dec 2022, 19:16 That power off issue doesn't exist when using P109, ThermoOLED, that seems to do what you want, and you can still control from MQTT states via rules...
My build ESPEasy_ESP82xx_mega-20220616 does not have this plugin.Or not for a 1 MB flash. :roll:
That plugin is only available in the Display build, but that is not available for 1MB devices. You can create a Custom build that includes the P109 plugin, documented here. If you are unable to create a Custom build, you can request it here, and I'll try to build it for you, later this evening (CET).
/Ton (PayPal.me)

igorka
Normal user
Posts: 74
Joined: 17 Jul 2022, 13:41
Location: Ukraine

Re: Rules in ESPeasy

#21 Post by igorka » 08 Dec 2022, 09:22

I will be grateful and grateful to you if you create an assembly for me. But after all, the plugin can be used without a display? I don't have it and I just don't need it in this product.

User avatar
chromo23
Normal user
Posts: 821
Joined: 10 Sep 2020, 16:02
Location: germany

Re: Rules in ESPeasy

#22 Post by chromo23 » 08 Dec 2022, 09:42

Ath wrote: 07 Dec 2022, 19:16 That power off issue doesn't exist when using P109, ThermoOLED, that seems to do what you want, and you can still control from MQTT states via rules...
As does the Level Control Plugin as far a i can remember. Why would igorka need P109?

User avatar
chromo23
Normal user
Posts: 821
Joined: 10 Sep 2020, 16:02
Location: germany

Re: Rules in ESPeasy

#23 Post by chromo23 » 08 Dec 2022, 09:50

You can try this:
***removed***
Last edited by chromo23 on 08 Dec 2022, 10:11, edited 2 times in total.

User avatar
Ath
Normal user
Posts: 3417
Joined: 10 Jun 2018, 12:06
Location: NL

Re: Rules in ESPeasy

#24 Post by Ath » 08 Dec 2022, 10:05

chromo23 wrote: 08 Dec 2022, 09:42
Ath wrote: 07 Dec 2022, 19:16 That power off issue doesn't exist when using P109, ThermoOLED, that seems to do what you want, and you can still control from MQTT states via rules...
As does the Level Control Plugin as far a i can remember. Why would igorka need P109?
The difference is that the Level plugin can only save immediately, with a fixed delay, or not at all and you have to schedule your own (delayed) save action.

But P109 also doesn't support inverted Relay pin behavior, but that would be a nice addition. I'll work on that soon.

IMHO P109 should run fine without a display connected.
/Ton (PayPal.me)

User avatar
chromo23
Normal user
Posts: 821
Joined: 10 Sep 2020, 16:02
Location: germany

Re: Rules in ESPeasy

#25 Post by chromo23 » 08 Dec 2022, 10:10

Ath wrote: 08 Dec 2022, 10:05 The difference is that the Level plugin can only save immediately, with a fixed delay, or not at all and you have to schedule your own (delayed) save action.
Ahh true.. i forgot..
@igorka i´ll send you an updated binary with P109

User avatar
chromo23
Normal user
Posts: 821
Joined: 10 Sep 2020, 16:02
Location: germany

Re: Rules in ESPeasy

#26 Post by chromo23 » 08 Dec 2022, 10:14

ESP_Easy_mega_20221208_custom_ESP8266_1M.bin.zip
(467.03 KiB) Downloaded 120 times
Last edited by chromo23 on 08 Dec 2022, 11:06, edited 2 times in total.

igorka
Normal user
Posts: 74
Joined: 17 Jul 2022, 13:41
Location: Ukraine

Re: Rules in ESPeasy

#27 Post by igorka » 08 Dec 2022, 10:15

There is a problem with setting the value using the configuration command. The picture shows the settings of my plugin:
1.png
1.png (31.65 KiB) Viewed 9424 times
I enter the command config,task,thermostat,28.00,temperature:
2.png
2.png (7.96 KiB) Viewed 9424 times
The value does not change. As it was 24, so it became, the temperature is also maintained at 24 degrees. Also in my "old" build there is no possibility of choosing the time of auto-save.

User avatar
chromo23
Normal user
Posts: 821
Joined: 10 Sep 2020, 16:02
Location: germany

Re: Rules in ESPeasy

#28 Post by chromo23 » 08 Dec 2022, 10:29

igorka wrote: 08 Dec 2022, 10:15 I enter the command config,task,thermostat,28.00,temperature:
The correct command would be:

Code: Select all

config,task,thermostat,SetLevel,28
but Ath was right with his suggestion. P109 is the better option because it automatically delays the saving of the value... (with Level Control you have to make an Rule for that)
So look at my post before and download the new binary with P109

igorka
Normal user
Posts: 74
Joined: 17 Jul 2022, 13:41
Location: Ukraine

Re: Rules in ESPeasy

#29 Post by igorka » 08 Dec 2022, 10:36

Thanks! I will definitely do it later.

User avatar
Ath
Normal user
Posts: 3417
Joined: 10 Jun 2018, 12:06
Location: NL

Re: Rules in ESPeasy

#30 Post by Ath » 08 Dec 2022, 22:37

I've created PR #4409 to introduce in P109 the Inverted relay-state option, so 0=on and 1=off.

@chromo23 can you rebuild the 1M Custom build including P109 from this PR?
/Ton (PayPal.me)


igorka
Normal user
Posts: 74
Joined: 17 Jul 2022, 13:41
Location: Ukraine

Re: Rules in ESPeasy

#32 Post by igorka » 11 Dec 2022, 18:36

In this particular case, the solution with this plugin is completely suitable for me. But let me express my opinion or even wishes. It would be very convenient to be able to (command) save user variables "Let" in flash. After all, there is certainly a need to work - to operate not only with temperature, but with arbitrary values. I am sure that if it is possible, the functionality of the rules will be greatly expanded. :roll:

dr.zorg82
Normal user
Posts: 81
Joined: 02 Feb 2023, 07:32
Location: russia

Re: Rules in ESPeasy

#33 Post by dr.zorg82 » 02 Feb 2023, 07:48

gd. firmware ESP_Easy_mega_20221224_energy_ESP32_4M316k Dec 24 2022, modul esp32 wroom 32d. here is part of the code:

Code: Select all

On Clock#Time=All,17:37 do // каждый день вкл. химия
If [boiler#boiler]=0 and [pump#pump]=1
gpio,27,1
delay,2500
Pulse,32,1,500
delay,2500
Pulse,13,1,500
Else
gpio,27,0
Endif
endon
at 17:37, with a time delay, the 32nd pin is pressed, then the 13th, and only then the 27th turns on. please tell me how to make it so that 27 is turned on first, and then everything else?
what if you swap 32 and 13, then the turn-on queue also changes, but from 27 it doesn’t work like that

User avatar
Ath
Normal user
Posts: 3417
Joined: 10 Jun 2018, 12:06
Location: NL

Re: Rules in ESPeasy

#34 Post by Ath » 02 Feb 2023, 08:29

Just to make 1 important thing very clear:

DO NOT USE DELAY IN RULES

That is the cause of the erratic behavior, as delay is BLOCKING the entire ESP for that amount of time.

You can use timers (there are 128 available) to have planned delays in execution.

Your intended code would translate to this:

Code: Select all

On Clock#Time=All,17:37 do // every day on chemistry (Google translated...)
  If [boiler#boiler]=0 and [pump#pump]=1
    gpio,27,1
    TimerSet_ms,1,2500
  Else
    gpio,27,0
  Endif
Endon

On Rules#Timer=1 do // timer 1 action
  Pulse,32,1,500
  TimerSet_ms,2,2500
Endon

On Rules#Timer=2 do // timer 2 action
  Pulse,13,1,500
Endon
(Also added some indentation for readability)
/Ton (PayPal.me)

dr.zorg82
Normal user
Posts: 81
Joined: 02 Feb 2023, 07:32
Location: russia

Re: Rules in ESPeasy

#35 Post by dr.zorg82 » 02 Feb 2023, 09:27

Ath wrote: 02 Feb 2023, 08:29

That is the cause of the erratic behavior, as dela
thank you very much

dr.zorg82
Normal user
Posts: 81
Joined: 02 Feb 2023, 07:32
Location: russia

Re: Rules in ESPeasy

#36 Post by dr.zorg82 » 03 Feb 2023, 08:22

Is there an espeasy emulator for windows? it would be great not having a module, configure and test the rules. for example, I don’t have Wi-Fi at work and I don’t really want to carry a module with me to write rules. and so I would set everything up on the computer and then transfer it to the module

User avatar
Ath
Normal user
Posts: 3417
Joined: 10 Jun 2018, 12:06
Location: NL

Re: Rules in ESPeasy

#37 Post by Ath » 03 Feb 2023, 08:44

dr.zorg82 wrote: 03 Feb 2023, 08:22 Is there an espeasy emulator for windows?
Not as far as we know, but if you're into emulators, you're welcome to write one :lol:

There are (at least) 3 ways to check the syntax of rules:
- The EasyColorCode highlighter included in the Rules editor, (highlighting is available in most ESPEasy builds that have access to internet)
- The EasyColorCode highlighter test environment, provided by the author of the highlighter, over here
- The Notepad++ syntax highlighter plugin, available from here (Notepad++ is available for Windows only)
/Ton (PayPal.me)

dr.zorg82
Normal user
Posts: 81
Joined: 02 Feb 2023, 07:32
Location: russia

Re: Rules in ESPeasy

#38 Post by dr.zorg82 » 03 Feb 2023, 09:11

Ath wrote: 03 Feb 2023, 08:44 There are (at least) 3 ways to
it's not that. for example if i write this code

Code: Select all

On [boiler#boiler]=0 do // every day on chemistry (Google translated...)
  If %systm_hm_0% >22:00 And %systm_hm_0% < 02:00
    gpio,27,1
  Else
    gpio,27,0
  Endif
Endon
then nothing works. though the colors are beautiful :D
that is, I need to perform the following task: if in the time interval from 22:00 to 02:00 [boiler#boiler]=0, then pin 27 should be 1.
but so far there is not enough time to figure out what is wrong

User avatar
Ath
Normal user
Posts: 3417
Joined: 10 Jun 2018, 12:06
Location: NL

Re: Rules in ESPeasy

#39 Post by Ath » 03 Feb 2023, 09:35

dr.zorg82 wrote: 03 Feb 2023, 09:11 it's not that. for example if i write this code
Yes, I fully appreciate your original question ;)
but as we don't have anything that even looks like an emulator, the IMHO best suggestion is to use syntax highlighting/checks as a helper.
/Ton (PayPal.me)

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

Re: Rules in ESPeasy

#40 Post by TD-er » 03 Feb 2023, 10:12

And the fix to your rules problem is very simple:

Code: Select all

On [boiler#boiler]=0 do // every day on chemistry (Google translated...)
  If %systm_hm_0% <22:00 And %systm_hm_0% > 02:00
    gpio,27,0
  Else
    gpio,27,1
  Endif
Endon
There is never a time during the day being both before 2 in the morning and past 22h.

Just fipped the compares and the states of the GPIO commands.
The other option would be to change the "and" to an "or".
Boolean logic dictates:
!(A or B) == !A and !B

dr.zorg82
Normal user
Posts: 81
Joined: 02 Feb 2023, 07:32
Location: russia

Re: Rules in ESPeasy

#41 Post by dr.zorg82 » 03 Feb 2023, 11:24

TD-er wrote: 03 Feb 2023, 10:12 And the fix to your rules problem is very simple:
thanks for the help ;)

dr.zorg82
Normal user
Posts: 81
Joined: 02 Feb 2023, 07:32
Location: russia

Re: Rules in ESPeasy

#42 Post by dr.zorg82 » 04 Feb 2023, 17:09

it's me again :oops: ihave part of the code:

Code: Select all

On Clock#Time=All,18:00 do // каждый день вкл химия
  If [boiler#boiler]=0 and [pump#pump]=1
    gpio,27,1
    TimerSet_ms,1,2500
  Else
    gpio,27,0
  Endif
Endon

On Rules#Timer=1 do // timer 1 action
  Pulse,32,1,500
  TimerSet_ms,2,2500
Endon

On Rules#Timer=2 do // timer 2 action
  Pulse,13,1,500
Endon

On Clock#Time=All,19:30 do // каждый день выкл. химия
 gpio,27,0
endon

On [boiler#boiler] = 0 do // включает химию после выключения нагрева, если нагрев был , когда должна вкл химия
  If   %systm_hm_0% >=18:00 And %systm_hm_0% <=19:30 
  gpio,27,1
  TimerSet_ms,1,2500
  TimerSet_ms,3,5400000
  Endif
Endon

  On Rules#Timer=3 do
  gpio,27,0
Endon
according to the code, pin 27 turns on at 18:00 and turns off at 19:30. but heating can work at the same time ([boiler#boiler]=1). but I don't need pin 27 and [boiler#boiler] to work at the same time, so I write that if [boiler#boiler]=0 in the period from 18:00 to 19:30, then pin 27 should turn on at 5400000(one and a half hours). for example, the heating will turn off ([boiler#boiler]=0) at 19:25, then pin 27 will turn off at 19:30, and not after an hour and a half.how to prioritize timer execution (if timer is enabled)?
it is difficult to explain in a non-native language, but I hope you understand me :roll:

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

Re: Rules in ESPeasy

#43 Post by TD-er » 04 Feb 2023, 17:43

Without really thoroughly reading what you want to do, I already spotted a syntax error in your rules:

With on...do you don't use []

So

Code: Select all

On [boiler#boiler] = 0 do
Should be changed to:

Code: Select all

On boiler#boiler=0 do
And maybe even better:

Code: Select all

On boiler#boiler do
  if %eventvalue1%=0
    ...
  endif
endon

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

Re: Rules in ESPeasy

#44 Post by TD-er » 04 Feb 2023, 18:00

One other thing...
the "pulse" command is a blocking command.
Meaning the rules execution (and anything else) in ESPEasy is blocked as long as this command is being executed.
It would be better to use LongPulse_mS as this does return immediately after setting the initial pin state and schedules itself to switch the pin state again.
See: https://espeasy.readthedocs.io/en/lates ... ernal-gpio

The problem with "blocking commands" is that you may effectively miss some time critical events.


One more tip for debugging rules...
Try using the LogEntry command.
It may be very useful in seeing if some parts of your rules are actually being called and with which values.

Also the part between On ... Do in the rules act on events.
So if an event is never 'fired', those will never be called.

For example the "On boiler#boiler Do" suggests there is a task with taskname "boiler" and taskvalue name "boiler" which is called every now and then.
For example a switch task.
But if a task has a long interval (for example > 60 sec), then you may get conflicting situations as it may also take some time between sending the event and the event actually being handled.
What I mean is that you have a separate rules block for exactly 19:30 and also do the exact opposite action using the same time in another rules block.

So for example events matching the 2 examples below are being sent in this exact order, less than 1 minute apart:

Code: Select all

Clock#Time=All,19:30
boiler#boiler=0
The first will turn GPIO 27 to 0
The second one will turn GPIO 27 to 1.

The same applies to the 18:00 timestamp.

dr.zorg82
Normal user
Posts: 81
Joined: 02 Feb 2023, 07:32
Location: russia

Re: Rules in ESPeasy

#45 Post by dr.zorg82 » 04 Feb 2023, 18:16

thanks for the clarification. I'm trying to figure out the rest.

dr.zorg82
Normal user
Posts: 81
Joined: 02 Feb 2023, 07:32
Location: russia

Re: Rules in ESPeasy

#46 Post by dr.zorg82 » 04 Feb 2023, 19:55

I'm sorry, but I don't understand. I will try to explain again: the main setting is to turn on pin 27 at 18:00 and turn it off at 19:30. but the boiler can work during this period of time, so I need to shift the work of pin 27. but pin 27 should work for an hour and a half, despite the fact that the main setting disables pin 27.
is it possible to do this?

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

Re: Rules in ESPeasy

#47 Post by TD-er » 04 Feb 2023, 21:14

Maybe you can first tell which pin should perform what.

- GPIO 27 = 1 => boiler enabled?
- GPIO 32 pulse for 500 ms = what?
- GPIO 13 pulse for 500 ms = what?

What kind of task do you have which is called boiler#boiler? Is this an input switch? output switch? something else?

When we have this clear, please explain the 'normal' mode, like:

At 18:00:
- turn on whatever GPIO-27 controls
- Timer for 2500ms => pulse Gpio32
- Timer for 2500ms => pulse Gpio13

At 19:30:
- turn off whatever GPIO-27 controls

Now the not normal mode, something with a pump?
What kind of task is pump#pump?
Should the pump state only be checked at 18:00?

dr.zorg82
Normal user
Posts: 81
Joined: 02 Feb 2023, 07:32
Location: russia

Re: Rules in ESPeasy

#48 Post by dr.zorg82 » 05 Feb 2023, 06:26

Code: Select all

on Time#Initialized do
If %systm_hm_0% <=22:00 And %systm_hm_0% >= 02:00
  gpio,33,1
  gpio,12,1
else
  gpio,33,0
endif
endon

On Clock#Time=All,22:00 do // каждый день выкл. насос
If [boiler#boiler]=1
  gpio,33,1
else
  gpio,33,0
Endif
endon

On Clock#Time=All,02:00 do // каждый день вкл. нас
  gpio,33,1
endon

on temp#water<=25.00 do // темп. воды в бассдля вкл. обогрева
  GPIO,12,1
  gpio,33,1
Endon

on temp#water>=26.00 do // темп. воды в бассдля выкл. обогрева
  GPIO,12,0
Endon

on temp#air<=-0.5 do // темп. воздуха вкл. греющ. кабеля
  GPIO,25,1
Endon

on temp#air>=0.0 do // темп. воздуха выкл. греющ.кабеля
   GPIO,25,0
Endon

On Clock#Time=All,06:00 do // каждый день вкл химия
  If [boiler#boiler]=0 and [pump#pump]=1
    gpio,27,1
    TimerSet_ms,1,2500
  Else
    gpio,27,0
  Endif
Endon

On Rules#Timer=1 do // timer 1 action
  LongPulse_mS,32,1,500,500,0
  TimerSet_ms,2,2500
Endon

On Rules#Timer=2 do // timer 2 action
  LongPulse_mS,13,1,500,500,0
Endon

On Clock#Time=All,07:30 do // каждый день выкл. химия
gpio,27,0
endon

On Clock#Time=All,18:00 do // каждый день вкл химия
  If [boiler#boiler]=0 and [pump#pump]=1
    gpio,27,1
    TimerSet_ms,1,2500
  Else
    gpio,27,0
  Endif
Endon

On Rules#Timer=1 do // timer 1 action
  LongPulse_mS,32,1,500,500,0
  TimerSet_ms,2,2500
Endon

On Rules#Timer=2 do // timer 2 action
  LongPulse_mS,13,1,500,500,0
Endon

On Clock#Time=All,19:30 do // каждый день выкл. химия
  gpio,27,0
endon

On boiler#boiler do // включает химию после выключения нагрева, если нагрев был , когда должна вкл химия
if %eventvalue1%=0
  If   %systm_hm_0% >=06:00 And %systm_hm_0% <=07:30 or %systm_hm_0% >=18:00 And %systm_hm_0% <=19:30
  gpio,27,1
  TimerSet_ms,1,2500
  TimerSet_ms,3,5400000
  Endif
Endon

  On Rules#Timer=3 do
  gpio,27,0
Endon
gd. this is all the code currently available. I'm trying to automate the pool care process. the pool is provided with water filtration ([pump#pump]), a break in the operation of the pump from 22:00 to 02:00, water heating ([boiler#boiler]), which is switched on by water temperature and water disinfection (filter#filter) is switched on by time, twice a day for an hour and a half from 06:00 to 07:30 and from 18:00 to 19:30. pin 27 turns on disinfection, but for it to work, you need to press two more buttons; this is what pins 32 and 13 do. simultaneous operation of the boiler and disinfection is undesirable.but it may happen that at the moment when the disinfection is supposed to start, the boiler will still be working, so the activation of the disinfection should be postponed until the boiler turns off.
temp#air this is a parallel task and does not apply to the pool. with this code, everything works as intended (at least on the layout), only disinfection is disabled by this command

Code: Select all

On Clock#Time=All,19:30 do // каждый день выкл. химия
  gpio,27,0
endon
2023-02-05_08h07_29.png
2023-02-05_08h07_29.png (52.69 KiB) Viewed 8210 times

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

Re: Rules in ESPeasy

#49 Post by TD-er » 05 Feb 2023, 12:37

Ok a few more questions then.
Which are actually "inputs" and which are "outputs"?
For example when switching an output pin, then there will not be an event, but if you have some inputs then it may trigger an event when you configured it as a switch task.

Another approach can be to enable "monitor" on a specific pin, so you will always get an event when the state changes.

Just one more thing that's probably causing issues here as it requires some ()

Code: Select all

  If  (%systm_hm_0% >=06:00 And %systm_hm_0% <=07:30) or (%systm_hm_0% >=18:00 And %systm_hm_0% <=19:30)
But this can be done with more clean code, which I will show you later.

First I need to know which GPIO pins will be input and need to be acted on.

dr.zorg82
Normal user
Posts: 81
Joined: 02 Feb 2023, 07:32
Location: russia

Re: Rules in ESPeasy

#50 Post by dr.zorg82 » 05 Feb 2023, 16:08

unfortunately I didn't understand the question:cry: . pin 26 is an input (temperature sensor), pin 12.13.27.32.33 is an output, they control devices. at the moment there are no more pins involved. use esp32 wroom32d.

Post Reply

Who is online

Users browsing this forum: No registered users and 16 guests