#:########################################################################################:# # TITLE: GARAGE EXTERNAL CORNER LIGHT # zorruno.com layout v1.1 2026 #:########################################################################################:# # REPO: # https://home.fox.co.nz/gitea/zorruno/zorruno-homeassistant/src/branch/master/esphome/esp-garageextcornerlight.yaml #:########################################################################################:# # VERSIONS: # V2.1 2026-03-11 Updated yaml to zorruno layout V1.1 # V2.0 2025-10-22 Latest layout with home MQTT code # V1.0 2025-10-22 Initial Version #:########################################################################################:# # HARDWARE: # - Sonoff Basic R1 (ESP8266) # - Relay: GPIO12 # - Button: GPIO03 # - Status LED: GPIO13 (inverted) #:########################################################################################:# # OPERATION NOTES: # - Local button toggles the relay output # - MQTT control: # - Command topic: ${mqtt_command_topic} # Payload: "ON" / "OFF" # - Status topic: ${mqtt_status_topic} # Payload: "ON" / "OFF" # - On MQTT connect, publishes current relay state to the status topic #:########################################################################################:# # OFFLINE NOTES: # a) Home Assistant OFFLINE, but Network and MQTT ONLINE # - Local button still works # - MQTT commands still work # b) MQTT OFFLINE (but WiFi/Network and HA API ONLINE) # - Local button still works # - HA/API control still works # - MQTT commands will not work while broker is down # c) Entire WiFi/Network OFFLINE # - Local button still works # - No HA/API and no MQTT control until network returns # - Accurate time is not needed (SNTP not required) #:########################################################################################:# #:########################################################################################:# # SUBSTITUTIONS: Specific device variable substitutions # If NOT using a secrets file, just replace these with the passwords etc (in quotes) #:########################################################################################:# substitutions: # Device Custom Naming device_name: "esp-garageextcornerlight" friendly_name: "Garage External Corner Light" description_comment: "Garage External Corner Light :: Sonoff Basic (Layout V1.1)" device_area: "Garage" # Allows ESP device to be automatically linked to an 'Area' in Home Assistant. static_ip_address: !secret esp-garageextcornerlight_ip mqtt_device_name: "garage-externalcorner-light" # Project Naming project_name: "Sonoff Technologies.Sonoff Basic V1" # Project Details project_version: "v2.1" # Project V denotes release of yaml file, allowing checking of deployed vs latest version # Passwords & Secrets 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 mqtt_command_main_topic: !secret mqtt_command_main_topic mqtt_status_main_topic: !secret mqtt_status_main_topic # If we are changing IP addresses, you must update the current IP address here, otherwise it remains # Don't forget to switch it back when changed. current_ip_address: ${static_ip_address} # Device Settings relay_icon: "mdi:lightbulb" log_level: "ERROR" # NONE, ERROR, WARN, INFO, DEBUG (Default), VERBOSE, VERY_VERBOSE update_interval: "60s" # update time for for general sensors etc # I/O Naming relay_1_name: "Garage External Light" button_1_name: "Power Button" # MQTT Controls mqtt_command_topic: "${mqtt_command_main_topic}/${mqtt_device_name}" mqtt_status_topic: "${mqtt_status_main_topic}/${mqtt_device_name}" #:########################################################################################:# # PACKAGES: Included Common Packages # https://esphome.io/components/packages.html #:########################################################################################:# packages: #### WIFI, Network (Static/DHCP/IPV6 etc), Fallback AP, Safemode #### common_wifi: !include file: common/network_common.yaml vars: local_device_name: "${device_name}" local_static_ip_address: "${static_ip_address}" local_ota_pass: "${ota_pass}" local_current_ip_address: "${current_ip_address}" #### HOME ASSISTANT API (choose encryption or no encryption options) #### common_api: !include file: common/api_common.yaml #file: common/api_common_noencryption.yaml vars: local_api_key: "${api_key}" #### MQTT #### common_mqtt: !include file: common/mqtt_common.yaml vars: local_device_name: "${device_name}" #### WEB PORTAL #### #common_webportal: !include common/webportal_common.yaml #### SNTP (Only use if you want/need accurate timeclocks) #### #common_sntp: !include common/sntp_common.yaml #### DIAGNOSTICS Sensors #### diag_basic: !include common/include_basic_diag_sensors.yaml diag_more: !include common/include_more_diag_sensors.yaml #diag_debug: !include common/include_debug_diag_sensors.yaml #diag_resetcount: !include common/include_resetcount_diag_sensors.yaml #:########################################################################################:# # 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}" #:########################################################################################:# # ESP PLATFORM AND FRAMEWORK: # https://esphome.io/components/esp8266.html #:########################################################################################:# esp8266: board: esp01_1m # The original Sonoff Basic restore_from_flash: true # restore some values on reboot #:########################################################################################:# # PREFERENCES: # https://esphome.io/components/preferences.html #:########################################################################################:# preferences: flash_write_interval: 5min #:########################################################################################:# # MDNS: # https://esphome.io/components/mdns.html #:########################################################################################:# mdns: disabled: false #:########################################################################################:# # LOGGING: # https://esphome.io/components/logger.html #:########################################################################################:# logger: level: "${log_level}" baud_rate: 0 # set to 0 for no logging via UART, needed if you are using it for other serial things (eg PZEM) #:########################################################################################:# # SWITCH COMPONENT: # https://esphome.io/components/switch/ # Sonoff Basic R1 relay is GPIO12 #:########################################################################################:# switch: - platform: gpio name: "${relay_1_name}" pin: GPIO12 id: relay1 restore_mode: RESTORE_DEFAULT_OFF icon: "${relay_icon}" #:########################################################################################:# # BINARY SENSORS: # https://esphome.io/components/binary_sensor/ # Sonoff Basic R1 button is GPIO03 #:########################################################################################:# binary_sensor: # Actual button input - platform: gpio pin: number: GPIO03 mode: INPUT_PULLUP inverted: true name: "${button_1_name}" id: power_button filters: - delayed_on: 20ms on_click: - min_length: 20ms max_length: 500ms then: - lambda: |- if (id(relay1).state) { // Relay is ON: turn it OFF id(relay1).turn_off(); } else { // Relay is OFF: turn it ON id(relay1).turn_on(); } # Mimics actual relay status (publishes MQTT state) - platform: template name: "${relay_1_name} Status" lambda: |- return id(relay1).state; on_press: - mqtt.publish: topic: "${mqtt_status_topic}" payload: "ON" on_release: - mqtt.publish: topic: "${mqtt_status_topic}" payload: "OFF" #:########################################################################################:# # STATUS LED: # https://esphome.io/components/status_led.html # Sonoff Basic R1 LED is GPIO13 #:########################################################################################:# status_led: pin: number: GPIO13 inverted: true #:########################################################################################:# # MQTT: Device-specific command triggers #:########################################################################################:# mqtt: on_message: # Relay control (only act and publish if a change is needed) - topic: "${mqtt_command_topic}" payload: "ON" then: - if: condition: not: switch.is_on: relay1 then: - switch.turn_on: relay1 - mqtt.publish: topic: "${mqtt_status_topic}" payload: "ON" - topic: "${mqtt_command_topic}" payload: "OFF" then: - if: condition: not: switch.is_off: relay1 then: - switch.turn_off: relay1 - mqtt.publish: topic: "${mqtt_status_topic}" payload: "OFF" # Announce current state whenever MQTT (re)connects on_connect: then: - mqtt.publish: topic: "${mqtt_status_topic}" payload: !lambda 'return id(relay1).state ? "ON" : "OFF";'