Skip to content

Instantly share code, notes, and snippets.

@greghesp
Created February 5, 2023 17:25
Show Gist options
  • Save greghesp/d50eeab2800d00d7ee945808000bae71 to your computer and use it in GitHub Desktop.
Save greghesp/d50eeab2800d00d7ee945808000bae71 to your computer and use it in GitHub Desktop.
esphome:
name: dressing-room-esp32
esp32:
board: mhetesp32minikit
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
manual_ip:
static_ip: 192.168.1.243
gateway: 192.168.1.1
subnet: 255.255.255.0
ap:
ssid: "D-Room-Esp32 Fallback Hotspot"
password: !secret wifi_password
# Enable logging
logger:
# Enable Home Assistant API
api:
captive_portal:
ota:
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: "Dressing Room"
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'
id: icon_font
size: 36
glyphs: [
'󰁔', # arrow-right
'󰁃', # arrow down right
'󰁅', # arrow down
'󰁜', # arrow right up
'󰁝', # arrow up
'󰄿', # double up
'󰄼', # double down
'󰀪' #alert
]
globals:
- id: room_topic
type: std::string
initial_value: '"esphome-presence/${room_name}"'
- id: last_update_timestamp
type: uint32_t
- id: last_update_seconds
type: uint32_t
bluetooth_proxy:
active: true
esp32_ble_tracker:
on_ble_advertise:
- then:
- lambda: |-
if (x.get_ibeacon().has_value()) {
std::string uuid;
esp_bt_uuid_t raw_uuid = x.get_ibeacon().value().get_uuid().get_uuid();
char sbuf[64];
char *bpos = sbuf;
switch (raw_uuid.len) {
case ESP_UUID_LEN_128:
for (int8_t i = 0; i <= 15; i++) {
sprintf(bpos, "%02x", raw_uuid.uuid.uuid128[i]);
bpos += 2;
if (i == 6 || i == 8 || i == 10 || i == 12)
sprintf(bpos++, "-");
}
sbuf[47] = '\0';
uuid.assign(sbuf);
break;
default:
uuid = x.get_ibeacon().value().get_uuid().to_string();
std::transform(uuid.begin(), uuid.end(), uuid.begin(), [](unsigned char c){ return std::tolower(c); });
break;
}
char mbuf[32] = {0};
sprintf(mbuf, "-%hu-%hu", x.get_ibeacon().value().get_major(), x.get_ibeacon().value().get_minor());
uuid.append(mbuf);
int8_t tx_power = -69;
float dist = pow(10, (float)(tx_power - x.get_rssi()) / (10 * 2));
ESP_LOGD("ble_adv", "Sending MQTT room update for '%s' (%s): %.03fm (%d rssi)",
x.get_name().c_str(), uuid.c_str(), dist, x.get_rssi());
id(mqtt_client).publish_json(id(room_topic), [=](JsonObject root) {
root["id"] = uuid;
root["name"] = x.get_name();
root["distance"] = dist;
});
}
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
i2c:
sda: GPIO23 #white
scl: GPIO19 #purple
scan: true
frequency: 100kHz
display:
- platform: ssd1306_i2c
model: "SH1106 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