--- /dev/null
+######################################################################
+# Substitutions
+######################################################################
+substitutions:
+ esp01_topic: "esphome/esp01"
+ esp01_version: "00.01"
+ vitality_message: "hello, i'm alive!"
+
+######################################################################
+# ESPHome Configuration
+######################################################################
+esphome:
+ name: esp01
+ comment: "Test esp01"
+ platform: ESP8266
+ board: esp01_1m
+
+######################################################################
+# Globals Var
+######################################################################
+globals:
+ - id: enable_flash
+ type: bool
+ restore_value: no
+ initial_value: 'false'
+
+######################################################################
+# WiFi
+######################################################################
+wifi:
+ ssid: !secret wifi_ssid
+ password: !secret wifi_password
+ domain: !secret domain
+
+ # Enable fallback hotspot (captive portal) in case wifi connection fails
+ ap:
+ ssid: "Esp01 Fallback Hotspot"
+ password: !secret hotspot_password
+
+captive_portal:
+
+# Enable logging
+logger:
+
+# Enable Home Assistant API
+#api:
+# password: !secret api_password
+
+ota:
+ password: !secret ota_password
+
+######################################################################
+# Web Server
+######################################################################
+web_server:
+ port: 80
+ auth:
+ username: !secret web_user
+ password: !secret web_password
+
+######################################################################
+# MQTT
+######################################################################
+mqtt:
+ broker: !secret mqtt_host
+ username: !secret mqtt_user
+ password: !secret mqtt_password
+ client_id: esp01
+ discovery: false
+ topic_prefix: $esp01_topic
+ birth_message:
+ topic: '$esp01_topic/status'
+ payload: online
+ will_message:
+ topic: '$esp01_topic/status'
+ payload: offline
+ on_message:
+ - topic: $esp01_topic/switch/led/command
+ qos: 0
+ then:
+ - if:
+ condition:
+ lambda: 'return (x=="on");'
+ then:
+ - switch.turn_on: led
+ - if:
+ condition:
+ lambda: 'return (x=="off");'
+ then:
+ - switch.turn_off: led
+ - if:
+ condition:
+ lambda: 'return (x=="toggle");'
+ then:
+ - switch.toggle: led
+ - topic: $esp01_topic/switch/activity_led/command
+ qos: 0
+ then:
+ - if:
+ condition:
+ lambda: 'return (x=="on");'
+ then:
+ - switch.turn_on: activity_led
+ - if:
+ condition:
+ lambda: 'return (x=="off");'
+ then:
+ - switch.turn_off: activity_led
+ - topic: $esp01_topic/switch/reboot/command
+ qos: 0
+ then:
+ - switch.toggle: reset
+
+######################################################################
+# Switch
+######################################################################
+switch:
+ - platform: gpio
+ name: "Led"
+ id: led
+ internal: false
+ pin: GPIO2
+ inverted: yes
+ restore_mode: ALWAYS_ON
+ #state_topic: esp/esp01/led/status
+
+ - platform: template
+ name: "Activity Led"
+ id: activity_led
+ internal: false
+ #state_topic: esp/esp01/activity_led/status
+ lambda: 'return id(enable_flash);'
+ turn_on_action:
+ - globals.set:
+ id: enable_flash
+ value: 'true'
+ - script.execute: flash
+ turn_off_action:
+ - globals.set:
+ id: enable_flash
+ value: 'false'
+
+ - platform: restart
+ name: "Reboot"
+ internal: false
+ id: reset
+
+#status_led:
+# pin: GPIO2
+
+######################################################################
+# Sensor
+######################################################################
+sensor:
+ - platform: wifi_signal
+ name: "WiFi Signal"
+ update_interval: 60s
+
+######################################################################
+# Text Sensor
+######################################################################
+text_sensor:
+ - platform: version
+ name: "ESPHome Version"
+ icon: mdi:chip
+
+ - platform: template
+ name: "Application Version"
+ icon: mdi:chip
+ lambda: |-
+ return {"$esp01_version"};
+ update_interval: 60s
+
+######################################################################
+# Interval
+######################################################################
+interval:
+ - interval: 60sec
+ then:
+ - script.execute: mqtt_update_msg
+
+######################################################################
+# Scripts
+######################################################################
+script:
+ - id: mqtt_update_msg
+ then:
+ - mqtt.publish:
+ topic: $esp01_topic/vitality
+ payload: $vitality_message
+
+ - id: flash
+ then:
+ - while:
+ condition:
+ lambda: 'return id(enable_flash);'
+ then:
+ - switch.turn_on: led
+ - delay: 100ms
+ - switch.turn_off: led
+ - delay: 100ms
+ - switch.turn_on: led
+ - delay: 100ms
+ - switch.turn_off: led
+ - delay: 100ms
+ - switch.turn_off: led
+ - delay: 1000ms