State received 2 times by Nodered

Moderators: grovkillen, Stuntteam, TD-er

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

State received 2 times by Nodered

#1 Post by Sibusate » 13 Oct 2022, 14:07

Hi, all

A simple switch on a garage door is connected on GPIO 13 of a nodemcu ESP8266 managed by Easyesp.

When the Garage#Etat changes, a publish command on rules sends :
Publish %sysname%/Garage/Etat,[Garage#Etat] to Home assistant MQTT on a Raspberry Pi 4

Node-red on the same Raspberry Pi 4 receives this state 2 times…… every time !

I try the different combinations of
- ESPEasy Controller > Ignore new/Delete Oldest > Ignore/Check Acknowledgment and Will retain or not
Actually Ignore New + Ignore acknowledgment + Will Retain = off
- EspEasy Hadware : GPIO 13 set as Default or Input : No change on results. Actually set as Input.
- In the log of EasyESP I can check that this Publish command is sent only once.
- I didn’t check parameters in MQTT Broker..... Is there my problem ????
- In Node-red the change state (ON to OFF *AND* OFF to ON) is ALWAYS received 2 times and registered on file Portail.txt on Raspberry….
- I tried different combinations of QOS 0/1/2 without any change on the results…. Always two states received at the same time.

I tried so many tests with these different values that I'm completely lost and I can’t find the good combination of these parameters.....I don’t remember the good values. This problem occured fron only 3 or 4 monthes. Worked correctly before.
Can you help me ?

Best regards
François

Sorry for my poor english….


Here are the rules in Espeasy
// Module portail IP233
on System#Boot do
timerSet,1,60
endon
on Rules#Timer=1 do
Timerset,1,60
Publish %sysname%/SW2/State,[Portail#Etat]
endon
On Portail#Etat do
Publish %sysname%/Portail/Etat,[Portail#Etat]
if [Portail#Etat] = 0
SendToHttp 192.168.1.231,80,'/control?cmd=Event,Portail_Ouverture'
else
SendToHttp 192.168.1.231,80,'/control?cmd=Event,Portail_Fermeture'
endif
endon

Here is the Node export
[{"id":"704ed223.86eca4","type":"mqtt in","z":"ba9b25e5.03e008","name":"Portail_3/Portail/Etat","topic":"Portail_3/Portail/Etat","qos":"0","datatype":"auto","broker":"b3887ed6.b2203","x":110,"y":120,"wires":[["84234ce.f11b23","48515842.a2732"]]},{"id":"b3887ed6.b2203","type":"mqtt-broker","z":"","name":"Cave","broker":"localhost","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""}]

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

Re: State received 2 times by Nodered

#2 Post by TD-er » 13 Oct 2022, 14:14

You are sending something via sendtohttp.
This isn't the same ESPEasy node, right?

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

Re: State received 2 times by Nodered

#3 Post by TD-er » 13 Oct 2022, 15:09

- ESPEasy Controller > Ignore new/Delete Oldest > Ignore/Check Acknowledgment and Will retain or not
Actually Ignore New + Ignore acknowledgment + Will Retain = off
These are related to the sending queue.
If this queue is full, what to do, like ignore new ones, or delete the oldest one.

Will retain is related to the LWT of MQTT.
When connecting, a MQTT client sends its Last Will and Testament.
The broker will send this LWT message to all subscribed clients when this node is disconnected.
So this has nothing to do with sending messages, but only on what will happen when the node is no longer connected.

The ignore acknowledgement is not really related to MQTT, so I guess I could remove that one from MQTT controller settings.
For sending to HTTP, you may want to wait for an acknowledgement from the web server. But for MQTT there is not really an option to wait for an ack.

About your GPIO-13 switch...
How is it connected? Via a long cable? What configuration do you use in the switch plugin/task for this GPIO? Especially on a real button, you may need some debounce configured.
Using a long cable, you may get extra unexpected triggers, but that's not the issue here so it seems.

How is the switch task configured? Act on "change" or "rising edge" or "falling edge" ?
If it is just a push button, then you should have something like "rising edge" set as it would otherwise trigger on both pressing and releasing the button.

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

Re: State received 2 times by Nodered

#4 Post by Sibusate » 13 Oct 2022, 19:57

Thanks TD-er for your answer...
Let's me a time to understand exactly what you said "between the lines"...
Answers expected tomorrow morning
Best regards
François

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

Re: State received 2 times by Nodered

#5 Post by Sibusate » 14 Oct 2022, 12:26

Hello TD-er
Again, thanks for your answer

In fact I have 2 NodeMcu ESP8266, one on my garage door, the second on my garden gate with a magnetic switch like attached image, on each. One has a short cable (about 15 cm) the second one is longer, about 2 meters.
I have exactly the same problem one the two detectors (as if commmand %sysname%/Garage/Etat,[Garage#Etat] or Portail (=gate) is sent two times at each change state.

The http: command is sent to another Nodemcu in my desk. A LED is blinking and a buzzer is bipping when the garage or the gate is open.

How or where do you specify parameter for the switch task (Change/Rising edge or falling edge) ? For me is on the change state.

Thanks for your help
Best regards
François
magnet contact.jpg
magnet contact.jpg (17.75 KiB) Viewed 3010 times
Portail doublons.jpg
Portail doublons.jpg (67.34 KiB) Viewed 3010 times

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

Re: State received 2 times by Nodered

#6 Post by TD-er » 14 Oct 2022, 13:26

Adding a task with the "Switch input" plugin.
There you set a GPIO nr, switch type to "Switch" and Switch Button Type to either "Push Button Active Low" or "...High"
You have it now probably set to "Normal Switch", which acts on either change.

"Push Button Active Low" triggers on the level going from high to low.
"Push Button Active High" triggers on the level going from low to high.
"Normal Switch" triggers on both high and low.

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

Re: State received 2 times by Nodered

#7 Post by Sibusate » 14 Oct 2022, 15:43

So I set it to normal switch.

Again thanks for you help
Regards
François

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

Re: State received 2 times by Nodered

#8 Post by TD-er » 14 Oct 2022, 17:43

I would expect you need one of the other 2, with "normal switch" you will get 2 events

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

Re: State received 2 times by Nodered

#9 Post by Sibusate » 14 Oct 2022, 17:56

OK... but I receive two times the event Door_Open when the door opens and 2 times the event Door_closed when the door closes.

These event are registered in a document.txt in the Raspberry (2 lines for each event).
It worked correctly (1 line for eac event) 1 year ago.
I probably change a parameter and obtain 2 lines for one event... but which parameter ?

In the log of Easyesp I note only one publish command for each event.
Node-Red receives two times this event.

Regards
François

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

Re: State received 2 times by Nodered

#10 Post by TD-er » 14 Oct 2022, 18:15

Is it possible NodeRed receives the event from 2 different sources?
For example via ESPEasy and also MQTT broker (or whatever connections you configured)

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

Re: State received 2 times by Nodered

#11 Post by Sibusate » 14 Oct 2022, 19:16

NO.
NodeRed (running on the Raspberry) receives the event only from the MQTT Broker.

There are two different Publish commands :
Publish %sysname%/SW2/State,[Portail#Etat] sent every minute

Publish %sysname%/Portail/Etat,[Portail#Etat] when the state changes : it's this event which is received 2 times by NodeRed. Perhaps due to MQTT Broker....

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

Re: State received 2 times by Nodered

#12 Post by TD-er » 14 Oct 2022, 19:21

Does this publish to the MQTT broker also trigger a state change in ESPEasy?

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

Re: State received 2 times by Nodered

#13 Post by Sibusate » 14 Oct 2022, 19:25

No... Only from ESP to the MQTT Broker

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

Re: State received 2 times by Nodered

#14 Post by TD-er » 14 Oct 2022, 19:31

Can you have a look at the MQTT controller settings?
For example can you set the max. retries as a test to 0?

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

Re: State received 2 times by Nodered

#15 Post by Sibusate » 14 Oct 2022, 19:48

I'll try tomorrow...
But I have somm difficulties to manage MQTT. This is the part I know not so well...

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

Re: State received 2 times by Nodered

#16 Post by TD-er » 14 Oct 2022, 19:49

I'm talking about the controller setting in ESPEasy.

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

Re: State received 2 times by Nodered

#17 Post by Sibusate » 15 Oct 2022, 12:46

Hi TD-er

Max retry was at 10.
I change it to 1 (0 is not possible).
No change : NodeRed receives the change state info 2 times at each change state

Again, thanks for your help
Best regards
François

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

Re: State received 2 times by Nodered

#18 Post by TD-er » 15 Oct 2022, 13:01

Hmm, then I'm also a bit out of options here as I don't see where this extra message may come from.

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

Re: State received 2 times by Nodered

#19 Post by Ath » 15 Oct 2022, 14:02

TD-er wrote: 14 Oct 2022, 13:26 Adding a task with the "Switch input" plugin.
There you set a GPIO nr, switch type to "Switch" and Switch Button Type to either "Push Button Active Low" or "...High"
You have it now probably set to "Normal Switch", which acts on either change.

"Push Button Active Low" triggers on the level going from high to low.
"Push Button Active High" triggers on the level going from low to high.
"Normal Switch" triggers on both high and low.
Sibusate wrote: 14 Oct 2022, 15:43 So I set it to normal switch.
I don't think that Normal Switch is the suggested option in your situation, either of the Push Button options should be selected.
/Ton (PayPal.me)

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

Re: State received 2 times by Nodered

#20 Post by Sibusate » 17 Oct 2022, 10:27

No Ath, I want to register in a .txt file each change state : Open action from closed state and Close action from Open state.
My problem is that any change is registered 2 times.
Thanks for your help

_Cyber_
Normal user
Posts: 115
Joined: 20 Oct 2019, 09:46

Re: State received 2 times by Nodered

#21 Post by _Cyber_ » 19 Oct 2022, 09:29

in node red, use the "delay" node to put a rate limit in your flow.
it's quite hidden, there you can define the period where your superfluous messages will be dropped and only one will get forwarded.

e.g.:
rate_limit.png
rate_limit.png (14.27 KiB) Viewed 2857 times

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

Re: State received 2 times by Nodered

#22 Post by Sibusate » 20 Oct 2022, 18:59

Thanks _Cyber_
I'll try your suggestion and post the result in 2-3 days...

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

Re: State received 2 times by Nodered

#23 Post by Sibusate » 21 Oct 2022, 18:55

Hi _Cyber_

I add a rate node with a 6 seconds delay as you suggested and it works !

But... since I added the rate node the result of the join node is inversed : the two members of the Join node are inversed :
I get "day on month : opening at" instead of "opening at : day on month"

Could you explain me that ? How to correct it ?


download/file.php?mode=view&id=7235
Attachments
Join & Rate.png
Join & Rate.png (64.75 KiB) Viewed 2802 times

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

[Resolved] State received 2 times by Nodered

#24 Post by Sibusate » 21 Oct 2022, 19:42

I think I find the solution.
I put the rate node just after the MQTT input node and before the Change and the Date/time nodes.

It seems to work fine...

Again thanks to TD-ER and _Cyber_ and others.
Best regards
François

Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests