From 579e287e9bf9197c5a36938b8440a8b7f97c9e75 Mon Sep 17 00:00:00 2001 From: Giorgio Ravera Date: Fri, 24 Sep 2021 20:46:39 +0200 Subject: [PATCH] Added relay interface and relay only project --- .gitignore | 10 +++++++ esp01-ro.yaml | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++ esp01.yaml | 45 ++++++++++++++++++++++++------ 3 files changed, 123 insertions(+), 8 deletions(-) create mode 100644 .gitignore create mode 100644 esp01-ro.yaml diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0bbf89c --- /dev/null +++ b/.gitignore @@ -0,0 +1,10 @@ +# Gitignore settings for ESPHome +# This is an example and may include too much for your use-case. +# You can modify this file to suit your needs. +/.esphome/ +**/.pioenvs/ +**/.piolibdeps/ +**/lib/ +**/src/ +**/platformio.ini +/secrets.yaml diff --git a/esp01-ro.yaml b/esp01-ro.yaml new file mode 100644 index 0000000..f9a7026 --- /dev/null +++ b/esp01-ro.yaml @@ -0,0 +1,76 @@ +###################################################################### +# Substitutions +###################################################################### +substitutions: + esp01_topic: "esphome/esp01" + esp01_version: "00.02-ro" + vitality_message: "hello, i'm alive!" + +###################################################################### +# ESPHome Configuration +###################################################################### +esphome: + name: esp01-ro + comment: "Test esp01 relay only" + platform: ESP8266 + board: esp01_1m + +###################################################################### +# 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 + +###################################################################### +# Switch +###################################################################### +switch: + - platform: gpio + name: "Relay" + id: relay + internal: false + pin: GPIO0 + inverted: yes + restore_mode: ALWAYS_OFF + +###################################################################### +# Text Sensor +###################################################################### +text_sensor: + - platform: version + name: "ESPHome Version" + icon: mdi:chip + + - platform: template + name: "Application Version" + icon: mdi:chip + lambda: |- + return {"$esp01_version"}; diff --git a/esp01.yaml b/esp01.yaml index 569210b..0915f71 100644 --- a/esp01.yaml +++ b/esp01.yaml @@ -2,16 +2,18 @@ # Substitutions ###################################################################### substitutions: + esp01_hostname: "esp01" esp01_topic: "esphome/esp01" - esp01_version: "00.01" + esp01_version: "00.02-full" vitality_message: "hello, i'm alive!" + update_interval: 120s ###################################################################### # ESPHome Configuration ###################################################################### esphome: - name: esp01 - comment: "Test esp01" + name: $esp01_hostname + comment: "Test $esp01_hostname full version" platform: ESP8266 board: esp01_1m @@ -40,7 +42,7 @@ wifi: captive_portal: # Enable logging -logger: +#logger: # Enable Home Assistant API #api: @@ -75,6 +77,24 @@ mqtt: topic: '$esp01_topic/status' payload: offline on_message: + - topic: $esp01_topic/switch/relay/command + qos: 0 + then: + - if: + condition: + lambda: 'return (x=="on");' + then: + - switch.turn_on: relay + - if: + condition: + lambda: 'return (x=="off");' + then: + - switch.turn_off: relay + - if: + condition: + lambda: 'return (x=="toggle");' + then: + - switch.toggle: relay - topic: $esp01_topic/switch/led/command qos: 0 then: @@ -115,13 +135,22 @@ mqtt: # Switch ###################################################################### switch: + - platform: gpio + name: "Relay" + id: relay + internal: false + pin: GPIO0 + inverted: yes + restore_mode: ALWAYS_OFF + #state_topic: esp/esp01/relay/status + - platform: gpio name: "Led" id: led internal: false pin: GPIO2 inverted: yes - restore_mode: ALWAYS_ON + restore_mode: ALWAYS_OFF #state_topic: esp/esp01/led/status - platform: template @@ -154,7 +183,7 @@ switch: sensor: - platform: wifi_signal name: "WiFi Signal" - update_interval: 60s + update_interval: $update_interval ###################################################################### # Text Sensor @@ -169,13 +198,13 @@ text_sensor: icon: mdi:chip lambda: |- return {"$esp01_version"}; - update_interval: 60s + update_interval: $update_interval ###################################################################### # Interval ###################################################################### interval: - - interval: 60sec + - interval: $update_interval then: - script.execute: mqtt_update_msg -- 2.47.3