various esphome changes

This commit is contained in:
root
2025-05-18 16:35:38 +12:00
parent e60f404d05
commit 0c3ba9cad8
36 changed files with 2813 additions and 356 deletions

View File

@@ -0,0 +1,21 @@
#############################################
# SYSTEM SPECIFIC VARIABLE SUBSTITUTIONS
#############################################
substitutions:
mqtt_server: !secret ha_mqtt_server
mqtt_username: !secret ha_mqtt_username
mqtt_password: !secret ha_mqtt_password
mqtt_topic: "esphome" #main topic for the mqtt server, call it what you like
#############################################
# MQTT Monitoring
# https://esphome.io/components/mqtt.html?highlight=mqtt
# MUST also have api enabled if you enable MQTT
#############################################
mqtt:
broker: ${mqtt_server}
topic_prefix: ${mqtt_topic}/${devicename}
username: ${mqtt_username}
password: ${mqtt_password}
discovery: false # enable entity discovery (true is default, we don't want two HA Instances)
id: mqtt_client

View File

@@ -0,0 +1,77 @@
substitutions:
local_gpioinvert: "True"
local_singleclick_duration: "300000" # 5 minutes in ms
# local_doubleclick_duration: "1800000" # 30 minutes in ms
# local_tripleclick_duration: "7200000" # 2 hours in ms
#globals:
# - id: single_click_delay
# type: long
# restore_value: no
# initial_value: ${local_singleclick_duration}
# - id: double_click_delay
# type: long
# restore_value: no
# initial_value: ${local_doubleclick_duration}
# - id: triple_click_delay
# type: long
# restore_value: no
# initial_value: ${local_tripleclick_duration}
binary_sensor:
- platform: gpio
pin:
number: ${local_gpio}
mode: INPUT
inverted: ${local_gpioinvert}
name: ${local_name}
on_multi_click:
# Single Click: one press (short press/release)
- timing:
- ON for at most 1s
- OFF for at least 0.5s
then:
- lambda: |-
if (id(Relay_3).state) {
ESP_LOGD("button3", "Single click: Relay_3 is on, turning it off.");
id(Relay_3).turn_off();
} else {
ESP_LOGD("button3", "Single click: Relay_3 is off, turning it on for %d ms.", id(single_click_delay));
id(Relay_3).turn_on();
delay(id(single_click_delay));
id(Relay_3).turn_off();
}
# # Double Click: two quick press/release cycles
# - timing:
# - ON for at most 1s
## - OFF for at most 1s
# - ON for at most 1s
# - OFF for at least 0.5s
# then:
# - lambda: |-
# ESP_LOGD(${local_gpio}, "Double click detected: turning ",${local_relay_id}," on for %d ms.", ${local_doubleclick_duration});
## ${local_relay_id}->turn_on();
# delay(${local_doubleclick_duration});
# ${local_relay_id}->turn_off();
# # Triple Click: three quick press/release cycles
## - timing:
# - ON for at most 1s
## - OFF for at most 1s
# - ON for at most 1s
# - OFF for at most 1s
# - ON for at most 1s
# - OFF for at least 0.5s
# then:
# - lambda: |-
# ESP_LOGD(${local_gpio}, "Triple click detected: turning ",${local_relay_id}," on for %d ms.", ${local_tripleclick_duration});
# ${local_relay_id}->turn_on();
# delay(${local_tripleclick_duration});
# ${local_relay_id}->turn_off();
# # Hold: button held for at least 4 seconds
# - timing:
# - ON for at least 4s
## then:
# - lambda: |-
# ESP_LOGD(${local_gpio}, "Hold detected: turning ",${local_relay_id}," on indefinitely.");
# ${local_relay_id}->turn_on();

View File

