From 80bfebabcd00c9a601c4fc676042886726078456 Mon Sep 17 00:00:00 2001 From: KemoNine Date: Sun, 19 May 2019 22:35:31 -0400 Subject: [PATCH] Update polling times to be 'forever' ; tweak boot/shutdown to run sensor updates and immediately deep sleep ; store globals pointers for update components to fire updates during boot --- .../esphome/plant_dashboard/max1704xsensor.h | 3 +- .../plant_dashboard/plant_dashboard.yaml | 158 +++++++++++------- hardware/esphome/plant_dashboard/sht1x.h | 2 +- 3 files changed, 101 insertions(+), 62 deletions(-) diff --git a/hardware/esphome/plant_dashboard/max1704xsensor.h b/hardware/esphome/plant_dashboard/max1704xsensor.h index 28aa145..5be7131 100644 --- a/hardware/esphome/plant_dashboard/max1704xsensor.h +++ b/hardware/esphome/plant_dashboard/max1704xsensor.h @@ -12,7 +12,8 @@ class MAX1704xSensor : public PollingComponent, public sensor::Sensor { sensor::Sensor *alertIsActiveSensor = new sensor::Sensor(); sensor::Sensor *getThresholdSensor = new sensor::Sensor(); - MAX1704xSensor() : PollingComponent(3*60*1000) { } + // 4294967295UL == never per sources + MAX1704xSensor() : PollingComponent(4294967295UL) { } void setup() override { _fuelGauge1.begin(); diff --git a/hardware/esphome/plant_dashboard/plant_dashboard.yaml b/hardware/esphome/plant_dashboard/plant_dashboard.yaml index 0bc7b66..eb8f158 100644 --- a/hardware/esphome/plant_dashboard/plant_dashboard.yaml +++ b/hardware/esphome/plant_dashboard/plant_dashboard.yaml @@ -23,12 +23,37 @@ esphome: - "86" - "5812" on_boot: - priority: 90.0 # 100 is highest where early init happens, 50.0 is where sensors come up - then: - - lambda: |- - pinMode(13, OUTPUT); - digitalWrite(13, HIGH); - delay(10); + - priority: 90.0 # 100 is highest where early init happens, 50.0 is where sensors come up + then: + - lambda: |- + pinMode(13, OUTPUT); + digitalWrite(13, HIGH); + delay(10); + - priority: -100 + then: + - lambda: |- + ESP_LOGD("on_boot: -10:", "Starting sensor updates"); + ESP_LOGD("on_boot: -10:", "WiFi"); + id(sensor_wifi_signal)->update(); + ESP_LOGD("on_boot: -10:", "END WiFi"); + ESP_LOGD("on_boot: -10:", "shtx1"); + ((SHT1xSensor*)id(ptr_component_shtx1))->update(); + ESP_LOGD("on_boot: -10:", "END shtx1"); + ESP_LOGD("on_boot: -10:", "delay(500)"); + delay(500); + ESP_LOGD("on_boot: -10:", "END delay(500)"); + ESP_LOGD("on_boot: -10:", "max1704x"); + id(ptr_component_max1704x)->update(); + ESP_LOGD("on_boot: -10:", "END max1704x"); + ESP_LOGD("on_boot: -10:", "delay(500)"); + delay(500); + ESP_LOGD("on_boot: -10:", "END delay(500)"); + ESP_LOGD("on_boot: -10:", "Display"); + id(display_main).update(); + ESP_LOGD("on_boot: -10:", "END Display"); + ESP_LOGD("on_boot: -10:", "END custom"); + delay(500); + - deep_sleep.enter: deep_sleep_main on_shutdown: then: - lambda: |- @@ -51,14 +76,15 @@ spi: mosi_pin: 18 deep_sleep: - run_duration: 6min - sleep_duration: 54min + id: deep_sleep_main + run_duration: 5min + sleep_duration: 1h wakeup_pin_mode: INVERT_WAKEUP # stop caring and be judicious about tolerance of goofy pin modes # Enable logging logger: level: DEBUG # Flip to ERROR for production deployments - #baud_rate: 0 # Disable UART logging + baud_rate: 0 # Disable UART logging # Enable Home Assistant API #api: @@ -86,10 +112,72 @@ mqtt: topic: 'hass/status' payload: 'offline' +globals: + - id: ptr_component_shtx1 + type: "SHT1xSensor*" + restore_value: no + - id: ptr_component_max1704x + type: "MAX1704xSensor*" + restore_value: no + +binary_sensor: + - platform: status + name: "Status" + +sensor: + - platform: wifi_signal + id: sensor_wifi_signal + name: "WiFi_Signal" + update_interval: 3min + unit_of_measurement: "dB" + accuracy_decimals: 1 + - platform: custom + lambda: |- + SHT1xSensor* sht1x = new SHT1xSensor(); + id(ptr_component_shtx1) = sht1x; + App.register_component(sht1x); + return {sht1x->temp_c_sensor, sht1x->temp_f_sensor, sht1x->humidity_sensor}; + sensors: + - name: "Temperature_C" + id: Temperature_C + unit_of_measurement: "°C" + accuracy_decimals: 1 + - name: "Temperature_F" + id: Temperature_F + unit_of_measurement: "°F" + accuracy_decimals: 1 + - name: "Humidity" + id: Humidity + unit_of_measurement: "%" + accuracy_decimals: 1 + - platform: custom + lambda: |- + MAX1704xSensor* max1704x = new MAX1704xSensor(); + id(ptr_component_max1704x) = max1704x; + App.register_component(max1704x); + return {max1704x->voltageSensor, max1704x->percentSensor, max1704x->isSleepingSensor, max1704x->alertIsActiveSensor, max1704x->getThresholdSensor}; + sensors: + - name: "Battery_Voltage" + id: Battery_Voltage + unit_of_measurement: "V" + accuracy_decimals: 2 + - name: "Battery_Level" + id: Battery_Level + unit_of_measurement: "%" + accuracy_decimals: 1 + - name: "Battery_Sleeping" + id: Battery_Sleeping + - name: "Battery_Alert" + id: Battery_Alert + - name: "Battery_Threshold" + id: Battery_Threshold + accuracy_decimals: 0 + # 2.9" Waveshare e-ink setup # BUSY -> 21, RST -> 14, DC -> 15, CS -> 27, CLK -> SCK(5), DIN -> MOSI(18), GND -> GND, 3.3V -> 3.3V display: - platform: waveshare_epaper + id: display_main cs_pin: 27 dc_pin: 15 busy_pin: 21 @@ -251,54 +339,4 @@ image: - file: graphics/disabled_noun_Tulip_2510353.png # disabled tulip id: disabled_tulip resize: 32x32 - -binary_sensor: - - platform: status - name: "Status" - -sensor: - - platform: wifi_signal - id: sensor_wifi_signal - name: "WiFi_Signal" - update_interval: 3min - unit_of_measurement: "dB" - accuracy_decimals: 1 - - platform: custom - lambda: |- - auto sht1x = new SHT1xSensor(); - App.register_component(sht1x); - return {sht1x->temp_c_sensor, sht1x->temp_f_sensor, sht1x->humidity_sensor}; - sensors: - - name: "Temperature_C" - id: Temperature_C - unit_of_measurement: "°C" - accuracy_decimals: 1 - - name: "Temperature_F" - id: Temperature_F - unit_of_measurement: "°F" - accuracy_decimals: 1 - - name: "Humidity" - id: Humidity - unit_of_measurement: "%" - accuracy_decimals: 1 - - platform: custom - lambda: |- - auto max1704x = new MAX1704xSensor(); - App.register_component(max1704x); - return {max1704x->voltageSensor, max1704x->percentSensor, max1704x->isSleepingSensor, max1704x->alertIsActiveSensor, max1704x->getThresholdSensor}; - sensors: - - name: "Battery_Voltage" - id: Battery_Voltage - unit_of_measurement: "V" - accuracy_decimals: 2 - - name: "Battery_Level" - id: Battery_Level - unit_of_measurement: "%" - accuracy_decimals: 1 - - name: "Battery_Sleeping" - id: Battery_Sleeping - - name: "Battery_Alert" - id: Battery_Alert - - name: "Battery_Threshold" - id: Battery_Threshold - accuracy_decimals: 0 + \ No newline at end of file diff --git a/hardware/esphome/plant_dashboard/sht1x.h b/hardware/esphome/plant_dashboard/sht1x.h index e97a379..e0b0674 100644 --- a/hardware/esphome/plant_dashboard/sht1x.h +++ b/hardware/esphome/plant_dashboard/sht1x.h @@ -17,7 +17,7 @@ class SHT1xSensor : public PollingComponent, public sensor::Sensor { sensor::Sensor *temp_f_sensor = new sensor::Sensor(); sensor::Sensor *humidity_sensor = new sensor::Sensor(); - SHT1xSensor() : PollingComponent(3*60*1000) { } + SHT1xSensor() : PollingComponent(4294967295UL) { } void setup() override { }