From e60f404d05d1f90c7980eb1f53f616997fd0d142 Mon Sep 17 00:00:00 2001 From: root Date: Mon, 3 Mar 2025 22:30:15 +1300 Subject: [PATCH] esphome downstairs bath lightswitch --- esphome/esp-downstbathswitch.yaml | 143 +++++++++++++++--------------- 1 file changed, 71 insertions(+), 72 deletions(-) diff --git a/esphome/esp-downstbathswitch.yaml b/esphome/esp-downstbathswitch.yaml index 1ae40d7..6f278f9 100644 --- a/esphome/esp-downstbathswitch.yaml +++ b/esphome/esp-downstbathswitch.yaml @@ -1,23 +1,14 @@ ############################################# ############################################# -# MASTER BATHROOM HEATED TOWEL RAIL -# Controlled by a Sonoff Basic +# DOWNSTAIRS BATHROOM MAIN LIGHTSWITCH +# Zemismart KS-811 Triple push button # # V1.0 2025-02-14 Initial Version # +# pinout/schematic https://community.home-assistant.io/t/zemismart-ks-811-working-with-esphome/ +# # 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 # 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: + + ############################################# + # 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 #startup_duration: "120" # Minutes to stay ON in STARTUP mode before reverting to TIMER #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 - ota_pass: !secret esp-downstbathswitch_ota_pass # unfortunately you can't use substitutions inside secrets names +############################################# +# MY SYSTEM VARIABLE SUBSTITUTIONS +############################################# wifi_ssid: !secret ha_wifi_ssid wifi_password: !secret ha_wifi_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 - static_ip_address: !secret esp-downstbathswitch_ip - static_ip_gateway: !secret ha_gateway - static_ip_subnet: !secret ha_subnet + static_ip_subnet: !secret ha_wifi_subnet + static_ip_gateway: !secret ha_wifi_gateway mqtt_server: !secret ha_mqtt_server mqtt_username: !secret ha_mqtt_username @@ -73,6 +67,7 @@ substitutions: update_interval: 60s # update time for for general sensors etc + ############################################# # ESPHome # https://esphome.io/components/esphome.html @@ -80,7 +75,7 @@ substitutions: esphome: name: ${devicename} 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 # 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 ############################################# time: @@ -177,14 +172,10 @@ mqtt: #globals: ############################################# -# Text Sensors -# https://esphome.io/components/text_sensor/index.html +# TEXT SENSORS +# https://esphome.io/components/text_sensor/ ############################################# text_sensor: - - ###################################################### - # ESPHome Info - ###################################################### - platform: version name: ${friendly_name} Version - platform: wifi_info @@ -192,21 +183,18 @@ text_sensor: name: ${friendly_name} IP Address ############################################# -# General Sensors -# https://esphome.io/components/sensor/index.html +# STATUS LED +# https://esphome.io/components/status_led.html ############################################# -sensor: - - platform: uptime # Uptime for this device - name: ${friendly_name} Uptime - update_interval: ${update_interval} - - 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/ +status_led: + pin: + number: GPIO2 + inverted: yes +############################################# +# BINARY SENSORS +# https://esphome.io/components/binary_sensor/ +############################################# binary_sensor: - platform: gpio pin: @@ -215,7 +203,7 @@ binary_sensor: inverted: True name: "Light Switch 1 (Main)" on_press: - - switch.toggle: load1 + - switch.toggle: Relay_1 - platform: gpio pin: number: GPIO05 @@ -223,7 +211,7 @@ binary_sensor: inverted: True name: "Light Switch 2 (Cabinet)" on_press: - - switch.toggle: load2 + - switch.toggle: Relay_2 - platform: gpio pin: number: GPIO04 @@ -231,35 +219,46 @@ binary_sensor: inverted: True name: "Extract Fan" on_press: - - switch.toggle: load2 + - switch.toggle: Relay_3 +############################################# +# SWITCH COMPONENT +# https://esphome.io/components/switch/ +############################################# switch: - platform: gpio - name: "DS Bathroom Top" + name: "Main Light" pin: GPIO13 - id: load1 + id: Relay_1 - platform: gpio - name: "DS Bathroom Bottom" + name: "Cabinet Light" pin: GPIO12 - id: load2 + id: Relay_2 - platform: gpio - name: "DS Bathroom Bottom" + name: "Extract Fan" pin: GPIO14 - id: load2 - -status_led: - pin: - number: GPIO2 - inverted: yes + id: Relay_3 +############################################# +# GENERAL SENSORS +# https://esphome.io/components/sensor/ +############################################# sensor: - - platform: wifi_signal - name: "DS Bathroom WiFi signal" - update_interval: 60s + - platform: uptime # Uptime for this device + name: ${friendly_name} Uptime + 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" \ No newline at end of file