193 lines
7.2 KiB
YAML
193 lines
7.2 KiB
YAML
#############################################
|
|
#############################################
|
|
# OFFICE ELV CONTROL
|
|
# Controlled by a Sonoff Basic R1
|
|
#
|
|
# V1.0 2025-06-14 Initial Version
|
|
#
|
|
##########################################################################################
|
|
##########################################################################################
|
|
|
|
##########################################################################################
|
|
# SPECIFIC DEVICE VARIABLE SUBSTITUTIONS
|
|
# If NOT using a secrets file, just replace these with the passwords etc (in quotes)
|
|
##########################################################################################
|
|
substitutions:
|
|
# Device Naming
|
|
device_name: "esp-officeelvcontrol"
|
|
friendly_name: "Office ELV Control"
|
|
mqtt_device_name: "office-elv-control"
|
|
description_comment: "ELV Power Supply control in the Office (under desk) :: Sonoff Basic"
|
|
device_area: "Office" # Allows ESP device to be automatically linked to an 'Area' in Home Assistant.
|
|
|
|
# Project Naming
|
|
project_name: "Sonoff Technologies.Sonoff Basic V1" # Project Details
|
|
project_version: "v1.0" # Project V denotes release of yaml file, allowing checking of deployed vs latest version
|
|
|
|
# Passwords
|
|
api_key: !secret esp-api_key # unfortunately you can't use substitutions inside secrets names
|
|
ota_pass: !secret esp-ota_pass # unfortunately you can't use substitutions inside secrets names
|
|
static_ip_address: !secret esp-officeelvcontrol_ip
|
|
mqtt_main_command_topic: !secret mqtt_main_command_topic
|
|
|
|
# Device Settings
|
|
relay_icon: "mdi:generator-portable"
|
|
log_level: "ERROR" # Define logging level: NONE, ERROR, WARN, INFO, DEBUG (Default), VERBOSE, VERY_VERBOSE
|
|
update_interval: "60s" # update time for for general sensors etc
|
|
|
|
# MQTT Controls
|
|
mqtt_command_topic: "${mqtt_main_command_topic}/${mqtt_device_name}/operation" # Topic we will use to command stuff from external withougt HA
|
|
#mqtt_status_topic: "${mqtt_main_status_topic}/esphome/${device_name}" # Topic we will use to read stuff from external withougt HA
|
|
#mqtt_main_status_topic: !secret mqtt_main_status_topic
|
|
#mqtt_remote_device1_command_topic: "${mqtt_main_command_topic}/masterbath-towelrail/operation"
|
|
#mqtt_remote_device1_command1: "BOOST"
|
|
|
|
##########################################################################################
|
|
# PACKAGES: Included Common Packages
|
|
# https://esphome.io/components/esphome.html
|
|
##########################################################################################
|
|
packages:
|
|
common_wifi: !include
|
|
file: common/network_common.yaml
|
|
vars:
|
|
local_static_ip_address: "${static_ip_address}"
|
|
local_ota_pass: "${ota_pass}"
|
|
common_api: !include
|
|
file: common/api_common.yaml
|
|
vars:
|
|
local_api_key: "${api_key}"
|
|
#common_webportal: !include
|
|
# file: common/webportal_common.yaml
|
|
common_mqtt: !include
|
|
file: common/mqtt_common.yaml
|
|
common_sntp: !include
|
|
file: common/sntp_common.yaml
|
|
common_general_sensors: !include
|
|
file: common/sensors_common.yaml
|
|
vars:
|
|
local_friendly_name: "${friendly_name}"
|
|
local_update_interval: "${update_interval}"
|
|
|
|
##########################################################################################
|
|
# ESPHome
|
|
# https://esphome.io/components/esphome.html
|
|
##########################################################################################
|
|
esphome:
|
|
name: "${device_name}"
|
|
friendly_name: "${friendly_name}"
|
|
comment: "${description_comment}" # Appears on the esphome page in HA
|
|
area: "${device_area}"
|
|
# platformio_options:
|
|
# build_flags:
|
|
# - "-Os" # optimize for size
|
|
# - "-Wl,--gc-sections" # drop unused code/data
|
|
# - "-fno-exceptions" # strip C++ exceptions
|
|
# - "-fno-rtti" # strip C++ RTTI
|
|
|
|
|
|
##########################################################################################
|
|
# ESP Platform and Framework
|
|
# https://esphome.io/components/esp32.html
|
|
##########################################################################################
|
|
esp8266:
|
|
board: esp01_1m # The original sonoff basic
|
|
restore_from_flash: True # restore some values on reboot
|
|
|
|
preferences:
|
|
flash_write_interval: 5min
|
|
|
|
mdns:
|
|
disabled: False
|
|
|
|
##########################################################################################
|
|
# ESPHome Logging Enable
|
|
# https://esphome.io/components/logger.html
|
|
##########################################################################################
|
|
logger:
|
|
level: "${log_level}" #INFO Level suggested, or DEBUG for testing
|
|
baud_rate: 0 # set to 0 for no logging via UART, needed if you are using it for other serial things (eg PZEM)
|
|
#esp8266_store_log_strings_in_flash: false
|
|
#tx_buffer_size: 64
|
|
|
|
##########################################################################################
|
|
# SWITCH COMPONENT
|
|
# https://esphome.io/components/switch/
|
|
##########################################################################################
|
|
# Sonoff Basic R1 Relay Switch is GPIO12
|
|
#############################################
|
|
switch:
|
|
- platform: gpio
|
|
name: "ELV Power Supply"
|
|
pin: GPIO12
|
|
id: relay
|
|
restore_mode: RESTORE_DEFAULT_OFF
|
|
icon: "${relay_icon}"
|
|
|
|
##########################################################################################
|
|
# BINARY SENSORS
|
|
# https://esphome.io/components/binary_sensor/
|
|
##########################################################################################
|
|
# Sonoff Basic R1 Button is GPIO03
|
|
#############################################
|
|
binary_sensor:
|
|
|
|
- platform: gpio
|
|
pin:
|
|
number: GPIO03
|
|
mode: INPUT_PULLUP
|
|
inverted: true
|
|
name: "Power Button"
|
|
id: power_button
|
|
filters:
|
|
- delayed_on: 20ms
|
|
on_click:
|
|
- min_length: 20ms
|
|
max_length: 500ms
|
|
then:
|
|
- lambda: |-
|
|
if (id(relay).state) {
|
|
// Relay is ON: turn it OFF
|
|
id(relay).turn_off();
|
|
} else {
|
|
// Relay is OFF: turn it ON
|
|
id(relay).turn_on();
|
|
}
|
|
|
|
# Mimics actual relay status (but not controllable)
|
|
- platform: template
|
|
name: "Relay Status"
|
|
lambda: |-
|
|
return id(relay).state;
|
|
|
|
##########################################################################################
|
|
# STATUS LED
|
|
# https://esphome.io/components/status_led.html
|
|
##########################################################################################
|
|
# Sonoff Basic R1 LED is GPIO13
|
|
#############################################
|
|
status_led:
|
|
pin:
|
|
number: GPIO13
|
|
inverted: yes
|
|
|
|
##########################################################################################
|
|
# Text Sensors
|
|
# https://esphome.io/components/text_sensor/index.html
|
|
##########################################################################################
|
|
text_sensor:
|
|
- platform: mqtt_subscribe
|
|
name: "Office ELV MQTT Command"
|
|
id: office_elv_cmd
|
|
topic: "${mqtt_command_topic}"
|
|
internal: true # hide from HA
|
|
on_value:
|
|
then:
|
|
- lambda: |-
|
|
// payload is x (std::string)
|
|
if (x == "ON") {
|
|
id(relay).turn_on();
|
|
} else if (x == "OFF") {
|
|
id(relay).turn_off();
|
|
}
|
|
|