Page 1 of 1

[noob question] esp8266 rules + analog read mq-2 senor

Posted: 27 Dec 2018, 21:46
by pdrobek
Hi folks

Near 4 days ago i switched to espeasy from my own firmware for wemos d1 mini pro(esp8266).I read whole wiki page for rules which could be set on espeasy and still something work wrong in my opinion.

Please see where i am doing wrong things

I create device Analog input internal named it mq2 with values named value. In short mq2#value

I also create rule(s) to switch on/off relay connected to GPIO5

Code: Select all

on [mq2]#value>75 do
gpio,5,1
endon
on [mq2]#value<=75 do
gpio,5,0
endon
In log i see

Code: Select all

1125701: ADC : Analog value: 63
1125704: EVENT: mq2#value=63.00
1125721: Domoticz: Sensortype: 1 idx: 64 values: 63
....
As far i observe my relay it wont switch on even if mq2#value is greater than 100

Please tell how to create rule to frequently check for analog value and power on/off relay

Re: [noob question] esp8266 rules + analog read mq-2 senor

Posted: 27 Dec 2018, 22:11
by dynamicdave
You could try this piece of code.
It checks the value of mq2 every 2 seconds (adjust the timing to suit your needs).

Code: Select all

On System#Boot do
  GPIO,5,0
  timerSet,1,2  //Set timer1 for 2 seconds (adjust the timing to suit your needs)
endon

on Rules#Timer=1 do    //This is executed when timer1 runs out
  if [mq2#value]>75
    GPIO,5,1
  else
    GPIO,5,0
  endif
  timerSet,1,2  // set timer1 for another 2 seconds
endon

[Solved][noob question] esp8266 rules + analog read mq-2 senor

Posted: 27 Dec 2018, 22:26
by pdrobek
It works!

So i have to read another wiki for timers :-)

Re: [noob question] esp8266 rules + analog read mq-2 senor

Posted: 28 Dec 2018, 10:25
by dynamicdave
Glad to help.

Cheers from david