Reading (output) GPIO state within rules

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
jgrad
Normal user
Posts: 105
Joined: 29 Aug 2016, 22:03
Location: Slovenia

Reading (output) GPIO state within rules

#1 Post by jgrad » 16 Nov 2020, 08:56

Hi,

what is preferred way (if exists) to read state of output GPIO within rules and GPIO is not defined within Taks/Devices? Is there a way to make such

I have relays on GPIO 15 and GPIO4 and i want to make following if clause (below example doesn't work):

if [GPIO#15]=1 and [GPIO#4]=1
GPIO,15,0
GPIO,4,0
endif

TD-er
Core team member
Posts: 8846
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Reading (output) GPIO state within rules

#2 Post by TD-er » 16 Nov 2020, 09:05

See the "monitor" command: https://espeasy.readthedocs.io/en/lates ... ore-events
N.B. this does require a recent build.

jgrad
Normal user
Posts: 105
Joined: 29 Aug 2016, 22:03
Location: Slovenia

Re: Reading (output) GPIO state within rules

#3 Post by jgrad » 16 Nov 2020, 10:33

I use Monitor function on input GPIOs in order to get event when state is changed (button pressed).

I am asking for solution to get state of output GPIO which is used for controlling relay. Since I dont want to get events when changed I am asking for solution like in example in documentation

Code: Select all

if [Plugin#GPIO#Pinstate#13]=0
   // do something
 endif
 

but for this I have to define every output as task/device.

Is Monitor command also useful for monitoring output GPIOs without using events which are generated on change? How many system resources does Monitor command consume?

if YES I assume that after enabling Monitor on output GPIO (eg. GPIO15) I will be able to
if [GPIO#15]=1
// do something
endif

Oetsch
Normal user
Posts: 195
Joined: 13 Jul 2020, 12:10

Re: Reading (output) GPIO state within rules

#4 Post by Oetsch » 16 Nov 2020, 18:29

Hi
I´m only beginner at this topic but according my understanding the monitoring function is always enabled for Gpios.

I use the monitor function for additional GPIOs of a PCF8574 IO-Extender and here you have to enable it by rule. But not for GPIOs and therefore your last example can be used directly.

Best regards

P.S.: If I´m wrong regarding enabled monitoring for GPIOs... I use it for 6pcs PCF8574 IOs and have not recognized any load or memory impact.
Only as example how I use it. I like to get an update by Mqtt after reboot about the status of the output and an update in case of a change.
I haven´t had enough free devices to do this by internal input/switch.

Code: Select all

on System#Boot do
Monitor,pcf,1
Monitor,pcf,2
Monitor,pcf,4
Monitor,pcf,5
Monitor,pcf,7
Monitor,pcf,8
pcfgpio,1,1
pcfgpio,2,0
pcfgpio,4,0
pcfgpio,5,1
pcfgpio,7,1
pcfgpio,8,0
endon

on MQTT#Connected do
Publish,%sysname%/PCFGPIO/P1Gruen,[plugin#pcfgpio#pinstate#1]
Publish,%sysname%/PCFGPIO/P2Rot,[plugin#pcfgpio#pinstate#2]
Publish,%sysname%/PCFGPIO/P4BlauET1,[plugin#pcfgpio#pinstate#4]
Publish,%sysname%/PCFGPIO/P5BlauET2,[plugin#pcfgpio#pinstate#5]
Publish,%sysname%/PCFGPIO/P7GelbAT1,[plugin#pcfgpio#pinstate#7]
Publish,%sysname%/PCFGPIO/P8GelbAGarten,[plugin#pcfgpio#pinstate#8]
endon 

on pcf#1 do
Publish,%sysname%/PCFGPIO/P1Gruen,[plugin#pcfgpio#pinstate#1]
endon

on pcf#2 do
Publish,%sysname%/PCFGPIO/P2Rot,[plugin#pcfgpio#pinstate#2]
endon

on pcf#4 do
Publish,%sysname%/PCFGPIO/P4BlauET1,[plugin#pcfgpio#pinstate#4]
endon

on pcf#5 do
Publish,%sysname%/PCFGPIO/P5BlauET2,[plugin#pcfgpio#pinstate#5]
endon

on pcf#7 do
Publish,%sysname%/PCFGPIO/P7GelbAT1,[plugin#pcfgpio#pinstate#7]
endon

on pcf#8 do
Publish,%sysname%/PCFGPIO/P8GelbAGarten,[plugin#pcfgpio#pinstate#8]
endon

leel1967l
Normal user
Posts: 73
Joined: 30 Nov 2017, 18:29

Re: Reading (output) GPIO state within rules

#5 Post by leel1967l » 17 Nov 2020, 17:03

I am asking for solution to get state of output GPIO which is used for controlling relay. Since I dont want to get events when changed I am asking for solution like in example in documentation
Yes, monitor command operates also on output pins.

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest