Page 1 of 1

Problem with a rule for MQ-7 Gas sensor

Posted: 31 Mar 2020, 09:11
by tparvais
[I moved my question from viewtopic.php?f=4&t=7328 here, as problem is not directly related to MQ-7]

Hello

I implemented same MQ-7 for CO detection.

I've set a rule for managing heating/measurements/calibration

The idea is to be able to launch the calibration during 48 when pressing the button GPIO4 or to stop it by pressing again.
I use a dummy variable "Calibration_MQ7" that is 1 if calibration is on, and 0 if off...

By pressing the push switch, I shgall inverese the state of this variable

I shall be stupid because it does not work... :-(

( the others timers for heating/measuring are ok)

any idea ?


Thank you

Thomas

Code: Select all

on System#Boot do
  timerSet,1,5
  taskvalueset 8,1,0 // état calibration à 0
endon

on [MQ7_Calibration_Start-Stop#etat]=1 do //switch pressed
  if [Calibration_MQ7#etat]=1
    TaskValueSet 8,1,0 // inverse state + stop calibration
    gpio,13,0
    timerSet,4,0
  else
    TaskValueSet 8,1,1 // inverse state + start calibration
    gpio,13,1 //power on heating
    timerSet,2,0
    timerSet,3,0
    timerSet,4,172800  // Calibrate 48h
    gpio,13,0 //stop heating
  endif
endon

on Rules#Timer=1 do 
 gpio,13,1
 timerSet,2,60
endon

on Rules#Timer=2 do 
 gpio,13,0 
 timerSet,3,45  
endon

on Rules#Timer=3 do 
 TaskValueSet 7,1, [Mesure_MQ7_CO#Analog] 
 timerSet,1,45 
endon
Here are my tasks :

Image

and how I configure the switch to launch calibration (this is a push button, normally closed, between GND & GPIO4):

Image

Re: Problem with a rule for MQ-7 Gas sensor

Posted: 01 Apr 2020, 14:43
by GravityRZ
is the problem not that you do a check on an ON statement

i am not an experienced ESPEasy rules guru bu can you try

Code: Select all

on MQ7_Calibration_Start-Stop#etat do //switch pressed
TaskValueSet 8,1,[MQ7_Calibration_Start-Stop#etat] set switch pressed setting to Calibration_MQ7#etat
  if [Calibration_MQ7#etat]=1

Re: Problem with a rule for MQ-7 Gas sensor

Posted: 02 Apr 2020, 20:13
by tparvais
Hi

It does not work.

I simplified it as with the follwoing code, when pressing the button, Q7_Calibration_Start-Stop#etat is inverted properly each time

My problem is that it does not execute the IF test if [MQ7_Calibration_Start-Stop#etat]=0

Code: Select all

on System#Boot do
  timerSet,1,5 // wait 5s then start
  taskvalueset 9,1,0 // état calibration à 0
endon

on [MQ7_Calibration_Start-Stop#etat] do //switch pressed
  if [MQ7_Calibration_Start-Stop#etat]=0
      gpio,13,0 // stop calibration
      timerSet,1,1 // wait 1s then restart normal cycle
  else
    gpio,13,1 //power on heating to calibrate
    timerSet,3,0 // stop timer 3
    timerSet,1,0 // stoptimer 1
    timerSet,2,20  // Calibrate 20s
  endif
endon

on Rules#Timer=1 do 
 gpio,13,1 //heat before measure
 timerSet,2,5
endon

on Rules#Timer=2 do 
 gpio,13,0 // stop heating before measure
 timerSet,3,5  
endon

on Rules#Timer=3 do 
 TaskValueSet 7,1, [Mesure_MQ7_CO#Analog] 
 timerSet,1,1 //go back to begining
endon

Re: Problem with a rule for MQ-7 Gas sensor

Posted: 02 Apr 2020, 20:24
by Domosapiens
[MQ7_Calibration_Start-Stop#etat]=0
the name contains the "-" minus sign.
I can imagine that ...

Try using the "_" underscore instead, in Task and in the rule ??

Re: Problem with a rule for MQ-7 Gas sensor

Posted: 02 Apr 2020, 22:14
by tparvais
Hi

good idea, I changed - by _
no effect

when I press the push-switch, the state ofMQ7_Calibration_Start_Stop changes properly in task/device view.

Is there a way to debug ?

I add a tasksetvalue in #8 to a dummy variable as output to check if the IF condition is executed (or ELSE). nada.

I shorten the variable length. nada

Code: Select all

on System#Boot do
  timerSet,1,5 // wait 5s then start
  taskvalueset 9,1,0 // état calibration à 0
taskvalueset 8,1,0 //for debugging
endon

on [MQ7#etat]=0 do //switch pressed
      gpio,13,0 // stop calibration
      taskvalueset 8,1,0
      timerSet,1,1 // wait 1s then restart normal cycle
endon

on [MQ7#etat]=1 do //switch pressed
    taskvalueset 8,1,99
    gpio,13,1 //power on heating to calibrate
    timerSet,3,0 // stop timer 3
    timerSet,1,0 // stoptimer 1
    timerSet,2,60  // Calibrate 48h
endon

on Rules#Timer=1 do 
 gpio,13,1 //heat before measure
taskvalueset 8,1,1
 timerSet,2,5
endon

on Rules#Timer=2 do 
 gpio,13,0 // stop heating before measure
taskvalueset 8,1,2
 timerSet,3,5  
endon

on Rules#Timer=3 do 
 TaskValueSet 7,1, [Mesure_MQ7_CO#Analog] 
taskvalueset 8,1,3
 timerSet,1,5 //go back to begining
endon


Re: Problem with a rule for MQ-7 Gas sensor

Posted: 02 Apr 2020, 22:36
by tparvais
I found it myself:
there is no need to use [] in on .... do statement...

Re: Problem with a rule for MQ-7 Gas sensor

Posted: 03 Apr 2020, 05:42
by grovkillen
tparvais wrote: 02 Apr 2020, 22:36 I found it myself:
there is no need to use [] in on .... do statement...
The brackets turn the name into a value.

Re: Problem with a rule for MQ-7 Gas sensor

Posted: 03 Apr 2020, 11:17
by tparvais
grovkillen wrote: 03 Apr 2020, 05:42 The brackets turn the name into a value.
Worthwhile to add it to the doc :)

btw, is that possible to put a text in a dummy variable/task ? or is this only numbers ?

Thank you

Re: Problem with a rule for MQ-7 Gas sensor

Posted: 03 Apr 2020, 11:37
by TD-er
Right now we don't have the option to use strings as values.
The support for strings is very preliminary and it is not yet possible to store them in variables or in Dummy plugin.

Re: Problem with a rule for MQ-7 Gas sensor

Posted: 03 Apr 2020, 12:19
by grovkillen
tparvais wrote: 03 Apr 2020, 11:17
grovkillen wrote: 03 Apr 2020, 05:42 The brackets turn the name into a value.
Worthwhile to add it to the doc :)
Isn't it already part of the rules examples?

Re: Problem with a rule for MQ-7 Gas sensor

Posted: 03 Apr 2020, 13:29
by GravityRZ
tparvais wrote: 02 Apr 2020, 22:36 I found it myself:
there is no need to use [] in on .... do statement...
or you could have read my advice in which i told you to remove the []

Re: Problem with a rule for MQ-7 Gas sensor

Posted: 03 Apr 2020, 13:59
by tparvais
GravityRZ wrote: 03 Apr 2020, 13:29
tparvais wrote: 02 Apr 2020, 22:36 I found it myself:
there is no need to use [] in on .... do statement...
or you could have read my advice in which i told you to remove the []
you're right, I read your message 5 times, but I didn't noticed the [] removal

Need to change my glasses

so thank you !

Re: Problem with a rule for MQ-7 Gas sensor

Posted: 03 Apr 2020, 14:07
by GravityRZ
no problem.
next time i will mention what i changed :-)