2 different states on the same GPIO

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
Sibusate
Normal user
Posts: 17
Joined: 21 Apr 2020, 09:24

2 different states on the same GPIO

#1 Post by Sibusate » 06 Nov 2020, 17:22

Hello everybody,
I have a nodemcu ESP-12F with a simple switch (ILS) connected to GPIO-13(D7). This switch detects the position of my garage door (open or close).
This nodemcu is managed by EasyESP Mega 20200305 and communicates with OpenHab MQTT on RPI4 with a dashboard Node-Red
On ESP, I defined one OpenHab MQTT controller and 1 device checking the GPIO-13(D7) : interval 0 to detect and register to a file the action to open and close the door. This information is wrote on a text file with date and time.
As my wifi isn't perfectly stable, sometimes I miss this information.
To check that point I defined a second device for the same GPIO-13(D7) and the same parameters but with an interval = 60 seconds. This forces a communication between NodeMCU and RPI and give me the state of the door every minute (I don't want
write this information to a file (too large...) but only on the Node-Red dashboard.
Sometimes Task1:Garage_2/Garage/Etat = 1 (last action = door closed) and at the same time Task2:Garage_2/SW2/State = 0 (every minute = door open).

Question : Is it possible to define 2 devices for the same GPIO-13 ????
How to have these 2 informations : every minute and at the action time

Thanks for your help,
Best regards,
François
Garage.jpg
Garage.jpg (152.36 KiB) Viewed 7188 times

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

Re: 2 different states on the same GPIO

#2 Post by TD-er » 06 Nov 2020, 22:55

Defining 2 tasks using the same GPIO is asking for trouble.
I guess you could try to read from the GPIO via rules commands and then act on them by sending data via these rules. (see monitor command)

The switch plugin may be doing more than you would expect, as for some controllers (e.g. OpenHAB MQTT and Domoticz MQTT) the switch plugin can also receive state updates.
So it may also try to set the GPIO to some state.

User avatar
ThomasB
Normal user
Posts: 1065
Joined: 17 Jun 2018, 20:41
Location: USA

Re: 2 different states on the same GPIO

#3 Post by ThomasB » 06 Nov 2020, 23:24

I suggest deleting the SW2 (task #2) and perform its 60 second send interval using rules (as mentioned by TD-er).

Here is a Rule example to perform a periodic (60 sec timer interval) Garage Door update:

Code: Select all

on System#Boot do
   timerSet,1,60
endon

on Rules#Timer=1 do
   timerSet,1,60
   Publish %sysname%/Garage/Etat,[Garage#Etat]
endon
You'll need to edit the publish statement to match what your OH's MQTT expects. You didn't show a screenshot of the Garage Task so I will assume it has correct settings and can remain as-is. But post a screenshot if you need further assistance.

- Thomas

Sibusate
Normal user
Posts: 17
Joined: 21 Apr 2020, 09:24

Re: 2 different states on the same GPIO [resolved]

#4 Post by Sibusate » 07 Nov 2020, 09:47

Thanks for your suggestions... It works fine !

Just another question : is't possible to send, fron Node-red on RPI4 to the NodeMCU with ESP-Easy Mega a command to read the state of the GPIO13 (switch) at that time and get the answer ? I don't want to get the last state registered in MQTT broker but the real state at that time.....
I don't see how to do that....

Again, thanks for your help.
Best regards
François

User avatar
Ath
Normal user
Posts: 3517
Joined: 10 Jun 2018, 12:06
Location: NL

Re: 2 different states on the same GPIO

#5 Post by Ath » 07 Nov 2020, 10:01

To make Thomas' solution a bit more efficient, and avoid drifting in time, the 'newish' loopTimerSet command could be used:

Code: Select all

on System#Boot do
   looptimerSet,1,60
endon

on Rules#Timer=1 do
   Publish %sysname%/Garage/Etat,[Garage#Etat]
endon
/Ton (PayPal.me)

Sibusate
Normal user
Posts: 17
Joined: 21 Apr 2020, 09:24

Re: 2 different states on the same GPIO

#6 Post by Sibusate » 07 Nov 2020, 11:53

Thanks Ath for your help.
Unfortunatly it doesn't work.... But I don't need a very precise timing... Solutions given by Thomas and TD-er are good for me.
Rgds
François

User avatar
Ath
Normal user
Posts: 3517
Joined: 10 Jun 2018, 12:06
Location: NL

Re: 2 different states on the same GPIO

#7 Post by Ath » 07 Nov 2020, 14:04

Sibusate wrote: 07 Nov 2020, 11:53 Unfortunatly it doesn't work....
Then most likely you are using an older ESPEasy release, as this loopTimerSet feature was introduced around August this year.
/Ton (PayPal.me)

User avatar
ThomasB
Normal user
Posts: 1065
Joined: 17 Jun 2018, 20:41
Location: USA

Re: 2 different states on the same GPIO

#8 Post by ThomasB » 07 Nov 2020, 18:17

is't possible to send, fron Node-red on RPI4 to the NodeMCU with ESP-Easy Mega a command to read the state of the GPIO13 (switch) at that time and get the answer ?
I suggest adding a custom event rule like this one:

Code: Select all

on GetDoorState do
   Publish %sysname%/Garage/Etat,[Garage#Etat]
endon
This rule can be executed by other rules, Tools->Command, HTTP, and MQTT. Here is the basic event syntax to execute the rule:

Code: Select all

event,GetDoorState
- Thomas

Sibusate
Normal user
Posts: 17
Joined: 21 Apr 2020, 09:24

Re: 2 different states on the same GPIO

#9 Post by Sibusate » 07 Nov 2020, 18:43

Thanks Thomas for your help and your suggestions.
Best regards
François

Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 128 guests