Skip to content

Instantly share code, notes, and snippets.

@albal
Last active January 15, 2023 18:46
Show Gist options
  • Select an option

  • Save albal/1a71fb0078caeb1fec0fa7ee91e4f9b8 to your computer and use it in GitHub Desktop.

Select an option

Save albal/1a71fb0078caeb1fec0fa7ee91e4f9b8 to your computer and use it in GitHub Desktop.
MAX7219 Display with ESPHome
esphome:
name: livingroom
esp8266:
board: esp01_1m
# Enable logging
logger:
# Enable Home Assistant API
api:
password: ""
ota:
password: ""
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "Livingroom Fallback Hotspot"
password: ""
captive_portal:
switch:
- platform: gpio
name: "LED3"
pin:
number: 16
inverted: true
spi:
clk_pin: 5
mosi_pin: 4
display:
- platform: max7219digit
id: my_display
cs_pin: 0
num_chips: 4
intensity: 1
update_interval: 1s
lambda: |-
std::string s = id(elec).state;
std::string delimiter = ".";
std::string token = s.substr(0, s.find(delimiter));
switch (id(page)){
case 1:
it.printf(0, 0, id(pixel_font), "%s%s", id(garage).state.c_str(), id(hatxt).state.c_str() );
break;
case 2:
it.strftime(0, 0, id(pixel_font), "%H:%M", id(now).now());
break;
case 3:
// it.printf(0, 0, id(pixel_font), "Hello World .");
it.printf(0, 0, id(pixel_font), "%sW", token.c_str() );
break;
case 4:
it.printf(0, 0, id(pixel_font), "%s%s", id(temp).state.c_str(), id(hatxt).state.c_str() );
break;
}
font:
- file: "../pixelmix.ttf"
id: pixel_font
size: 8
text_sensor:
- platform: homeassistant
name: "Display Text"
id: hatxt
entity_id: input_text.display
- platform: homeassistant
name: "Garage Temp"
id: garage
entity_id: sensor.garage_os_temperature
- platform: homeassistant
name: "Electric"
id: elec
entity_id: sensor.el_electric_consumption_w
- platform: homeassistant
name: "Living Room Temp"
id: temp
entity_id: sensor.living_room_os_temperature
time:
- platform: sntp
id: now
globals:
- id: page
type: int
initial_value: "1"
interval:
- interval: 10s
then:
- lambda: |-
id(page) = (id(page) + 1);
if (id(page) > 4) {
id(page) = 1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment