260 lines
7.3 KiB
YAML
260 lines
7.3 KiB
YAML
substitutions:
|
|
name: "energymonitor"
|
|
friendly_name: "Energy Monitor"
|
|
|
|
esphome:
|
|
name: ${name}
|
|
friendly_name: ${friendly_name}
|
|
name_add_mac_suffix: false
|
|
project:
|
|
name: monitor.energymonitor
|
|
version: "1.0"
|
|
on_boot:
|
|
then:
|
|
- light.turn_on: display_backlight
|
|
|
|
esp32:
|
|
board: m5stack-core-esp32
|
|
framework:
|
|
type: esp-idf
|
|
|
|
network:
|
|
enable_ipv6: true
|
|
|
|
wifi:
|
|
networks:
|
|
- ssid: "Voltage-legacy"
|
|
password: !secret voltage_legacy_psk
|
|
priority: 10
|
|
- ssid: "Moppelkotze"
|
|
password: !secret moppelkotze_psk
|
|
priority: 5
|
|
use_address: 192.168.126.250
|
|
on_connect:
|
|
- lambda: id(wifi_connected) = true;
|
|
on_disconnect:
|
|
- lambda: id(wifi_connected) = false;
|
|
power_save_mode: high
|
|
min_auth_mode: WPA2
|
|
ap:
|
|
ssid: "Energymonitor Fallback Hotspot"
|
|
password: !secret fallback_psk
|
|
|
|
captive_portal:
|
|
|
|
time:
|
|
- platform: sntp
|
|
id: sntp_time
|
|
timezone: Europe/Berlin
|
|
servers:
|
|
- de.pool.ntp.org
|
|
|
|
# Values are maintained in secrets.yaml.
|
|
wireguard:
|
|
id: energymonitor_wireguard
|
|
address: !secret energymonitor_wireguard_address
|
|
netmask: !secret energymonitor_wireguard_netmask
|
|
private_key: !secret energymonitor_wireguard_private_key
|
|
peer_endpoint: !secret energymonitor_wireguard_peer_endpoint
|
|
peer_port: !secret energymonitor_wireguard_peer_port
|
|
peer_public_key: !secret energymonitor_wireguard_peer_public_key
|
|
peer_allowed_ips:
|
|
- !secret energymonitor_wireguard_peer_allowed_ip
|
|
peer_persistent_keepalive: 25s
|
|
# Avoid rebooting while the placeholder endpoint is intentionally unreachable.
|
|
reboot_timeout: 0s
|
|
|
|
logger:
|
|
|
|
api:
|
|
encryption:
|
|
key: !secret apikey
|
|
|
|
ota:
|
|
platform: esphome
|
|
password: !secret ota
|
|
|
|
spi:
|
|
clk_pin: GPIO18
|
|
mosi_pin: GPIO23
|
|
|
|
output:
|
|
- platform: gpio
|
|
pin: GPIO32
|
|
id: display_backlight_output
|
|
|
|
light:
|
|
- platform: binary
|
|
id: display_backlight
|
|
name: "Display Backlight"
|
|
output: display_backlight_output
|
|
restore_mode: ALWAYS_ON
|
|
|
|
font:
|
|
- file: "fonts/Roboto-Regular.ttf"
|
|
id: font_small
|
|
size: 18
|
|
glyphsets:
|
|
- GF_Latin_Kernel
|
|
glyphs: ["äöüÄÖÜß"]
|
|
- file: "fonts/Roboto-Bold.ttf"
|
|
id: font_title
|
|
size: 28
|
|
glyphsets:
|
|
- GF_Latin_Kernel
|
|
glyphs: ["äöüÄÖÜß"]
|
|
- file: "fonts/Roboto-Bold.ttf"
|
|
id: font_value
|
|
size: 52
|
|
glyphsets:
|
|
- GF_Latin_Kernel
|
|
glyphs: ["äöüÄÖÜß"]
|
|
- file: "fonts/materialdesignicons-webfont.ttf"
|
|
id: font_icon
|
|
size: 24
|
|
glyphs:
|
|
- "\U000F0306" # mdi:key
|
|
- "\U000F091F" # mdi:wifi-strength-1
|
|
- "\U000F0922" # mdi:wifi-strength-2
|
|
- "\U000F0925" # mdi:wifi-strength-3
|
|
- "\U000F0928" # mdi:wifi-strength-4
|
|
- "\U000F092D" # mdi:wifi-strength-off
|
|
|
|
globals:
|
|
- id: page_index
|
|
type: int
|
|
restore_value: true
|
|
initial_value: '0'
|
|
- id: wifi_connected
|
|
type: bool
|
|
restore_value: false
|
|
initial_value: 'false'
|
|
|
|
sensor:
|
|
# WiFi signal strength
|
|
- platform: wifi_signal
|
|
name: "WiFi Signalstärke"
|
|
id: wifisignal
|
|
update_interval: 60s
|
|
- platform: homeassistant
|
|
id: grid_power
|
|
entity_id: sensor.netzleistung
|
|
internal: true
|
|
- platform: homeassistant
|
|
id: balcony_solar_power
|
|
entity_id: sensor.balkonkraftwerk_power
|
|
internal: true
|
|
- platform: wireguard
|
|
latest_handshake:
|
|
name: 'WireGuard Latest Handshake'
|
|
|
|
binary_sensor:
|
|
- platform: wireguard
|
|
status:
|
|
name: 'WireGuard Status'
|
|
- platform: wireguard
|
|
enabled:
|
|
name: 'WireGuard Enabled'
|
|
# M5Stack Core button A (left). GPIO39 is input-only and has an external pull-up.
|
|
- platform: gpio
|
|
pin:
|
|
number: GPIO39
|
|
mode: INPUT
|
|
inverted: true
|
|
id: button_left
|
|
on_press:
|
|
then:
|
|
- lambda: |-
|
|
id(page_index) = (id(page_index) + 2 - 1) % 2;
|
|
- component.update: tft
|
|
# M5Stack Core button C (right). GPIO37 is input-only and has an external pull-up.
|
|
- platform: gpio
|
|
pin:
|
|
number: GPIO37
|
|
mode: INPUT
|
|
inverted: true
|
|
id: button_right
|
|
on_press:
|
|
then:
|
|
- lambda: |-
|
|
id(page_index) = (id(page_index) + 1) % 2;
|
|
- component.update: tft
|
|
|
|
text_sensor:
|
|
- platform: wireguard
|
|
address:
|
|
name: 'WireGuard Address'
|
|
|
|
# M5CORE is the mipi_spi preset for the M5Stack Core's integrated display.
|
|
display:
|
|
- platform: mipi_spi
|
|
id: tft
|
|
model: M5CORE
|
|
cs_pin: GPIO14
|
|
dc_pin: GPIO27
|
|
reset_pin: GPIO33
|
|
invert_colors: true
|
|
update_interval: 1s
|
|
lambda: |-
|
|
it.fill(Color::BLACK);
|
|
|
|
if (id(sntp_time).now().is_valid()) {
|
|
it.strftime(260, 10, id(font_small), Color::WHITE, TextAlign::TOP_RIGHT,
|
|
"%H:%M", id(sntp_time).now());
|
|
} else {
|
|
it.printf(260, 10, id(font_small), Color::WHITE, TextAlign::TOP_RIGHT, "--:--");
|
|
}
|
|
|
|
// Green means the WireGuard peer is online; red means it is offline.
|
|
const bool wireguard_online = id(energymonitor_wireguard).is_peer_up();
|
|
const Color wireguard_color = wireguard_online ? Color(64, 255, 64) : Color(255, 80, 80);
|
|
it.printf(286, 8, id(font_icon), wireguard_color, TextAlign::TOP_RIGHT, "\U000F0306");
|
|
|
|
// Render the requested MDI Wi-Fi strength glyph in green or red when disconnected.
|
|
const bool wifi_online = id(wifi_connected);
|
|
const Color wifi_color = wifi_online ? Color(64, 255, 64) : Color(255, 80, 80);
|
|
const char *wifi_icon = "\U000F092D"; // mdi:wifi-strength-off
|
|
if (wifi_online) {
|
|
if (id(wifisignal).has_state()) {
|
|
const float rssi = id(wifisignal).state;
|
|
wifi_icon = rssi >= -55 ? "\U000F0928" : rssi >= -67 ? "\U000F0925"
|
|
: rssi >= -75 ? "\U000F0922" : "\U000F091F";
|
|
} else {
|
|
wifi_icon = "\U000F091F";
|
|
}
|
|
}
|
|
it.printf(312, 8, id(font_icon), wifi_color, TextAlign::TOP_RIGHT, "%s", wifi_icon);
|
|
|
|
if (id(page_index) == 0) {
|
|
it.printf(12, 12, id(font_small), Color::WHITE, "Netzleistung");
|
|
if (id(grid_power).has_state()) {
|
|
it.printf(308, 32, id(font_value), Color::WHITE, TextAlign::TOP_RIGHT,
|
|
"%+.0f W", id(grid_power).state);
|
|
} else {
|
|
it.printf(308, 42, id(font_value), Color::WHITE, TextAlign::TOP_RIGHT,
|
|
"-- W");
|
|
}
|
|
|
|
it.printf(12, 99, id(font_small), Color::WHITE, "Balkonkraftwerk");
|
|
if (id(balcony_solar_power).has_state()) {
|
|
it.printf(308, 119, id(font_value), Color(255, 215, 0), TextAlign::TOP_RIGHT,
|
|
"%.0f W", id(balcony_solar_power).state);
|
|
} else {
|
|
it.printf(308, 129, id(font_value), Color(255, 215, 0), TextAlign::TOP_RIGHT,
|
|
"-- W");
|
|
}
|
|
} else {
|
|
it.printf(160, 45, id(font_title), Color::WHITE, TextAlign::TOP_CENTER,
|
|
"Weitere Seite");
|
|
it.printf(160, 95, id(font_small), Color::WHITE, TextAlign::TOP_CENTER,
|
|
"Für zusätzliche Werte vorbereitet");
|
|
}
|
|
|
|
// Labels correspond to the left (A) and right (C) hardware buttons.
|
|
it.printf(8, 239, id(font_small), Color::WHITE, TextAlign::BOTTOM_LEFT,
|
|
"< Zurück");
|
|
it.printf(312, 239, id(font_small), Color::WHITE, TextAlign::BOTTOM_RIGHT,
|
|
"Weiter >");
|
|
it.printf(160, 239, id(font_small), Color::WHITE, TextAlign::BOTTOM_CENTER,
|
|
"%d / 2", id(page_index) + 1);
|