175 lines
3.6 KiB
YAML
175 lines
3.6 KiB
YAML
|
|
|
|
substitutions:
|
|
device_name: utilities2
|
|
friendly_name: um2
|
|
esphome:
|
|
name: ${device_name}
|
|
project:
|
|
name: d1.utilities-meter
|
|
version: "1.0.0"
|
|
name_add_mac_suffix: true
|
|
|
|
esp8266:
|
|
board: esp01_1m
|
|
restore_from_flash: true
|
|
|
|
|
|
# Enable logging
|
|
logger:
|
|
|
|
# Enable Home Assistant API
|
|
api:
|
|
encryption:
|
|
key: !secret api_encryption_key
|
|
reboot_timeout: 30min
|
|
|
|
wifi:
|
|
ssid: !secret wifi_ssid
|
|
password: !secret wifi_password
|
|
manual_ip:
|
|
static_ip: 192.168.1.171
|
|
gateway: 192.168.1.254
|
|
subnet: 255.255.255.0
|
|
dns1: 192.168.1.1
|
|
# Enable fallback hotspot (captive portal) in case wifi connection fails
|
|
ap:
|
|
ssid: !secret ap_ssid
|
|
password: !secret ap_password
|
|
|
|
captive_portal:
|
|
|
|
web_server:
|
|
port: 80
|
|
ota:
|
|
- platform: !secret ota_platform
|
|
password: !secret ota_password
|
|
|
|
status_led:
|
|
pin:
|
|
number: GPIO02
|
|
inverted: true
|
|
time:
|
|
- platform: sntp
|
|
id: sntp_time
|
|
|
|
i2c:
|
|
sda: GPIO04
|
|
scl: GPIO05
|
|
scan: true
|
|
id: bus_a
|
|
frequency: 400kHz
|
|
# Display configuration (SSD1306 128x64 OLED)
|
|
display:
|
|
- platform: ssd1306_i2c
|
|
model: "SH1106 128x32"
|
|
address: 0x3C
|
|
id: my_display
|
|
update_interval: 0.5s
|
|
pages:
|
|
- id: page1
|
|
lambda: |-
|
|
it.printf(0, 0, id(fontPPT), "oled_on: %.0f", id(oled_on));
|
|
- id: page2
|
|
lambda: |-
|
|
it.printf(0, 0, id(fontPPT), "Page 2: Menu 2");
|
|
- id: page3
|
|
lambda: |-
|
|
it.printf(0, 0, id(fontPPT), "Page 3: Menu 3");
|
|
# Button configuration
|
|
binary_sensor:
|
|
- platform: gpio
|
|
pin:
|
|
number: GPIO013
|
|
mode: INPUT_PULLUP
|
|
inverted: false
|
|
name: "Menu Button"
|
|
on_press:
|
|
- logger.log: "Button pressed"
|
|
- script.execute: reset_oled_timeout
|
|
filters:
|
|
- delayed_on: 30ms
|
|
- delayed_off: 30ms
|
|
light:
|
|
- platform: monochromatic
|
|
name: displayBL
|
|
id: displayBL
|
|
output: my_display1
|
|
# restore_mode: ALWAYS_ON
|
|
initial_state:
|
|
state: true
|
|
on_turn_on:
|
|
- logger.log:
|
|
format: "Display On begin: %d"
|
|
args: [ 'id(oled_on)' ]
|
|
# - lambda: id(my_display).turn_on();
|
|
- script.execute: reset_oled_timeout
|
|
|
|
on_turn_off:
|
|
then:
|
|
- logger.log:
|
|
format: "Display Off: %d"
|
|
args: [ 'id(oled_on)' ]
|
|
- lambda: id(my_display).turn_off();
|
|
globals:
|
|
- id: oled_on
|
|
type: bool
|
|
restore_value: no
|
|
initial_value: "true"
|
|
|
|
interval:
|
|
- interval: 1s
|
|
then:
|
|
- if:
|
|
condition:
|
|
- not:
|
|
- script.is_running: oled_timeout
|
|
then:
|
|
- script.execute: oled_timeout
|
|
|
|
script:
|
|
- id: reset_oled_timeout
|
|
then:
|
|
- lambda: |-
|
|
id(oled_on) = true;
|
|
- light.turn_on: displayBL #synchronize the button in HA
|
|
- lambda: id(my_display).turn_on();
|
|
- script.stop: oled_timeout
|
|
- script.execute: oled_timeout
|
|
|
|
- id: oled_timeout
|
|
mode: restart
|
|
then:
|
|
- delay: 5s
|
|
- lambda: |-
|
|
id(oled_on) = false;
|
|
# id(displayBL).publish_state(false);
|
|
- lambda: id(my_display).turn_off();
|
|
- light.turn_off: displayBL #synchronize the button in HA
|
|
|
|
output:
|
|
- platform: template
|
|
id: my_display1
|
|
type: float
|
|
write_action:
|
|
then:
|
|
- lambda: id(my_display).set_contrast(state);
|
|
|
|
text_sensor:
|
|
- platform: wifi_info
|
|
ip_address:
|
|
name: "IP Address"
|
|
ssid:
|
|
name: "WiFi SSID"
|
|
bssid:
|
|
name: "WiFi BSSID"
|
|
|
|
- platform: version
|
|
name: "ESPHome Version"
|
|
hide_timestamp: false
|
|
|
|
# Font for display
|
|
font:
|
|
- file: "fonts/Helvetica.ttf" # You'll need to upload this font file
|
|
id: fontPPT
|
|
size: 10 |