Let’s assume I have an ESP8266 device with a BME280 sensor attached and that device/sensor combination is running on batteries using deep sleep to conserve power. The sleep interval could be in the order of hours so I’m not always around when the device wakes.
Now while the device is in deep sleep, I edit and then save the device yaml file with say, some new calibration values for the BME280 sensor.
When the device wakes from deep sleep, I can stop it returning to deep sleep by using an input boolean displayed as a toggle switch…toggle switch on and the device does not reenter deep sleep…turn it off, device reenters deep sleep cycles. This works fine with the below script.
script:
- id: test_ota
mode: queued
then:
- lambda: |-
std::string version = id(esp8266_1_firmware_version).state.c_str();
ESP_LOGI("main", "Firmware Version: %s", version.c_str());
- logger.log: "Checking OTA Mode"
- if:
condition:
binary_sensor.is_on: otamode
then:
- logger.log: 'OTA Mode is On so I am going to PREVENT deep sleep from starting'
- deep_sleep.prevent: gotosleep
- delay: 20s
- homeassistant.service:
service: input_boolean.turn_off
data:
entity_id: input_boolean.ota_mode
else:
- logger.log: 'OTA Mode Off so I am going to ALLOW deep sleep to start'
- delay: 10s
- script.execute: test_ota
What I now want to do, but can’t seem to find any appropriate information online, is when the device wakes from deep sleep and the input boolean is turned on indicating a new update, install that new yaml file to the device . I’ve looked at the documentation for OTA as well as examples but can’t seem to grasp the process.
I don’t wont to simply keep the device awake until I can manually install the update as that affects the battery life.
Any assistance greatly appreciated.