Hi
Working on a Solar Powered Smart Mailbox and struggling with the following so any help will be appreciated. Simply want to show show new battery images as the battery percentage changes.
Trying to adopt this code into ESPhome rather than a native arduino flash.
Board is a TTGO T-Display
Arduino code:
if(BL.getBatteryVolts() >= MIN_USB_VOL){
for(int i=0; i< ARRAY_SIZE(batteryImages); i++){
drawingBatteryIcon(batteryImages[i]);
drawingText("Solar Charging");
vTaskDelay(500);
}
}else{
int imgNum = 0;
int batteryLevel = BL.getBatteryChargeLevel();
if(batteryLevel >=80){
imgNum = 3;
}else if(batteryLevel < 80 && batteryLevel >= 50 ){
imgNum = 2;
}else if(batteryLevel < 50 && batteryLevel >= 20 ){
imgNum = 1;
}else if(batteryLevel < 20 ){
imgNum = 0;
}
ESPHome Code thats inside the display block:
if (id(vcc).state) {
if (id(vcc).state >=80) {
it.image(24, 28, id(battery_image_5));
} else {if (id(vcc).state >=50) {
it.image(110, 28, id(battery_image_3));
} else {if (id(vcc).state >=20) {
it.image(110, 28, id(battery_image_2));
} else {if (id(vcc).state < 20) {
it.image(110, 28, id(battery_image_1));
}
Sensor:
sensor:
- platform: adc
pin: 34
attenuation: 11db
name: VBatt_MBox
id: vcc
update_interval: 10s
on_value_range:
below: 3.00
then:
- switch.turn_on:
id: shutdown_smart_mailbox
filters:- multiply: 1.72
Display Block:
display:
-
platform: st7789v
backlight_pin: GPIO4
cs_pin: GPIO5
dc_pin: GPIO16
reset_pin: GPIO23
rotation: 270
lambda: |-
it.image(0, 0, id(background_1));it.print(24, 86, id(impact_28), id(my_white), “SMART MAILBOX”);
it.rectangle(0, 0, it.get_width(), it.get_height(), id(my_white));
it.rectangle(0, 22, it.get_width(), it.get_height(), id(my_white)); // header barit.strftime((234 / 1), (140 / 3) * 0 + 0, id(impact_17), id(my_white), TextAlign::RIGHT, “%d-%m-%Y”, id(esptime).now());
if (id(Smart_Mailbox_Sensor).state) {
it.print(5, 1, id(impact_17), id(my_yellow), TextAlign::TOP_LEFT, “ONLINE”);
}
else {
it.print(5, 1, id(impact_17), id(my_red), TextAlign::TOP_LEFT, “OFFLINE”);
}if (id(vcc).has_state()) {
it.printf(24, 48, id(impact_28), id(my_white), “%.2fv %.1f %%”, id(vcc).state, id(batterylevel).state);
}it.image(24, 28, id(battery_image_5));
it.image(110, 28, id(battery_image_1));if (id(Smart_Mailbox_Status).state) {
it.print(60, 1, id(impact_17), id(my_red), TextAlign::TOP_LEFT, " - OPENED");
}
else {
it.print(60, 1, id(impact_17), id(my_white), TextAlign::TOP_LEFT, " - CLOSED");
}
End Result to date