@@ -0,0 +1,75 @@
substitutions:
##############################################
# SPECIFIC DEVICE VARIABLE SUBSTITUTIONS
# If NOT using a secrets file, just replace these with the passwords etc (in quotes)
#############################################
wifi_ssid: !secret ha_wifi_ssid
wifi_password: !secret ha_wifi_password
fallback_ap_password: !secret fallback_ap_password
# 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. i.e. iot.home.lan (so device will appear as athom-smart-plug-v2.iot.home.lan in DNS/DHCP logs)
dns_domain: ".local"
# Automatically add the mac address to the name
# eg so you can use a single firmware for all devices
add_mac_suffix: "false"
# Add these if we are giving it a static ip, or remove them in the Wifi section
static_ip_subnet: !secret ha_wifi_subnet
static_ip_gateway: !secret ha_wifi_gateway
static_ip_dns1: !secret ha_wifi_gateway
#############################################
# Common Wifi Settings
# https://esphome.io/components/wifi.html
#
# Power Save mode (can reduce wifi reliability)
# NONE (least power saving, Default for ESP8266)
# LIGHT (Default for ESP32)
# HIGH (most power saving)
#############################################
wifi:
ssid: ${wifi_ssid}
password: ${wifi_password}
#power_save_mode: LIGHT # https://esphome.io/components/wifi.html#wifi-power-save-mode
manual_ip: # optional static IP address
static_ip: ${local_static_ip_address}
gateway: ${static_ip_gateway}
subnet: ${static_ip_subnet}
dns1: ${static_ip_dns1}
ap: # Details for fallback hotspot in case wifi connection fails https://esphome.io/components/wifi.html#access-point-mode
ssid: ${devicename} AP
password: ${fallback_ap_password}
ap_timeout: 30min # Time until it brings up fallback AP. default is 1min
# Allow rapid re-connection to previously connect WiFi SSID, skipping scan of all SSID
fast_connect: "${wifi_fast_connect}"
# Define dns domain / suffix to add to hostname
domain: "${dns_domain}"
captive_portal: # extra fallback mechanism for when connecting if the configured WiFi fails
#############################################
# Enable the Home Assistant API
# https://esphome.io/components/api.html
#############################################
api:
encryption:
key: ${local_api_key}
#############################################
# Enable Over the Air Update Capability
# https://esphome.io/components/ota.html?highlight=ota
#############################################
ota:
- platform: esphome
password: ${local_ota_pass}
#############################################
# Safe Mode
# Safe mode will detect boot loops
# https://esphome.io/components/safe_mode
#############################################
safe_mode:

View File

@@ -0,0 +1,76 @@
#substitutions:
# local_gpioinvert: "True"
# local_singleclick_duration: "300000" # 5 minutes in ms
# local_doubleclick_duration: "1800000" # 30 minutes in ms
# local_tripleclick_duration: "7200000" # 2 hours in ms
#globals:
# - id: single_click_delay
# type: long
# restore_value: no
# initial_value: ${local_singleclick_duration}
# - id: double_click_delay
# type: long
# restore_value: no
# initial_value: ${local_doubleclick_duration}
# - id: triple_click_delay
# type: long
# restore_value: no
# initial_value: ${local_tripleclick_duration}
binary_sensor:
- platform: gpio
pin:
number: ${local_gpio}
mode: INPUT
inverted: True
name: ${local_name}
on_multi_click:
# Single Click: one press (short press/release)
- timing:
- ON for at most 1s
- OFF for at least 0.5s
then:
- lambda: |-
if (id(local_relay_id).state) {
ESP_LOGD(id(local_gpio},"Single click: ",id(local_relay_id)," is on, turning it off.");
id(local_relay_id).turn_off();
} else {
ESP_LOGD(id(local_gpio), "Single click: ",id(local_relay_id)," is off, turning it on for %d ms.", id(local_singleclick_duraton));
id(local_relay_id).turn_on();
delay(id(local_singleclick_duration));
id(local_relay_id).turn_off();
}
# Double Click: two quick press/release cycles
- timing:
- ON for at most 1s
- OFF for at most 1s
- ON for at most 1s
- OFF for at least 0.5s
then:
- lambda: |-
ESP_LOGD(id(local_gpio), "Double click detected: turning ",id(local_relay_id)," on for %d ms.", id(local_doubleclick_duration));
id(local_relay_id).turn_on();
delay(id(local_doubleclick_duration));
id(local_relay_id).turn_off();
# Triple Click: three quick press/release cycles
- timing:
- ON for at most 1s
- OFF for at most 1s
- ON for at most 1s
- OFF for at most 1s
- ON for at most 1s
- OFF for at least 0.5s
then:
- lambda: |-
ESP_LOGD(id(local_gpio), "Triple click detected: turning ",id(local_relay_id)," on for %d ms.", id(local_tripleclick_duration));
id(local_relay_id).turn_on();
delay(id(local_tripleclick_duration));
id(local_relay_id).turn_off();
# Hold: button held for at least 4 seconds
- timing:
- ON for at least 4s
then:
- lambda: |-
ESP_LOGD(id(local_gpio), "Hold detected: turning ",id(local_relay_id)," on indefinitely.");
id(local_relay_id).turn_on();

View File

