Created
September 20, 2022 20:23
-
-
Save dacoffey/787522faed2448757a9e48f56ff5200d to your computer and use it in GitHub Desktop.
ESPHOME: AdaFruit LED Backpack Integration: ht16k33
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Adafruit_LEDBackpack.h> | |
Adafruit_7segment LEDSEG; | |
esphome::time::ESPTime DTNOW; | |
char DTSTR[17]; | |
time_t DT; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
logger: | |
level: WARN | |
esphome: | |
name: test | |
platform: ESP32 | |
board: esp32dev | |
includes: CLOCK.h | |
libraries: | |
- "SPI" | |
- "Wire" | |
- "Adafruit BusIO" | |
- "Adafruit GFX Library" | |
- "Adafruit LED Backpack Library" | |
on_boot: | |
then: | |
- lambda: !lambda |- | |
DTNOW = id(DTHA).now(); | |
id(LEDSEGCOLON) = true; | |
LEDSEG = Adafruit_7segment(); | |
LEDSEG.begin(0x70); | |
LEDSEG.setBrightness(15); | |
LEDSEG.blinkRate(HT16K33_BLINK_OFF); | |
globals: | |
- id: LEDSEGCOLON | |
type: bool | |
restore_value: no | |
<<: !include CONFIG_WIFI.yaml | |
time: | |
- platform: homeassistant | |
id: DTHA | |
i2c: | |
scl: 22 | |
sda: 21 | |
frequency: 50000 | |
scan: true | |
sensor: | |
- platform: template | |
name: "T_DT" | |
update_interval: 100ms | |
lambda: |- | |
DTNOW = id(DTHA).now(); | |
DT = DTNOW.timestamp; | |
strftime(DTSTR, sizeof(DTSTR), "%I%M", localtime(&DT)); | |
return DT; | |
- platform: template | |
name: "T_LEDSEG" | |
update_interval: 750ms | |
lambda: |- | |
LEDSEG.print(strtoul(DTSTR,NULL,10)); | |
LEDSEG.drawColon(id(LEDSEGCOLON) = !id(LEDSEGCOLON)); | |
LEDSEG.writeDisplay(); | |
return id(LEDSEGCOLON); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
substitutions:
plug_name: ESP32 DEVKITV1
esphome:
name: esp-clock
comment: ${plug_name}
includes: include/Adafruit_LEDBackpack.h
libraries:
- "SPI"
- "Wire"
- "Adafruit BusIO"
- "Adafruit GFX Library"
- "Adafruit LED Backpack Library"
esp32:
board: nodemcu-32s
wifi:
ssid: "yourssid_wifi"
password: "yourpass_wifi"
power_save_mode: none
api:
web_server:
port: 80
logger:
baud_rate: 0
ota:
i2c:
scl: 22
sda: 21
scan: true
text_sensor:
name: "LED time"
id: led_time
icon: mdi:web-clock
update_interval: 1s
lambda: |-
Adafruit_7segment display;
if (!display.begin()) {
display = Adafruit_7segment();
}
if (id(ha_sun).elevation() < 0) {
display.setBrightness(1);
} else {
display.setBrightness(10);
}
auto now = id(ha_time).now();
char text[6];
if (now.hour == 0) {
snprintf(text, sizeof(text), "0%02d", now.minute);
} else if (now.hour < 10) {
snprintf(text, sizeof(text), " %d%02d", now.hour, now.minute);
} else {
snprintf(text, sizeof(text), "%d%02d", now.hour, now.minute);
}
display.print(text);
static int i = 0;
if (i == 1) {
display.drawColon(true);
} else {
display.drawColon(false);
}
i++;
if (i == 2) {
i = 0;
}
display.writeDisplay();
std::string str(text);
str.insert(str.length() - 2, ":");
return str;
binary_sensor:
name: "${plug_name} Status"
switch:
name: "${plug_name} Restart"
status_led:
pin:
number: GPIO2
inverted: false
time:
id: ha_time
sun:
latitude: 88.88°
longitude: 88.88°
id: ha_sun