Hello,
I’m wondering if anybody managed to use the wait until action during the boot because it seems not to work for me.
on_boot:
# priority: 800
# then:
- display.page.show: boot
- delay: 4s
- display.page.show: connection
- wait_until:
# timeout: 10s # this is not working but I'm unaware how to use it
binary_sensor.is_on: connection_status
# wifi.connected: #or this
- delay: 2s
- display.page.show: home
for some reason the script is not waiting the api connection (neighter the wifi connection) before going on because a script in the loop is changing my page during the boot (probably due to a switch restore mode happening at some stage in the boot that activates another display page).
Anybody could help me to get a clue about what am I doing wrong? thank you.
Or you may just need to set the boot priority correctly. Set the boot priority to -100.0 as lower is later in the boot process. 800.0 is very early in the boot process, before wifi has even been set up.
Unfortunately I can’t put wait until in the action that belongs to the loop because I don’t need it when I call that action.
Why the priority is so early (default 600 at moment)
The purpouse was to show a “wifi disconnected” icon on a display during the boot, until the device is connected to the wifi (or to the api) and as this state changes it will show the connected icon for 2 seconds before the homescreen will be displayed.
And this is working fine if I disable a call to another action (turn on a switch) that happens later in the code and that might be called only with a binary input_pullup.
I don’t understand how this call ends up in the boot…
There are 2 reason why it should not happen:
anything should wait until the wifi is connected (but in fact seems that wait until is not working as expected during the boot because some things are still happening underneat)
the action that is bothering my display page at the boot should occour only when the button is pressed (and this is not going to happen in the boot).
What is seems to me is that during the boot, notwithstanding the wait until action, the switch restore (who’s actually set on ALWAYS OFF) is triggering the whole action that happens later in the code.
I think this is related to restore because all other actions are nevering bothering the display boot.
wich is default, also attemps to restore the state. I tryend and had the same problem. I should try with a gpio output. What to you think about?
Seems that any state for switch component is somehow initialized at boot. I hope to be wrong…
RESTORE_DEFAULT_OFF` (Default) - Attempt to restore state and default to OFF if not possible to restore.
RESTORE_DEFAULT_ON` - Attempt to restore state and default to ON.
RESTORE_INVERTED_DEFAULT_OFF` - Attempt to restore state inverted from the previous state and default to OFF.
RESTORE_INVERTED_DEFAULT_ON` - Attempt to restore state inverted from the previous state and default to ON.
ALWAYS_OFF` - Always initialize the pin as OFF on bootup.
ALWAYS_ON` - Always initialize the pin as ON on bootup.
This works great for me so far, but I also cannot find a way to use timeout:
I don’t want to get stuck here with wait_until: so is there any help out there for timeout: syntax or usage? No examples found.
esphome:
name: huzzahwin9b
on_boot:
priority: 600 # Defaults to 600 DOESN'T WAIT FOR WIFI
# -100 waits till ALL IS INITIALIZED but NO EXECUTION HERE if no WIFI
then:
- wait_until: # HOW THE HECK DO YOU USE timeout:
wifi.connected:
- lambda: 'id(displaytext).publish_state("wifi on");'
- wait_until:
api.connected: # REMEMBER THAT LOGGER COUNTS AS AN API CLIENT
- lambda: 'id(displaytext2).publish_state("api on");'
I tried to use the binary_sensor route but I can’t figure out how to update a sensor or variable with the state of api.connected: or wifi.connected:
I have learned to NOT trust the execution order (or that it will even occur) in the yaml body in the absence of wifi. That is is why I’m now checking for connectivity first and putting sleep control all under esphome: on_boot:
My project needs to boot and execute correctly if wifi is there or not.
I need to guarantee wifi and api are connected, and if not, then TIMEOUT and go back to sleep. I have sleep control working all in api from the hassio front end. My project will be in the car, periodically waking up and checking for home wifi, and if so, report in and exchange data, and then go back to sleep.
In my experience, I have found that messing with priority: -100 causes no execution of whatever is under on_boot: after esphome: so best to leave at 600.
esphome:
name: huzzahwin9b
on_boot:
priority: -100 # -100 waits till ALL IS INITIALIZED but NO EXECUTION HERE if no WIFI
then: # NOTHING HAPPENS AFTER HERE WITH priority -100