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

This commit is contained in:
KemoNine 2019-05-19 22:35:31 -04:00
parent ad172398cc
commit 80bfebabcd
3 changed files with 101 additions and 62 deletions

View File

@ -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();

View File

@ -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
@ -252,53 +340,3 @@ image:
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

View File

@ -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 {
}