Skip to content

Instantly share code, notes, and snippets.

@greghesp
Last active April 14, 2023 15:50
Show Gist options
  • Save greghesp/3d3b3aae3a564454c2ef7104a5ae0bec to your computer and use it in GitHub Desktop.
Save greghesp/3d3b3aae3a564454c2ef7104a5ae0bec to your computer and use it in GitHub Desktop.
esphome:
name: master-bedroom-oled-display
comment: Bedroom OLED with Glucose Levels
esp32:
board: esp32dev
framework:
type: arduino
# Enable logging
logger:
level: DEBUG
mqtt:
broker: !secret mqtt_broker
username: !secret mqtt_username
password: !secret mqtt_password
discovery: false # Only if you use the HA API usually
id: mqtt_client
substitutions:
room_name: 'Master Bedroom'
globals:
- id: last_update_timestamp
type: uint32_t
- id: last_update_seconds
type: uint32_t
# Enable Home Assistant API
api:
ota:
wifi:
ssid: !secret 24_wifi_ssid
password: !secret wifi_password
manual_ip:
static_ip: 192.168.1.74
gateway: 192.168.1.1
subnet: 255.255.255.0
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "Master Bedroom Fallback Hotspot"
password: "TUsyBlAuN0HV"
bluetooth_proxy:
active: true
captive_portal:
time:
- platform: homeassistant
id: esptime
sensor:
- platform: homeassistant
id: glucose_level
entity_id: sensor.dexcom_glucose_value
on_value:
- lambda: |-
id(last_update_timestamp) = millis();
text_sensor:
- platform: homeassistant
id: glucose_trend
entity_id: sensor.dexcom_glucose_trend
font:
- file: "gfonts://Roboto"
id: levels
size: 48
- file: "gfonts://Roboto"
id: font_30
size: 38
- file: "gfonts://Roboto"
id: mmol
size: 8
- file: "gfonts://Roboto"
id: trend
size: 14
- file: "gfonts://Roboto"
id: font_12
size: 12
- file: 'fonts/materialdesignicons-webfont.ttf' # From https://github.com/Templarian/MaterialDesign-Webfont/blob/master/fonts/materialdesignicons-webfont.ttf
id: icon_font
size: 36
glyphs: [
'󰁔', # arrow-right
'󰁃', # arrow down right
'󰁅', # arrow down
'󰁜', # arrow right up
'󰁝', # arrow up
'󰄿', # double up
'󰄼', # double down
'󰀪' #alert
]
i2c:
sda: GPIO23 #yellow
scl: GPIO19 #green
scan: true
frequency: 100kHz
display:
- platform: ssd1306_i2c
model: "SSD1306 128x64"
reset_pin: GPIO0
address: 0x3C
id: my_display
pages:
- id: page1
lambda: |-
it.printf(5, 0, id(levels), TextAlign::TOP_LEFT , "%.1f", id(glucose_level).state);
it.printf(5, 50, id(font_12), "%i minutes ago", id(last_update_seconds)/60);
if (id(glucose_trend).state == "rising quickly") {
return it.print(90, 10, id(icon_font), "󰄿");
}
if (id(glucose_trend).state == "rising slightly") {
return it.print(90, 10, id(icon_font), "󰁜");
}
if (id(glucose_trend).state == "rising") {
return it.print(90, 10, id(icon_font), "󰁝");
}
if (id(glucose_trend).state == "falling") {
return it.print(90, 10, id(icon_font), "󰁅");
}
if (id(glucose_trend).state == "falling slightly") {
return it.print(90, 10, id(icon_font), "󰁃");
}
if (id(glucose_trend).state == "falling quickly") {
return it.print(90, 10, id(icon_font), "󰄼");
}
if (id(glucose_trend).state == "steady") {
return it.print(90, 10, id(icon_font), "󰁔");
}
else {
return it.print(90, 10, id(icon_font), "󰀪");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment