Level control or rules ?

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
margan
Normal user
Posts: 10
Joined: 15 May 2019, 11:23
Location: Italy

Level control or rules ?

#1 Post by margan » 15 May 2019, 12:53

I admit that initially thought was easyer to do a very little project I had in mind, but it was more complicated than expected in practice.
It seems that sometime Esp Easy makes what is difficult easy and makes what seems easy difficult.
I need to toggle two relays, the first when a sensor connected to the board read a 0 value and the second one when the same sensor read 1 value.
No controller needed in this project ( domoticz or others), only a local board control ( nodemcu V3 in this case).
I read examples and tutorials about "control level" but on lets control it wiki support is not clear what kind of firmware is charged in the example. Mine is the last firmware released ( Mega, may 2019) and there are'nt the same options seen on the wiki ( ds18b20 that read a temperature if I right remember). In my case the sensor is a photoresistor mounted on a LM393 board that shows on the devices page of Esp Easy a value of 0 or 1 if exposed or not to the light.
But I cannot translate this value to an action that toggle each of the two relays.

Thanks in advance for any suggestion.

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

Re: Level control or rules ?

#2 Post by grovkillen » 15 May 2019, 13:20

Have you a rule that we can look at? I'm always here to help but find it easier if you already have something to look at instead trying to guess your setup.
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:

margan
Normal user
Posts: 10
Joined: 15 May 2019, 11:23
Location: Italy

Re: Level control or rules ?

#3 Post by margan » 15 May 2019, 13:39

Thanks for your fast feedback at first.
No I don't have any rule wrote !
Your answer already sounds like a first suggestions: I need a rule!
Until now I was uncertain about this. So it's not enough to use level control plugin alone for this project?
I'll read with more attention wiki and so on, because probably don't payed enough attention on level control settings, if there where rules suggested or not.
On the other hand this statement suggested me an easy way to do what I need:
You have to enter some IDX, even if this is not used. In this sample, we have connected a DS18B20 sensor and the heater is controlled using GPIO 12. We have set the required temperature to 21 degree with a hysteresis of 1 degree.

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

Re: Level control or rules ?

#4 Post by grovkillen » 15 May 2019, 13:46

The wiki is outdated in many parts, we are moving to "read the docs". And yes rules are the way to do it.
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:

margan
Normal user
Posts: 10
Joined: 15 May 2019, 11:23
Location: Italy

Re: Level control or rules ?

#5 Post by margan » 15 May 2019, 18:19

Ok,

My photoresistor read on the GPIO 16
Flagged internal pull up on the devices section and selected GPIO 16 with switch type.

So I wrote this rule:

Code: Select all

On Rinnaimonitor#Rinnaimonitor=1 do 
gpio,12,1
timerset,1,30
Endon

On Rinnaimonitor#Rinnaimonitor=0 do 
gpio,14,1
timerset,1,30
Endon
Where on GPIO 12 and 14 I'll connect the two relays. I'd like that each relay should be on for 30 seconds.
How far I am from a correct rule ?

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

Re: Level control or rules ?

#6 Post by grovkillen » 15 May 2019, 18:42

Good start, this is how I would do it. Please observer that is considered bad practice to have the same name for the task as well as its value. So I have used shorter and unique naming.

Code: Select all


