GPIO pin status at rules engine

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
hiihoo
New user
Posts: 4
Joined: 09 Sep 2017, 20:13

GPIO pin status at rules engine

#1 Post by hiihoo » 09 Sep 2017, 20:52

Hello all.

Very first post.. :-) Exciting..

https://www.letscontrolit.com/wiki/inde ... _Reference

Says:
Command Class Purpose Syntax
Status Plugin Show status on previously controlled pins Status <device>,<pin>
and stated:
Plugins - Can be run from serial, rules engine, HTTP, MQTT
Very well. But how?-) Meaning using it at rules engine.

Many examples deploy "extra" switch for getting gpio state, but if I'm not misunderstood, it should work directly also?

via http://192.168.1.xx/control?cmd=status,gpio,12 i can get gpio status directly without extra switches.

I have sonoff basic, and want its relay to be ON at boot, so gpio 12 is default ACTIVE.
But if i have input switch task connected to gpio 12 to read relay state, it apparently puts relay off after couple of seconds after boot.
After that it works like it should, but initially it just ruins idea about light been "manually" operated..
One could write some system#boot gpio,12,1 rule, but even then relay goes off for moment and on again, not "professional"..

So.. It this a bug or a fly, or just a way it should work?

Firmware is espEasy.2.0.0-dev11_normal_8285.bin.

User avatar
toffel969
Normal user
Posts: 469
Joined: 03 Jan 2017, 10:58
Location: Germany

Re: GPIO pin status at rules engine

#2 Post by toffel969 » 10 Sep 2017, 20:54

You can probably get the gpio state(use in if condition) , but this way you are not able to start an event, trigger something, you can just check from existing event

If you want more professional advice on Rules +gpio + boot state post your rules, devices and config tab.
Domoticz on Raspi 2 -- 14 ESP units (hacked Sonoff,NodeMCUs, Wemos, self-built units) running with RC140- Mega 2.0.0 dev8

hiihoo
New user
Posts: 4
Joined: 09 Sep 2017, 20:13

Re: GPIO pin status at rules engine

#3 Post by hiihoo » 11 Sep 2017, 14:17

Thanks for reply, just happened to read my original post also.. :-)

Sorry, I was not making my question clear.

I was looking for syntax / format, to use with "status,gpio,12" in rules engine.

Like:

Code: Select all

On Button#Switch do

   If [status,gpio,12]=1
     gpio,12,0
     gpio,13,1
   else 
     gpio,12,1
     gpio,13,0
   endif
endon
Won't work. :-)

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

Re: GPIO pin status at rules engine

#4 Post by grovkillen » 11 Sep 2017, 15:30

This is the correct syntax for that. Since you already have a switch device you use that variable an not the state of the gpio.

Code: Select all

On Button#Switch do
   If [Button#Switch]=1
     gpio,12,0
     gpio,13,1
   else 
     gpio,12,1
     gpio,13,0
   endif
endon
Or as this:

Code: Select all

On Button#Switch=1 do
     gpio,12,0
     gpio,13,1
endon

On Button#Switch=0 do
     gpio,12,1
     gpio,13,0
endon
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:

hiihoo
New user
Posts: 4
Joined: 09 Sep 2017, 20:13

Re: GPIO pin status at rules engine

#5 Post by hiihoo » 11 Sep 2017, 20:17

Yes, it can be done that way, and there are million zillion ways.

My point, to be exact, is that how / or anyway, is it possible to us "status,gpio,12" in rules engine. :-)

Documentation implies that it could be possible, looking for syntax for that.

Thanks for example, appreciate help, but someday, when you least except it, it might be usefull to get gpio status straight away... :-)

User avatar
toffel969
Normal user
Posts: 469
Joined: 03 Jan 2017, 10:58
Location: Germany

Re: GPIO pin status at rules engine

#6 Post by toffel969 » 11 Sep 2017, 23:02

I get your point, though can't help you with that
Domoticz on Raspi 2 -- 14 ESP units (hacked Sonoff,NodeMCUs, Wemos, self-built units) running with RC140- Mega 2.0.0 dev8

ut1545
Normal user
Posts: 32
Joined: 22 Mar 2016, 20:56

Re: GPIO pin status at rules engine

#7 Post by ut1545 » 21 Sep 2017, 21:05

Hello,

I'd like to do the same as hiihoo. My ESP Easy node is controlling 16 relays so, it is not desirable to have to define 16 switches devices only to know gpio state in a rule.

Those relays are activated/deactivated by an openHab controller and in specific situations, I need to know gpio states.

Any idea?

Thanks in advance for any help.

User avatar
toffel969
Normal user
Posts: 469
Joined: 03 Jan 2017, 10:58
Location: Germany

Re: GPIO pin status at rules engine

#8 Post by toffel969 » 21 Sep 2017, 21:41

ut1545 wrote: 21 Sep 2017, 21:05 Hello,

I'd like to do the same as hiihoo. My ESP Easy node is controlling 16 relays so, it is not desirable to have to define 16 switches devices only to know gpio state in a rule.

Those relays are activated/deactivated by an openHab controller and in specific situations, I need to know gpio states.

Any idea?

Thanks in advance for any help.
You could use 4 dummy devices with 4var each, that's what I did on my 8 relay (i2c expander) multisensor node. Still not exactly what you ask for, but 12 less devices for 16 relay states. Just set the dummies whenever you set the gpios
Domoticz on Raspi 2 -- 14 ESP units (hacked Sonoff,NodeMCUs, Wemos, self-built units) running with RC140- Mega 2.0.0 dev8

ut1545
Normal user
Posts: 32
Joined: 22 Mar 2016, 20:56

Re: GPIO pin status at rules engine

#9 Post by ut1545 » 25 Sep 2017, 13:48

Hi,

Thank you for your response. Your suggestion, setting dummy variables, is a good solution. BTW, I'm looking for a new approach. I will explain the idea if it can be useful for other people.

I'm controlling a irrigation system through openHab controller so, when it is time to start a irrigation zone, it sends a MQTT message to ESP Easy node in order to turn on a gpio and sends another message when irrigation timer has finished to turn off the gpio. The problem occurs when openHab, for any reason, doesn't send the turn off message or when it doesn't arrive into EspEasy so, the irrigation zone will be turned on for all eternity.....

There are several approaches to solve this but, my favorite is the following: Using a dummy device and some ESPEasyrules, the openHab server sends a timer value and the gpio number to ESPEasy in order to start a irrigation zone for a time. Once the timer value expires, ESPEasy turns the gpio off. In this way, if the controller fails after the zone has started, the ESPEasy will turn it off anyway.

Thanks,

maluko
Normal user
Posts: 112
Joined: 02 Sep 2015, 00:49

Re: GPIO pin status at rules engine

#10 Post by maluko » 25 Sep 2017, 16:03

i have a irrigation system too with espeasy and domoticz to controll 8 relay, you for 16 can use the rules to controll it like this

Code: Select all

on relay1 do 
 gpio,1,1
 timerset 1,1800  //max timer to esp turn gpio off
endoff
on Rules#Timer=1 do
 gpio,1,0
 SendToHTTP domoticzip,8080,/json.htm?type=param=switchlight&command&idx=101&switchcmd=Off
endoff

on relay2 do
 gpio,2,1
 timerset 2,1800  //max timer to esp turn gpio off
endoff
on Rules#Timer=2 do
 gpio,2,0
 SendToHTTP domoticzip,8080,/json.htm?type=param=switchlight&command&idx=102&switchcmd=Off
endoff

etc....
to begin the relay1 you have to put this on your controller

http://<espeasyip>/control?cmd=event,relay1

Post Reply

Who is online

Users browsing this forum: No registered users and 13 guests