How to skip init events

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
Wojtek
New user
Posts: 4
Joined: 11 Oct 2023, 13:08

How to skip init events

#1 Post by Wojtek » 11 Oct 2023, 13:55

Hi,

I have a button that populate state via MQTT. I have a controller to publish and devices: switch to monitor GPIO and MQTT_import to subscribe topic.
Everything is coupled by rules and working like a charm, no issues.
BUT, if I restart ESP or update Device EE runs init which trigger rule that toggle topic value and light is going on/off.
To solve this I could do something like that:

Code: Select all

On System#Boot do
  TimerSet,1,5 //set timer #1 to 5 seconds
Endon

On Rules#Timer=1 Do
  Let,1,1 //set variable 1 to 1 after the 5 seconds of the timer
Endon

On Sw#State Do //on push button press
  If  [var#1]=1
    If [var#2] < 4
      Let,2,[var#2]+1
    Else
This couse that If [var#1]=1 is checked every time button is pushed. Is there a different way to make it working? Different means without if .

Kind regards,
Wojtek

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

Re: How to skip init events

#2 Post by TD-er » 11 Oct 2023, 14:06

You could disable the task generating the events using taskdisable command at boot.
Or maybe setting the boot state of the pin in the hardware tab is already helping here?

Or simply start monitoring the pin after the 5 second timer you already have?

Wojtek
New user
Posts: 4
Joined: 11 Oct 2023, 13:08

Re: How to skip init events

#3 Post by Wojtek » 11 Oct 2023, 15:24

@TD-er,

do you mean something like that:

Code: Select all

On System#Boot Do
  LogEntry,"BOOT -----=====------"
  TaskDisable,1
  TimerSet,1,10 //set timer #1 to 10 seconds
Endon
On Rules#Timer=1 Do
  TaskEnable,1
Endon
On SW5#State Do
....
It looks like there is an event queue. ESP reboots and after 10 sec it toggle topic.
I use monostable switches so the pin state doesn't really matter. MQTT topic value matters and it don't have to match switch state.
What do you mean by that:
Or simply start monitoring the pin after the 5 second timer you already have?
Thanks in advance,
Wojtek

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

Re: How to skip init events

#4 Post by TD-er » 11 Oct 2023, 15:41

Sending logs may take some time, so better do the taskdisable first.

And you mentioned "monitoring" so I assumed you may be using the monitor command to get events on pin state changes.
Since you won't get events from this "monitor" until you actually start the monitor command, you can suppress these events at boot.

However when you experience debounce pulses, this may easily flood the event queue.

Another approach can be to add some capacitor over GND and the GPIO pin you try to monitor.
This will filter out some bounce signals or picked up noise.
Something like 100 nF is always a good start.

Wojtek
New user
Posts: 4
Joined: 11 Oct 2023, 13:08

Re: How to skip init events

#5 Post by Wojtek » 16 Oct 2023, 14:41

@TD-er,

thanks for advice. I spent weekend learning rules, functions. etc. And I choose to use Monitor "option".
It is set in timer a working as expected.

Thank you very much,
Wojtek

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

Re: How to skip init events

#6 Post by TD-er » 16 Oct 2023, 15:43

Great!
Sounds like a weekend well spent :)

Post Reply

Who is online

Users browsing this forum: No registered users and 30 guests