On Rinnai#State do 
 If [Rinnai#State]=1
   gpio,12,1
   timerset,1,30
  Else
   gpio,14,1
   timerset,1,30
  Endif
Endon

On Rules#Timer=1 do 
gpio,14,0
gpio,12,0
Endon
But I'm not sure this is how you would want it?
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:

margan
Normal user
Posts: 10
Joined: 15 May 2019, 11:23
Location: Italy

Re: Level control or rules ?

#7 Post by margan » 15 May 2019, 18:53

Oh, not so far then......
Sure, I had already made some correction before your answer, i.e. state instead of Rinnaimonitor,
but now with your help I have some concrete roots for a bench test and then transfer it in the "real life".
Thanks a lot !

edit:

but the code probably should be this:

Code: Select all

On Rinnai#State do 
 If [Rinnai#State]=1
   gpio,12,1
   timerset,1,30
  If [Rinnai#State]=0
   gpio,14,1
   timerset,1,30
  Endif
Endon

On Rules#Timer=1 do 
gpio,14,0
gpio,12,0
Endon

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

Re: Level control or rules ?

#8 Post by Domosapiens » 15 May 2019, 20:47

Endif missing
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.

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

Re: Level control or rules ?

#9 Post by grovkillen » 15 May 2019, 21:34

In your case you only have two states (1/0 or a Boolean gate) so even if you can do multiple if it's not necessary. I mean, if it's not one then it must be zero right?
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:

margan
Normal user
Posts: 10
Joined: 15 May 2019, 11:23
Location: Italy

Re: Level control or rules ?

#10 Post by margan » 16 May 2019, 08:11

@ grovkillen
Ah,
so isn't necessary to repeat the same instruction for the second relay when the state is different from 1 ?
Is this the sense of "else" ?

@ Domosapiens: where is endif missing ?

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

Re: Level control or rules ?

#11 Post by grovkillen » 16 May 2019, 08:44

The "EndIf" was missing after your first if chunk. But given that you use "else" instead you don't have have add that EndIf between.
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
dynamicdave
Normal user
Posts: 168
Joined: 30 Jan 2017, 20:25
Location: Hampshire, UK

Re: Level control or rules ?

#12 Post by dynamicdave » 16 May 2019, 13:11

You could probably re-write it as..

Code: Select all

On Rinnai#State do 
 If [Rinnai#State]=0
   gpio,14,1
 else
   gpio,12,1
 Endif
 timerset,1,30
Endon

On Rules#Timer=1 do 
gpio,14,0
gpio,12,0
Endon
Last edited by dynamicdave on 18 May 2019, 07:23, edited 1 time in total.

margan
Normal user
Posts: 10
Joined: 15 May 2019, 11:23
Location: Italy

Re: Level control or rules ?

#13 Post by margan » 16 May 2019, 21:13

Ah, OK, thanks to everyone.

margan
Normal user
Posts: 10
Joined: 15 May 2019, 11:23
Location: Italy

Re: Level control or rules ?

#14 Post by margan » 19 May 2019, 07:40

Sorry, does not work with any rules.
Not found any way to toggle the relay, one or other.

I resume here:
The lux sensor who makes as switch ( state 1 or 0) is connected to GPIO 16 ( setting or not in <<pull up>> mode).
The Input switch is setted in <<normal switch>> mode ( does not work in any mode)
The two relays are connected to the GPIO 14 and 12 ( all the GPIO are in default mode).
The relays are connected to the vin (5v) and ground of the nodemcu that's powered by USB port.
The IN of the relays are connected to 14 and 12 GPIO.

The sensor changes the state when exposed to enough light and espeasy actually shows the state from 1 to 0 ( only refreshing page in this esp easy version 2.0.0-dev12).
No one of the relay is switched on in any case.

margan
Normal user
Posts: 10
Joined: 15 May 2019, 11:23
Location: Italy

Re: Level control or rules ?

#15 Post by margan » 19 May 2019, 10:23

Found the answer by myself. Could be an help for guys interested in.

On devices page of your v2.0.0-dev12 esp easy , you CANNOT change the name of value as you want (i.e. State or Fantasy) ! You must leave the name SWITCH !
So, if you do it, leaving the name of value as is by default (Switch) your gadget will works, but the rule mast be as follow:

Code: Select all

On Rinnai#Switch do 
 If [Rinnai#Switch]=1
   gpio,12,1
   gpio,14,0
  Else
   gpio,14,1
   gpio,12,0
  Endif
Endon
So when your sensor change fro 0 to 1 or viceversa, your relays board switches one of the relays.

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

Re: Level control or rules ?

#16 Post by grovkillen » 19 May 2019, 12:36

I wasn't aware that you're using dev12. Sorry
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:

margan
Normal user
Posts: 10
Joined: 15 May 2019, 11:23
Location: Italy

Re: Level control or rules ?

#17 Post by margan » 20 May 2019, 13:53

My fault if missing on first post wich v was flashed on the board. A lot of attempts to install a fresh updated bin was made with an old flasher exited with a wifi failure or a bootloop of the board, since the new flasher included in the new release does'nt work in my PC. I'll try to work with another one with win7.
But absolutely tanks anyway.

Post Reply

Who is online

Users browsing this forum: No registered users and 10 guests