Switch State On Boot

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
wiredcharlie
Normal user
Posts: 57
Joined: 28 Sep 2020, 13:58

Switch State On Boot

#1 Post by wiredcharlie » 18 Jul 2023, 18:20

I have a physical toggle switch as an input. I want to be able to read the sate of the switch onboot.

Experiment:

Code: Select all


On System#Boot do  

    If Pump#State=1
           7dtext,On
    Endif
   If Pump#State=0
           7dtext,Off
    Endif
Endon

No output! The switch has no state until it reveals itself by changing state?

Micha_he
Normal user
Posts: 372
Joined: 07 Feb 2018, 19:14
Location: Helmstedt, Germany

Re: Switch State On Boot

#2 Post by Micha_he » 18 Jul 2023, 20:55

Have you enabled "Send boot state" in the switch-configuration?

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

Re: Switch State On Boot

#3 Post by Ath » 18 Jul 2023, 20:56

wiredcharlie wrote: 18 Jul 2023, 18:20 No output! The switch has no state until it reveals itself by changing state?
It is not sure that the Switch plugin or 7Segment plugin are already initialized at the System#Boot event, so you might want to wait a little, for an event that will occur a bit later:

Code: Select all

On WiFi#Connected do  
    If Pump#State=1
           7dtext,On
    Else
           7dtext,Off
    Endif
Endon
Also simplified the code a bit, using 'else' instead of another 'if'.
/Ton (PayPal.me)

wiredcharlie
Normal user
Posts: 57
Joined: 28 Sep 2020, 13:58

Re: Switch State On Boot

#4 Post by wiredcharlie » 18 Jul 2023, 21:20

Micha_he wrote: 18 Jul 2023, 20:55 Have you enabled "Send boot state" in the switch-configuration?
Tried that - but thanks :)
Ath wrote: 18 Jul 2023, 20:56 It is not sure that the Switch plugin or 7Segment plugin are already initialized at the System#Boot event, so you might want to wait a little,
...but I had it displaying something else from On boot and it worked.
Ath wrote: 18 Jul 2023, 20:56 for an event that will occur a bit later:....
... I tried a one second delay with a timer but that didn't work.

I think most folk use buttons, but this use case relies upon a pre-select, where the switch is set and then the power is switched on.

User avatar
chromo23
Normal user
Posts: 827
Joined: 10 Sep 2020, 16:02
Location: germany

Re: Switch State On Boot

#5 Post by chromo23 » 18 Jul 2023, 21:52

Have you tried TaskRun?

Code: Select all

On System#Boot do  
  TaskRun,1 //(or whatever the number of the switch plugin is)
Endon

On Pump#State do
 If %eventvalue%=1
           7dtext,On
 Else
           7dtext,Off
 Endif
Endon

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

Re: Switch State On Boot

#6 Post by Ath » 18 Jul 2023, 21:59

chromo23 wrote: 18 Jul 2023, 21:52

Code: Select all

On System#Boot do  
  TaskRun,1 //(or whatever the number of the switch plugin is)
Endon
You mean TaskRun,Pump ? 8-)
/Ton (PayPal.me)

User avatar
chromo23
Normal user
Posts: 827
Joined: 10 Sep 2020, 16:02
Location: germany

Re: Switch State On Boot

#7 Post by chromo23 » 18 Jul 2023, 22:02

Ath wrote: 18 Jul 2023, 21:59 You mean TaskRun,Pump ?
Wow, is this a thing now? :) Things are changing fast here....

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

Re: Switch State On Boot

#8 Post by Ath » 18 Jul 2023, 22:07

chromo23 wrote: 18 Jul 2023, 22:02 Wow, is this a thing now? :) Things are changing fast here....
That improvement was merged well over 2 years ago :lol:
/Ton (PayPal.me)

User avatar
chromo23
Normal user
Posts: 827
Joined: 10 Sep 2020, 16:02
Location: germany

Re: Switch State On Boot

#9 Post by chromo23 » 18 Jul 2023, 22:12

Ath wrote: 18 Jul 2023, 22:07 That improvement was merged well over 2 years ago :lol:
:shock:

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

Re: Switch State On Boot

#10 Post by TD-er » 18 Jul 2023, 23:03

Or you can use [plugin#gpio#pinstate#13] as direct call to read the state of GPIO 13 :)

See: https://espeasy.readthedocs.io/en/lates ... ing-events (and then scroll up half a page)

wiredcharlie
Normal user
Posts: 57
Joined: 28 Sep 2020, 13:58

Re: Switch State On Boot

#11 Post by wiredcharlie » 19 Jul 2023, 12:26

Thanks TD-er!

That was really helpful. Also, by triggering the Monitor instruction after boot, I removed the unintended consequence of pre-setting the switch prior to power on.

Post Reply

Who is online

Users browsing this forum: No registered users and 37 guests