206 lines
5.8 KiB
YAML
206 lines
5.8 KiB
YAML
# Board: Generic ESP32-C3 Board (Generic)
|
|
# Definition: definitions/boards/generic-esp32c3/manifest.yaml
|
|
|
|
esphome:
|
|
name: the-saloon
|
|
friendly_name: the-saloon
|
|
|
|
api:
|
|
encryption:
|
|
key: "hOwepopyk9l0dnp8M+UBkLfhIIel75DOlYCtwJG8tvI="
|
|
|
|
ota:
|
|
- platform: esphome
|
|
|
|
wifi:
|
|
ssid: !secret wifi_ssid
|
|
password: !secret wifi_password
|
|
ap:
|
|
ssid: the-saloon Fallback Hotspot
|
|
password: "JrEe6jVLK36I"
|
|
|
|
|
|
esp32:
|
|
board: esp32-s3-devkitc-1
|
|
variant: esp32s3
|
|
flash_size: 16MB
|
|
framework:
|
|
type: esp-idf
|
|
|
|
psram:
|
|
mode: octal
|
|
speed: 80MHz
|
|
|
|
logger:
|
|
|
|
# Backlight
|
|
output:
|
|
- platform: ledc
|
|
pin: GPIO4
|
|
id: backlight_pwm
|
|
frequency: 5000Hz
|
|
|
|
light:
|
|
- platform: monochromatic
|
|
name: "Display Backlight"
|
|
id: backlight
|
|
output: backlight_pwm
|
|
restore_mode: ALWAYS_ON
|
|
gamma_correct: 2.8 # makes low brightness steps feel more even
|
|
default_transition_length: 0s
|
|
|
|
# Display bus (8-bit parallel, declared as an octal "spi")
|
|
spi:
|
|
type: octal
|
|
clk_pin: 8
|
|
data_pins:
|
|
- 39
|
|
- 40
|
|
- 41
|
|
- 42
|
|
- number: 45
|
|
ignore_strapping_warning: true
|
|
- number: 46
|
|
ignore_strapping_warning: true
|
|
- 47
|
|
- 48
|
|
|
|
display:
|
|
- platform: mipi_spi
|
|
model: t-display-s3
|
|
rotation: 270
|
|
update_interval: 5s
|
|
lambda: |-
|
|
// RAM
|
|
if (id(nas_ram_free).has_state())
|
|
it.printf(10, 10, id(roboto), "%.1f GB", id(nas_ram_free).state);
|
|
|
|
// Disk bar
|
|
// it.printf(10, 105, id(roboto), "HDD");
|
|
if (id(nas_disk_percent).has_state()) {
|
|
float pct = id(nas_disk_percent).state;
|
|
int x = 10, y = 135, w = 300, h = 22;
|
|
Color c = pct > 90 ? Color(255, 0, 0) : (pct > 75 ? Color(255, 165, 0) : Color(0, 200, 0));
|
|
it.filled_rectangle(x + 2, y + 2, (int)((w - 4) * pct / 100.0f), h - 4, c);
|
|
it.printf(10, 50, id(roboto), "%.1f%%", pct);
|
|
}
|
|
|
|
it.printf(10, 105, id(roboto_big), "%s - %.0f", id(lights_str).state.c_str(), id(lights_on_count).state);
|
|
script:
|
|
- id: update_brightness
|
|
then:
|
|
- lambda: |-
|
|
auto now = id(ha_time).now();
|
|
if (!now.is_valid()) return; // time not synced yet
|
|
bool night = (now.hour >= 17 || now.hour < 6);
|
|
auto call = id(backlight).turn_on();
|
|
call.set_brightness(night ? 0.05 : 1.0); // 5% at night, 100% by day
|
|
call.set_transition_length(0);
|
|
call.perform();
|
|
time:
|
|
- platform: homeassistant
|
|
id: ha_time
|
|
on_time_sync:
|
|
- script.execute: update_brightness # applies the right level after boot
|
|
on_time:
|
|
- hours: 17
|
|
minutes: 0
|
|
seconds: 0
|
|
then:
|
|
- script.execute: update_brightness
|
|
- hours: 6
|
|
minutes: 0
|
|
seconds: 0
|
|
then:
|
|
- script.execute: update_brightness
|
|
font:
|
|
- file: "gfonts://Roboto"
|
|
id: roboto
|
|
size: 24
|
|
- file: "gfonts://Roboto"
|
|
id: roboto_big
|
|
size: 48
|
|
glyphs: ["●", "○"]
|
|
# Data from Glances (same as before)
|
|
http_request:
|
|
timeout: 5s
|
|
|
|
sensor:
|
|
- platform: template
|
|
id: nas_ram_free
|
|
name: "NAS RAM libre"
|
|
unit_of_measurement: "GB"
|
|
accuracy_decimals: 0
|
|
state_class: measurement
|
|
- platform: template
|
|
id: nas_disk_percent
|
|
name: "NAS disque utilisé"
|
|
unit_of_measurement: "%"
|
|
accuracy_decimals: 1
|
|
state_class: measurement
|
|
- platform: template
|
|
id: lights_on_count
|
|
name: "Hue lights on"
|
|
accuracy_decimals: 0
|
|
update_interval: never
|
|
|
|
text_sensor:
|
|
- platform: template
|
|
id: lights_str
|
|
name: "Hue lights state"
|
|
update_interval: never
|
|
|
|
interval:
|
|
- interval: 60s
|
|
then:
|
|
- http_request.get:
|
|
url: http://192.168.1.19:61208/api/4/mem
|
|
capture_response: true
|
|
on_response:
|
|
- then:
|
|
- lambda: |
|
|
json::parse_json(body, [](JsonObject root) -> bool {
|
|
id(nas_ram_free).publish_state(root["available"].as<float>() / 1073741824.0f);
|
|
return true;
|
|
});
|
|
- http_request.get:
|
|
url: http://192.168.1.19:61208/api/4/fs
|
|
capture_response: true
|
|
on_response:
|
|
- then:
|
|
- lambda: |
|
|
JsonDocument doc;
|
|
if (deserializeJson(doc, body)) return;
|
|
for (JsonObject fs : doc.as<JsonArray>()) {
|
|
if (strcmp(fs["mnt_point"] | "", "/etc/hosts") == 0) { // your mount point
|
|
id(nas_disk_percent).publish_state(fs["percent"].as<float>());
|
|
break;
|
|
}
|
|
}
|
|
- http_request.get:
|
|
url: http://192.168.1.10/api/ZhVM43RTDHhmyU9Up08n0ebbCpD6XJ7RtSlcevw1/lights
|
|
capture_response: true
|
|
max_response_buffer_size: 16kB
|
|
on_response:
|
|
- then:
|
|
- lambda: |
|
|
if (response->status_code != 200) {
|
|
ESP_LOGD("http_response", "Failed connection to remote sensor. Status code: %d", response->status_code);
|
|
id(lights_str).publish_state("ERR");
|
|
return;
|
|
}
|
|
json::parse_json(body, [](JsonObject root) -> bool {
|
|
int count = 0;
|
|
std::string s;
|
|
for (JsonPair kv : root) {
|
|
JsonObject st = kv.value()["state"];
|
|
bool on = st["on"] | false;
|
|
bool reachable = st["reachable"] | false;
|
|
bool lit = on && reachable;
|
|
if (lit) count++;
|
|
s += lit ? "\u25CF" : "\u25CB";
|
|
}
|
|
id(lights_on_count).publish_state(count);
|
|
id(lights_str).publish_state(s);
|
|
return true;
|
|
}); |