############################################# ############################################# # MASTER BATHROOM HEATED TOWEL RAIL # Controlled by a Sonoff Basic # # V1.0 2025-02-14 Initial Version # # 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 # Use 00:00 in 24hr format for time setting. Note there is no weekday/weekend setting # mqtt_timer_topic/morning-on/06:00 : Time towel rail will go on # mqtt_timer_topic/morning-off/08:00 : Time towel rail will go off # mqtt_timer_topic/evening-on/09:00 : Time towel rail will go on # mqtt_timer_topic/evening-off/00:00 : Time towel rail will go off # mqtt_timer_topic/operation/ON : Towel rail permanently on # mqtt_timer_topic/operation/OFF : Towel rail permanently off # mqtt_timer_topic/operation/TIMER : Towel rail will obey timer settings # mqtt_timer_topic/operation/STARTUP : Turn on for 2 hours then TIMER (also on startup) # ############################################# ############################################# ############################################# # VARIABLE SUBSTITUTIONS # Give the device a useful name & description here # and change values accordingly. ############################################# substitutions: #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 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 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 # Add these if we are using the internal web server (this is pretty processor intensive) #web_server_username: !secret web_server_username #web_server_password: !secret web_server_password update_interval: 60s # update time for for general sensors etc ############################################# # ESPHome # https://esphome.io/components/esphome.html ############################################# esphome: name: ${devicename} friendly_name: ${friendly_name} comment: ${description_comment} #a ppears on the esphome page in HA ############################################# # ESP Platform and Framework # https://esphome.io/components/esp32.html ############################################# esp8266: board: esp01_1m # The original sonoff basic ############################################# # ESPHome Logging Enable # https://esphome.io/components/logger.html ############################################# logger: level: INFO #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 ############################################# # Enable the Home Assistant API # https://esphome.io/components/api.html ############################################# api: encryption: key: ${api_key} ############################################# # Enable Over the Air Update Capability # https://esphome.io/components/ota.html?highlight=ota ############################################# ota: - platform: esphome password: ${ota_pass} ############################################# # Safe Mode # Safe mode will detect boot loops # https://esphome.io/components/safe_mode ############################################# safe_mode: ############################################# # 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: ${static_ip_address} gateway: ${static_ip_gateway} subnet: ${static_ip_subnet} 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 captive_portal: # extra fallback mechanism for when connecting if the configured WiFi fails ############################################# # 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/sntp ############################################# time: - platform: sntp id: sntp_time ############################################# # 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: True # enable entity discovery (true is default) #discover_ip: True # enable device discovery (true is default) ############################################# # Global Variables for use in automations etc # https://esphome.io/guides/automations.html?highlight=globals#global-variables ############################################# #globals: ############################################# # Text Sensors # https://esphome.io/components/text_sensor/index.html ############################################# text_sensor: ###################################################### # ESPHome Info ###################################################### - platform: version name: ${friendly_name} Version - platform: wifi_info ip_address: name: ${friendly_name} IP Address ############################################# # General Sensors # https://esphome.io/components/sensor/index.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/ binary_sensor: - platform: gpio pin: number: GPIO16 mode: INPUT inverted: True name: "Light Switch 1 (Main)" on_press: - switch.toggle: load1 - platform: gpio pin: number: GPIO05 mode: INPUT inverted: True name: "Light Switch 2 (Cabinet)" on_press: - switch.toggle: load2 - platform: gpio pin: number: GPIO04 mode: INPUT inverted: True name: "Extract Fan" on_press: - switch.toggle: load2 switch: - platform: gpio name: "DS Bathroom Top" pin: GPIO13 id: load1 - platform: gpio name: "DS Bathroom Bottom" pin: GPIO12 id: load2 - platform: gpio name: "DS Bathroom Bottom" pin: GPIO14 id: load2 status_led: pin: number: GPIO2 inverted: yes sensor: - platform: wifi_signal name: "DS Bathroom WiFi signal" update_interval: 60s - platform: uptime name: "DS Bathroom uptime" text_sensor: - platform: version name: "DS Bathroom ESPHome version"