Files
2026-06-22 22:40:52 +12:00

141 lines
5.2 KiB
YAML

#:########################################################################################:#
# TITLE: COMMON NETWORK DHCP
# zorruno.com layout v1.1 2026
#:########################################################################################:#
# PURPOSE:
# Common ESPHome WiFi/network package using DHCP instead of static IP.
#
# Intended for portable or standalone devices where the WiFi network may change.
#:########################################################################################:#
# OPERATION NOTES:
# - Uses configured WiFi SSID/password from secrets for normal operation.
# - Uses DHCP, not static IP.
# - If configured WiFi fails, fallback AP starts after fallback_ap_timeout.
# - Captive portal allows WiFi settings to be manually overridden.
# - Captive portal WiFi changes should also be copied back into YAML later if permanent.
#:########################################################################################:#
#:########################################################################################:#
# SUBSTITUTIONS:
# Common network variable substitutions
#:########################################################################################:#
substitutions:
# WiFi Credentials
wifi_ssid: !secret ha_wifi_ssid
wifi_password: !secret ha_wifi_password
#fallback_ap_password: !secret fallback_ap_password
fallback_ap_password: !secret fallback_ap_password_shared
# Enables faster network connections, with last connected SSID being connected to and no full scan for SSID being undertaken
wifi_fast_connect: "false"
# Define a domain for this device to use
dns_domain: ".local"
# Enable or disable the use of IPv6 networking on the device
ipv6_enable: "false"
# Fallback AP Timing
fallback_ap_timeout: "2min"
# Network reconnect every x hours to ensure best access point
#base_interval_hours: "23"
#random_offset_max_minutes: "59"
#:########################################################################################:#
# WIFI:
# DHCP WiFi configuration with fallback AP and captive portal
# https://esphome.io/components/wifi.html
#:########################################################################################:#
wifi:
ssid: ${wifi_ssid}
password: ${wifi_password}
# Power Save mode can reduce WiFi reliability
power_save_mode: none
# Fallback hotspot in case configured WiFi connection fails
ap:
ssid: "${local_device_name}"
password: ${fallback_ap_password}
ap_timeout: ${fallback_ap_timeout}
# Allow rapid re-connection to previously connected WiFi SSID, skipping scan of all SSIDs
fast_connect: ${wifi_fast_connect}
# Define DNS domain / suffix to add to hostname
domain: ${dns_domain}
min_auth_mode: WPA2
# Reboot eventually when WiFi is down
reboot_timeout: 56h
#:########################################################################################:#
# CAPTIVE PORTAL:
# Fallback mechanism for changing WiFi if the configured WiFi fails
# https://esphome.io/components/captive_portal.html
#:########################################################################################:#
captive_portal:
#:########################################################################################:#
# OTA:
# Enable Over the Air update capability
# https://esphome.io/components/ota.html
#:########################################################################################:#
ota:
- platform: esphome
password: ${local_ota_pass}
version: 2
# Optional: uncomment if you want OTA uploads through the web interface
- platform: web_server
#:########################################################################################:#
# SAFE MODE:
# Safe mode will detect boot loops
# https://esphome.io/components/safe_mode
#:########################################################################################:#
safe_mode:
#:########################################################################################:#
# NETWORK:
# Global configuration for all types of networks
# https://esphome.io/components/network.html
#:########################################################################################:#
network:
enable_ipv6: ${ipv6_enable}
#:########################################################################################:#
# INTERVAL:
# Optional network reconnect every x hours + random minutes
#:########################################################################################:#
#script:
# - id: random_reconnect
# mode: restart
# then:
# - lambda: |-
# // Compute total delay: base hours + random offset minutes
# uint32_t extra;
# #if defined(ESP32)
# extra = esp_random() % (${random_offset_max_minutes} + 1);
# #elif defined(ESP8266)
# extra = os_random() % (${random_offset_max_minutes} + 1);
# #else
# extra = esp_random() % (${random_offset_max_minutes} + 1);
# #endif
# uint32_t total_s = ${base_interval_hours} * 3600 + extra * 60;
# ESP_LOGI("random_reconnect", "Next reconnect in %u seconds", total_s);
# delay(total_s * 1000);
# - logger.log: "network_check: performing reconnect"
# - wifi.disable: {}
# - delay: 1s
# - wifi.enable: {}
# - script.execute: random_reconnect