Monitoring GPIO and PCFGPIO outputs

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
dduley
Normal user
Posts: 93
Joined: 06 Feb 2016, 17:56

Monitoring GPIO and PCFGPIO outputs

#1 Post by dduley » 25 Apr 2016, 22:10

HI All,

I have been wanting to use GPIO output state for triggering rules and to just be able to tell whether an output is on or off. I found that if I make a task with a SWITCH input for the GPIO in question I can use it as an output and still monitor the pin state as an input. This could be useful as a condition within a rule.
When setting up the SWITCH input make sure to check the boxes labeled "Send Boot State" and "Send Data". IF you forget the send boot state box then the switch will not report correctly until the output has changed state.

I thought this might be useful to some.

Regards

Dave

andy
Normal user
Posts: 65
Joined: 26 Jan 2016, 23:07

Re: Monitoring GPIO and PCFGPIO outputs

#2 Post by andy » 27 Apr 2016, 01:52

That's really cool! Now I can test if the pump is on to know it's safe to inject chlorine into the pool plumbing.

tozett
Normal user
Posts: 734
Joined: 22 Dec 2015, 15:46
Location: Germany

Re: Monitoring GPIO and PCFGPIO outputs

#3 Post by tozett » 27 Apr 2016, 07:48

@ dduley,
very interesting. i would be very kind, if you could provide your succesful working rule and your switch-setting (screenshot),
to prevent typo-errors and misinterpretation. that could be a frustrating thing, in re-building your interesting working modell.

JR01
Normal user
Posts: 260
Joined: 14 Feb 2016, 21:04
Location: South Africa

Re: Monitoring GPIO and PCFGPIO outputs

#4 Post by JR01 » 28 Apr 2016, 21:19

tozett wrote:@ dduley,
very interesting. i would be very kind, if you could provide your succesful working rule and your switch-setting (screenshot),
to prevent typo-errors and misinterpretation. .
Well done @ dduley, +1 on on this request ?
-----------
IOTPLAY. Tinkerer, my projects are @ http://GitHub.com/IoTPlay, and blog https://iotplay.org. Using RPi, Node-Red, ESP8266 to prove Industry 4.0 concepts.

dduley
Normal user
Posts: 93
Joined: 06 Feb 2016, 17:56

Re: Monitoring GPIO and PCFGPIO outputs

#5 Post by dduley » 04 May 2016, 08:01

All,

Here is an example of how I am using this. I have one ESP module in a junction box near my front gate. OpenHab can issue a command to turn on a mechanical relay which opens the gate. OpenHab has a rule set up so that when the relay is activated a 2 second timer is run and then the relay is turned back off. Normally the ESP would not generate an event that I could trigger on because outputs are an inherent function that does not require a task to be set up. I have another ESP module that controls the driveway spot lights. I wanted the lights on that module to come on for 15 minutes when the gate is open. Using a SWITCH task to monitor the output state of the relay control bit I can generate a global event that the light module can react to.
On the Front Gate module:
task# 9: Switch input - PCF8574 Name: gaterelay PCFGPIO 1 Value Name: Switch
Set IDX to any nonzero value I arbitrarily used 170
Send Boot state: Checked
Send Data: Checked
Global Sync: Checked

Note that there is a bug in ESPEasy that prevented me from using any other Value Name besides "Switch" (The default). I initially tried to make the value name "state" but when the event was sent it was sent as gaterelay#Switch instead. Once I realized this and changed it back to the default value of "Switch" and it started working.

On the Driveway Light module under Rules:
on gaterelay#Switch=0 do
gpio,4,1 //turn lights on
timerSet,1,900 //Set Timer 1 for the next event in 15 minutes
endon

On Rules#Timer=1 do //When Timer1 expires, do
gpio,4,0 //turn lights off
endon

I hope this was clear

Regards

Dave

tozett
Normal user
Posts: 734
Joined: 22 Dec 2015, 15:46
Location: Germany

Re: Monitoring GPIO and PCFGPIO outputs

#6 Post by tozett » 04 May 2016, 15:21

thanks for explanation. ::thumb-up::

a side thing: do i understand it right?
you activated global sync on (one - or both esps?), and you can use this specific Rule-name "DEVICE-NAME#VALUE-NAME"
from one of the devices directly in the rules-section of the other module?
(as there is also mentioned in the wiki to use sentTO (ohter esp), to switch GPIOs)

it this is true, this is actually not documented on the wiki.
or am i wrong with this?

dduley
Normal user
Posts: 93
Joined: 06 Feb 2016, 17:56

Re: Monitoring GPIO and PCFGPIO outputs

#7 Post by dduley » 04 May 2016, 18:09

tozett wrote:thanks for explanation. ::thumb-up::

a side thing: do i understand it right?
you activated global sync on (one - or both esps?), and you can use this specific Rule-name "DEVICE-NAME#VALUE-NAME"
from one of the devices directly in the rules-section of the other module?
(as there is also mentioned in the wiki to use sentTO (ohter esp), to switch GPIOs)

it this is true, this is actually not documented on the wiki.
or am i wrong with this?
Hi Tozett,

Yes I have checked globalsync in the TOOLS\ADVANCED section on both modules. I also checked Send Data and Globalsync in the Switch task that I set up. This causes the event generated by the Switch task to be transmitted to all globalsync'd modules on the network. In the rule you only need to state "On taskname#valuename do". You can say "On taskname#valuename=0 Do" as well etc.
An easy way to see what is going on is to setup the globalsync settings on all modules. On the module that you want to act on the event go to TOOLS and then Log (Make sure your web log setting is 4). Then on the module that will be generating the event, cause the event to trigger (Flip the switch, turn on the light etc). You should see the log show something like "EVENT: taskname#valuename". If you can see this then you can write rules to act on the event.

There are other ways to do this. You mentioned the SendTo command. This could be used in exactly the same way to send an event to a specific module. I use this in an outbuilding on my property. The building is a fairly large barn-like structure that I use as an electronics workshop. There is a Fluorescent light about 10 feet up and I have another light that illuminates the toolbox area. I have one of my plug modules near the door. There is a second plug module up in the rafters that controls the ceiling lights. I didn't want to have to fumble with my phone every time I wanted to turn on the lights so I used a button on the toolbox light module near the door to send an event to the ceiling module. Now when I enter the shop I press the button and both lights come on but I can use my phone to turn them on or off individually or I can turn them both off remotely (Sometimes I forget to turn them off). I did not want to use globalsync here because no-one else on the network needed to act on that event. The front gate, however sends it's event to several modules that turn on lights all along the driveway. I could have used a sendTo to send an event to each of those modules but it was easier to send out a global event. I also eventually want an indoor annunciator that will play a chime when the gate is opened, alerting me to someone approaching. I will then be able to only set up a rule on that module to have it react to the gate event. I won't need to change any other module.

Its all pretty powerful stuff and no its not documented very well but that's why Opensource software always has an associated forum! :D I can only imagine how hard it must be to develop something like ESPEasy. The time demands must be enormous.

Hope this helps

Regards

Dave
Last edited by dduley on 04 May 2016, 19:05, edited 1 time in total.

tozett
Normal user
Posts: 734
Joined: 22 Dec 2015, 15:46
Location: Germany

Re: Monitoring GPIO and PCFGPIO outputs

#8 Post by tozett » 04 May 2016, 18:55

Helps alot, superb answer! :D

Many thanks,
tozett

Post Reply

Who is online

Users browsing this forum: No registered users and 14 guests