2 different states on the same GPIO
Moderators: grovkillen, Stuntteam, TD-er
2 different states on the same GPIO
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
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
Re: 2 different states on the same GPIO
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.
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.
Re: 2 different states on the same GPIO
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:
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
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
- Thomas
Re: 2 different states on the same GPIO [resolved]
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
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
Re: 2 different states on the same GPIO
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)
Re: 2 different states on the same GPIO
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
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
Re: 2 different states on the same GPIO
Then most likely you are using an older ESPEasy release, as this loopTimerSet feature was introduced around August this year.
/Ton (PayPal.me)
Re: 2 different states on the same GPIO
I suggest adding a custom event rule like this one: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 ?
Code: Select all
on GetDoorState do
Publish %sysname%/Garage/Etat,[Garage#Etat]
endon
Code: Select all
event,GetDoorState
Re: 2 different states on the same GPIO
Thanks Thomas for your help and your suggestions.
Best regards
François
Best regards
François
Who is online
Users browsing this forum: No registered users and 142 guests