esphome downstairs bath lightswitch

This commit is contained in:
root
2025-03-03 22:30:15 +13:00
parent b152961ae1
commit e60f404d05

View File

@@ -1,23 +1,14 @@
############################################# #############################################
############################################# #############################################
# MASTER BATHROOM HEATED TOWEL RAIL # DOWNSTAIRS BATHROOM MAIN LIGHTSWITCH
# Controlled by a Sonoff Basic # Zemismart KS-811 Triple push button
# #
# V1.0 2025-02-14 Initial Version # V1.0 2025-02-14 Initial Version
# #
# pinout/schematic https://community.home-assistant.io/t/zemismart-ks-811-working-with-esphome/
#
# INSTRUCTIONS # INSTRUCTIONS
# - It allows a heated towel rail device to work in a standalone operation # -
# - On startup, it will turn on for 2 hours then go into timer mode (this allows you to just turn it on to get some heat immediately)
# - The timer has a morning and evening time (but no weekday/weekend setting)
# - Default values are 5am-7am and 9pm-Midnight (as this suits our use case)
# - It uses SNTP for time setting (but obviously only if wifi & networking are working)
# - It will default to an internal timer if no wifi. To reset internal timer, reboot the device at 12pm (noon)
# - If on a network and there is a MQTT server, you can set the 4 on/off times via MQTT (See below commands)
# - You can set 4 modes ON/OFF/TIMER/STARTUP via MQTT
# - Any new timer times set via MQTT will be remembered though a reboot
# - On a reboot, the device will always turn on for the Startup Duration (STARTUP mode, default 2 hours)
# - TIMER mode will always be switched on after startup mode is complete
# - If you need it ON continuously with no MQTT, toggle power ON/OFF 4 times within 20 seconds (with ~2 secs in between to allow it to boot)
# #
# MQTT Commands # MQTT Commands
# Values will be set in place on the update_interval time, not immediately # Values will be set in place on the update_interval time, not immediately
@@ -34,32 +25,35 @@
############################################# #############################################
############################################# #############################################
#############################################
# VARIABLE SUBSTITUTIONS
# Give the device a useful name & description here
# and change values accordingly.
#############################################
substitutions: substitutions:
#############################################
# SPECIFIC DEVICE VARIABLE SUBSTITUTIONS
# If NOT using a secrets file, just replace these with the passwords etc (in quotes)
#############################################
devicename: "esp-downstbathswitch"
friendly_name: "Downstairs Bath Lightswitch"
description_comment: "Downstairs Bathroom Main Lightswitch using a Zemismart KS-811 Triple Push Button. Main Light (1), Cabinet Light (2), Extract Fan (3)"
api_key: !secret esp-downstbathswitch_api_key # unfortunately you can't use substitutions inside secrets names
ota_pass: !secret esp-downstbathswitch_ota_pass # unfortunately you can't use substitutions inside secrets names
static_ip_address: !secret esp-downstbathswitch_ip
#mqtt_timer_topic: "viewroad-commands/masterbath-towelrail" # Topics you will use to change stuff #mqtt_timer_topic: "viewroad-commands/masterbath-towelrail" # Topics you will use to change stuff
#startup_duration: "120" # Minutes to stay ON in STARTUP mode before reverting to TIMER #startup_duration: "120" # Minutes to stay ON in STARTUP mode before reverting to TIMER
#timezone: "Pacific/Auckland" # For setting clock with snmp #timezone: "Pacific/Auckland" # For setting clock with snmp
devicename: "esp-downstbathswitch"
friendly_name: "Downstairs Bath Lightswitch"
description_comment: "esp-downstbathswitch"
# If NOT using a secrets file, just replace these with the passwords etc (in quotes) #############################################
api_key: !secret esp-downstbathswitch_api_key # unfortunately you can't use substitutions inside secrets names # MY SYSTEM VARIABLE SUBSTITUTIONS
ota_pass: !secret esp-downstbathswitch_ota_pass # unfortunately you can't use substitutions inside secrets names #############################################
wifi_ssid: !secret ha_wifi_ssid wifi_ssid: !secret ha_wifi_ssid
wifi_password: !secret ha_wifi_password wifi_password: !secret ha_wifi_password
fallback_ap_password: !secret fallback_ap_password fallback_ap_password: !secret fallback_ap_password
# Add these if we are giving it a static ip, or remove them in the Wifi section # Add these if we are giving it a static ip, or remove them in the Wifi section
static_ip_address: !secret esp-downstbathswitch_ip static_ip_subnet: !secret ha_wifi_subnet
static_ip_gateway: !secret ha_gateway static_ip_gateway: !secret ha_wifi_gateway
static_ip_subnet: !secret ha_subnet
mqtt_server: !secret ha_mqtt_server mqtt_server: !secret ha_mqtt_server
mqtt_username: !secret ha_mqtt_username mqtt_username: !secret ha_mqtt_username
@@ -73,6 +67,7 @@ substitutions:
update_interval: 60s # update time for for general sensors etc update_interval: 60s # update time for for general sensors etc
############################################# #############################################
# ESPHome # ESPHome
# https://esphome.io/components/esphome.html # https://esphome.io/components/esphome.html
@@ -80,7 +75,7 @@ substitutions:
esphome: esphome:
name: ${devicename} name: ${devicename}
friendly_name: ${friendly_name} friendly_name: ${friendly_name}
comment: ${description_comment} #a ppears on the esphome page in HA comment: ${description_comment} #Appears on the esphome page in HA
############################################# #############################################
@@ -150,7 +145,7 @@ captive_portal: # extra fallback mechanism for when connecting if the configure
############################################# #############################################
# Real time clock time source for ESPHome # Real time clock time source for ESPHome
# If it's invalid, we fall back to an internal clock # If it's invalid, we fall back to an internal clock
# https://esphome.io/components/time/index.html # https://esphome.io/components/time/
# https://esphome.io/components/time/sntp # https://esphome.io/components/time/sntp
############################################# #############################################
time: time:
@@ -177,14 +172,10 @@ mqtt:
#globals: #globals:
############################################# #############################################
# Text Sensors # TEXT SENSORS
# https://esphome.io/components/text_sensor/index.html # https://esphome.io/components/text_sensor/
############################################# #############################################
text_sensor: text_sensor:
######################################################
# ESPHome Info
######################################################
- platform: version - platform: version
name: ${friendly_name} Version name: ${friendly_name} Version
- platform: wifi_info - platform: wifi_info
@@ -192,21 +183,18 @@ text_sensor:
name: ${friendly_name} IP Address name: ${friendly_name} IP Address
############################################# #############################################
# General Sensors # STATUS LED
# https://esphome.io/components/sensor/index.html # https://esphome.io/components/status_led.html
############################################# #############################################
sensor: status_led:
- platform: uptime # Uptime for this device pin:
name: ${friendly_name} Uptime number: GPIO2
update_interval: ${update_interval} inverted: yes
- platform: wifi_signal # Wifi Strength
name: ${friendly_name} Wifi Signal
update_interval: ${update_interval}
# for pinout/schematic
# https://community.home-assistant.io/t/zemismart-ks-811-working-with-esphome/
#############################################
# BINARY SENSORS
# https://esphome.io/components/binary_sensor/
#############################################
binary_sensor: binary_sensor:
- platform: gpio - platform: gpio
pin: pin:
@@ -215,7 +203,7 @@ binary_sensor:
inverted: True inverted: True
name: "Light Switch 1 (Main)" name: "Light Switch 1 (Main)"
on_press: on_press:
- switch.toggle: load1 - switch.toggle: Relay_1
- platform: gpio - platform: gpio
pin: pin:
number: GPIO05 number: GPIO05
@@ -223,7 +211,7 @@ binary_sensor:
inverted: True inverted: True
name: "Light Switch 2 (Cabinet)" name: "Light Switch 2 (Cabinet)"
on_press: on_press:
- switch.toggle: load2 - switch.toggle: Relay_2
- platform: gpio - platform: gpio
pin: pin:
number: GPIO04 number: GPIO04
@@ -231,35 +219,46 @@ binary_sensor:
inverted: True inverted: True
name: "Extract Fan" name: "Extract Fan"
on_press: on_press:
- switch.toggle: load2 - switch.toggle: Relay_3
#############################################
# SWITCH COMPONENT
# https://esphome.io/components/switch/
#############################################
switch: switch:
- platform: gpio - platform: gpio
name: "DS Bathroom Top" name: "Main Light"
pin: GPIO13 pin: GPIO13
id: load1 id: Relay_1
- platform: gpio - platform: gpio
name: "DS Bathroom Bottom" name: "Cabinet Light"
pin: GPIO12 pin: GPIO12
id: load2 id: Relay_2
- platform: gpio - platform: gpio
name: "DS Bathroom Bottom" name: "Extract Fan"
pin: GPIO14 pin: GPIO14
id: load2 id: Relay_3
status_led:
pin:
number: GPIO2
inverted: yes
#############################################
# GENERAL SENSORS
# https://esphome.io/components/sensor/
#############################################
sensor: sensor:
- platform: wifi_signal - platform: uptime # Uptime for this device
name: "DS Bathroom WiFi signal" name: ${friendly_name} Uptime
update_interval: 60s update_interval: ${update_interval}
entity_category: "diagnostic"
- platform: wifi_signal # Wifi Strength
name: ${friendly_name} Wifi Signal dB
id: wifi_signal_db
update_interval: ${update_interval}
entity_category: "diagnostic"
- platform: copy # Reports the WiFi signal strength in %
source_id: wifi_signal_db
name: ${friendly_name} WiFi Signal Percent
filters:
- lambda: return min(max(2 * (x + 100.0), 0.0), 100.0);
unit_of_measurement: "Signal %"
entity_category: "diagnostic"
device_class: ""
- platform: uptime
name: "DS Bathroom uptime"
text_sensor:
- platform: version
name: "DS Bathroom ESPHome version"