@@ -0,0 +1,76 @@
defaults:
local_gpioinvert: "True"
local_singleclick_duration: "300000" # 5 minutes in ms
local_doubleclick_duration: "1800000" # 30 minutes in ms
local_tripleclick_duration: "7200000" # 2 hours in ms
#globals:
# - id: single_click_delay
# type: long
# restore_value: no
# initial_value: ${local_singleclick_duration}
# - id: double_click_delay
# type: long
# restore_value: no
# initial_value: ${local_doubleclick_duration}
# - id: triple_click_delay
# type: long
# restore_value: no
# initial_value: ${local_tripleclick_duration}
binary_sensor:
- platform: gpio
pin:
number: ${local_gpio}
mode: INPUT
inverted: ${local_gpioinvert}
name: ${local_name}
on_multi_click:
# Single Click: one press (short press/release)
- timing:
- ON for at most 1s
- OFF for at least 0.5s
then:
- lambda: |-
if (id(${local_relay_id}).state) {
ESP_LOGD("${local_gpio}", "Single click: ${local_relay_id} is on, turning it off.");
id(${local_relay_id}).turn_off();
} else {
ESP_LOGD("${local_gpio}", "Single click: ${local_relay_id} is off, turning it on for %d ms.", id(single_click_delay));
id(${local_relay_id}).turn_on();
delay(id(single_click_delay));
id(${local_relay_id}).turn_off();
}
# Double Click: two quick press/release cycles
- timing:
- ON for at most 1s
- OFF for at most 1s
- ON for at most 1s
- OFF for at least 0.5s
then:
- lambda: |-
ESP_LOGD(${local_gpio}, "Double click detected: turning ",${local_relay_id}," on for %d ms.", id(double_click_delay));
id(${local_relay_id}).turn_on();
delay(id(double_click_delay));
id(${local_relay_id}).turn_off();
# Triple Click: three quick press/release cycles
- timing:
- ON for at most 1s
- OFF for at most 1s
- ON for at most 1s
- OFF for at most 1s
- ON for at most 1s
- OFF for at least 0.5s
then:
- lambda: |-
ESP_LOGD(${local_gpio}, "Triple click detected: turning ",${local_relay_id}," on for %d ms.", id(triple_click_delay));
id(${local_relay_id}).turn_on();
delay(id(triple_click_delay));
id(${local_relay_id}).turn_off();
# Hold: button held for at least 4 seconds
- timing:
- ON for at least 4s
then:
- lambda: |-
ESP_LOGD(${local_gpio}, "Hold detected (threshold %d ms): turning ",${local_relay_id}," on indefinitely.");
id(${local_relay_id}).turn_on();

View File

@@ -0,0 +1 @@
<<: !include ../secrets.yaml

View File

@@ -0,0 +1,96 @@
#############################################
# GENERAL COMMON SENSORS
# https://esphome.io/components/sensor/
#############################################
sensor:
- platform: uptime # Uptime for this device in seconds
name: "Uptime (s): ${local_friendly_name}"
update_interval: ${local_update_interval}
id: uptime_sensor
entity_category: "diagnostic"
- platform: wifi_signal # Wifi Strength
name: "Wifi dB: ${local_friendly_name}"
id: wifi_signal_db
update_interval: ${local_update_interval}
entity_category: "diagnostic"
- platform: copy # Reports the WiFi signal strength in %
source_id: wifi_signal_db
name: "WiFi Percent: ${local_friendly_name}"
filters:
- lambda: return min(max(2 * (x + 100.0), 0.0), 100.0);
unit_of_measurement: "% Max"
entity_category: "diagnostic"
device_class: ""
#############################################
# Text Sensors
# https://esphome.io/components/text_sensor/index.html
#############################################
text_sensor:
######################################################
# General ESPHome Info
######################################################
- platform: version
name: "Version: ${local_friendly_name}"
entity_category: "diagnostic"
- platform: wifi_info
ip_address:
name: "IP Address: ${local_friendly_name}"
- platform: uptime # Uptime for this device human readable
name: "Uptime: ${local_friendly_name}"
icon: mdi:clock-start
update_interval: ${local_update_interval}
entity_category: "diagnostic"
######################################################
# Creates a sensor showing when the device was last restarted
# Uptime template sensor, and SNTP are needed
######################################################
#- platform: template
# name: ${local_friendly_name} Last Restart
# id: device_last_restart
# icon: mdi:clock
# entity_category: diagnostic
# #device_class: timestamp
######################################################
# Creates a sensor of the uptime of the device, in formatted days, hours, minutes and seconds
######################################################
#- platform: template
# name: "Uptime"
# entity_category: diagnostic
# lambda: |-
# int seconds = (id(uptime_sensor).state);
# int days = seconds / (24 * 3600);
# seconds = seconds % (24 * 3600);
# int hours = seconds / 3600;
# seconds = seconds % 3600;
# int minutes = seconds / 60;
# seconds = seconds % 60;
# if ( days > 3650 ) {
# return { "Starting up" };
# } else if ( days ) {
# return { (String(days) +"d " + String(hours) +"h " + String(minutes) +"m "+ String(seconds) +"s").c_str() };
# } else if ( hours ) {
# return { (String(hours) +"h " + String(minutes) +"m "+ String(seconds) +"s").c_str() };
# } else if ( minutes ) {
# return { (String(minutes) +"m "+ String(seconds) +"s").c_str() };
# } else {
# return { (String(seconds) +"s").c_str() };
# }
# icon: mdi:clock-start
button:
- platform: safe_mode
name: "Safe Mode Restart: ${local_friendly_name}"
entity_category: "diagnostic"
- platform: restart
name: "Restart: ${local_friendly_name}"
entity_category: "diagnostic"
disabled_by_default: true
- platform: factory_reset
name: "FACTORY RESET: ${local_friendly_name}"
entity_category: "diagnostic"
disabled_by_default: true