Moderators: grovkillen, Stuntteam, TD-er
-
wiredcharlie
- Normal user
- Posts: 57
- Joined: 28 Sep 2020, 13:58
#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
#2
Post
by Micha_he » 18 Jul 2023, 20:55
Have you enabled "Send boot state" in the switch-configuration?
-
Ath
- Normal user
- Posts: 3643
- Joined: 10 Jun 2018, 12:06
- Location: NL
#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'.
-
wiredcharlie
- Normal user
- Posts: 57
- Joined: 28 Sep 2020, 13:58
#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.
-
chromo23
- Normal user
- Posts: 829
- Joined: 10 Sep 2020, 16:02
- Location: germany
#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
-
Ath
- Normal user
- Posts: 3643
- Joined: 10 Jun 2018, 12:06
- Location: NL
#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 ?
-
chromo23
- Normal user
- Posts: 829
- Joined: 10 Sep 2020, 16:02
- Location: germany
#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....
-
Ath
- Normal user
- Posts: 3643
- Joined: 10 Jun 2018, 12:06
- Location: NL
#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
-
chromo23
- Normal user
- Posts: 829
- Joined: 10 Sep 2020, 16:02
- Location: germany
#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
-
wiredcharlie
- Normal user
- Posts: 57
- Joined: 28 Sep 2020, 13:58
#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.
Who is online
Users browsing this forum: Bing [Bot], Google [Bot] and 2 guests