From a2bb947b4bf10e8c41fea181c6d8cf9e2f220e8e Mon Sep 17 00:00:00 2001 From: Giorgio Ravera Date: Wed, 5 Aug 2020 14:45:44 +0200 Subject: [PATCH] Added esp01.yaml and nodemcu1.yaml --- esp01.yaml | 207 ++++++++++++++++++++++++++++++++++++++++++++++++++ nodemcu1.yaml | 26 +++++++ 2 files changed, 233 insertions(+) create mode 100644 esp01.yaml create mode 100644 nodemcu1.yaml diff --git a/esp01.yaml b/esp01.yaml new file mode 100644 index 0000000..569210b --- /dev/null +++ b/esp01.yaml @@ -0,0 +1,207 @@ +###################################################################### +# 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 diff --git a/nodemcu1.yaml b/nodemcu1.yaml new file mode 100644 index 0000000..cd61865 --- /dev/null +++ b/nodemcu1.yaml @@ -0,0 +1,26 @@ +esphome: + name: nodemcu1 + platform: ESP8266 + board: nodemcuv2 + +wifi: + ssid: !secret wifi_ssid + password: !secret wifi_password + domain: !secret domain + + # Enable fallback hotspot (captive portal) in case wifi connection fails + ap: + ssid: "Nodemcu1 Fallback Hotspot" + password: !secret hotspot_password + +captive_portal: + +# Enable logging +logger: + +# Enable Home Assistant API +api: + password: "test" + +ota: + password: "test" -- 2.47.3