configs/sthome-ut9.yaml

128 lines
2.9 KiB
YAML

packages:
- !include common/wifi.yaml
- !include common/canbus.yaml
- !include common/felicityinverter.yaml
substitutions:
name: sthome-ut9
friendly_name: "sthome-ut9"
esphome:
name: "${name}"
friendly_name: "${friendly_name}"
esp32:
# board: nodemcu-32s
board: esp32dev
framework:
#type: arduino
type: esp-idf
debug:
update_interval: 5s
# Enable logging
logger:
level: DEBUG
logs:
canbus: INFO
# Enable Home Assistant API
api:
encryption:
key: "LI7j37zs9HsWNsUZ5c83leThmhHsgIVReAPoc9U6pVU="
ota:
- platform: esphome
password: "8ebd5bcefbdc833a5f6ddc4e8ba56e39"
wifi:
power_save_mode: none # stops display flickering
manual_ip:
static_ip: 10.0.2.9
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "${name} Fallback Hotspot"
password: "iZxjpw7ucRs4"
captive_portal:
uart:
- id: sth_uart
rx_pin: GPIO15
tx_pin: GPIO16
baud_rate: 2400
stop_bits: 1
parity: NONE
debug:
direction: BOTH
dummy_receiver: true
after:
delimiter: "\r"
sequence:
- lambda: UARTDebug::log_hex(direction, bytes, ',');
interval:
# - interval: 10s
# then:
# - lambda: |-
# id(canbus_send_heartbeat).execute();
- interval: 3.14s
then:
- uart.write:
data: "sthome9 heartbeat\r\n"
sun:
id: sun_sensor
latitude: !secret latitude
longitude: !secret longitude
time:
- platform: homeassistant
text_sensor:
- platform: debug
device:
name: "Device Info"
reset_reason:
name: "Reset Reason"
# human readable update text sensor from sensor:uptime
- platform: template
name: Uptime
id: uptime_human
icon: mdi:clock-start
switch:
- platform: restart
name: "${name} Restart"
id: "restart_switch"
sensor:
# human readable uptime sensor output to the text sensor above
- platform: uptime
name: Uptime in Days
id: uptime_sensor_days
update_interval: 10s
on_raw_value:
then:
- text_sensor.template.publish:
id: uptime_human
state: !lambda |-
int seconds = round(id(uptime_sensor_days).raw_state);
int days = seconds / (24 * 3600);
seconds = seconds % (24 * 3600);
int hours = seconds / 3600;
seconds = seconds % 3600;
int minutes = seconds / 60;
seconds = seconds % 60;
auto days_str = std::to_string(days);
auto hours_str = std::to_string(hours);
auto minutes_str = std::to_string(minutes);
auto seconds_str = std::to_string(seconds);
return (
(days ? days_str + "d " : "") +
(hours ? hours_str + "h " : "") +
(minutes ? minutes_str + "m " : "") +
(seconds_str + "s")
).c_str();