From 774ba71a8672249c2b7f76b3cb57c0f414f57900 Mon Sep 17 00:00:00 2001 From: Artem Sheremet Date: Fri, 7 Apr 2023 22:17:14 +0200 Subject: [PATCH] Reorganize configs into packages --- .gitignore | 2 +- bathroomheater.yaml | 20 ++------------------ blinds.yaml | 23 ++++------------------- boiler.yaml | 20 ++------------------ btproxy.yaml | 21 ++------------------- ruuvi.yaml | 27 +++------------------------ secrets.yaml.sample | 1 + templates/esp32-poe.yaml | 21 +++++++++++++++++++++ templates/esp8266.yaml | 19 +++++++++++++++++++ templates/mqtt.yaml | 5 +++++ templates/ota.yaml | 2 ++ templates/secrets.yaml.sample | 4 ++++ templates/wifi.yaml | 4 ++++ watermeter.yaml | 24 ++---------------------- 14 files changed, 72 insertions(+), 121 deletions(-) create mode 100644 secrets.yaml.sample create mode 100644 templates/esp32-poe.yaml create mode 100644 templates/esp8266.yaml create mode 100644 templates/mqtt.yaml create mode 100644 templates/ota.yaml create mode 100644 templates/secrets.yaml.sample create mode 100644 templates/wifi.yaml diff --git a/.gitignore b/.gitignore index bd2e2c0..6bf2aea 100644 --- a/.gitignore +++ b/.gitignore @@ -8,4 +8,4 @@ **/src/ **/platformio.ini **/partitions.csv -/secrets.yaml +secrets.yaml diff --git a/bathroomheater.yaml b/bathroomheater.yaml index a4d475b..9d3c39c 100644 --- a/bathroomheater.yaml +++ b/bathroomheater.yaml @@ -8,15 +8,8 @@ esphome: includes: - zehnder.h -esp8266: - board: nodemcuv2 - -logger: - -mqtt: - broker: homeassistant - username: esphome - password: !secret mqtt_password +packages: + device_base: !include templates/esp8266.yaml dallas: - pin: D1 @@ -24,7 +17,6 @@ dallas: sensor: - platform: dallas address: 0x0401212E565C7428 - name: "Bathroom Heater Temperature" id: bathroom_heater_temperature remote_transmitter: @@ -49,11 +41,3 @@ interval: then: # Periodically remind heater about the current setting. lambda: static_cast(id(bathroom_heater))->retransmit(); - -ota: - password: !secret ota_password - -wifi: - ssid: !secret wifi_ssid - password: !secret wifi_password - domain: "" diff --git a/blinds.yaml b/blinds.yaml index 2b9bcf8..d890f70 100644 --- a/blinds.yaml +++ b/blinds.yaml @@ -8,16 +8,9 @@ esphome: includes: - somfy.h -esp8266: - board: nodemcuv2 - -logger: - -mqtt: - broker: homeassistant - username: esphome - password: !secret mqtt_password - id: mqtt_client +packages: + device_base: !include templates/esp8266.yaml + mqtt: !include templates/mqtt.yaml globals: - id: somfy_remote_id_base @@ -36,7 +29,7 @@ cover: auto cover = new SomfyRTS( rfPin, id(somfy_remote_id_base) + i, - id(mqtt_client)); + id(mqtt_homeassistant)); blinds.push_back(cover); App.register_component(cover); } @@ -57,11 +50,3 @@ cover: - name: "Living Room window" - name: "Guest East window" - name: "Guest East door" - -ota: - password: !secret ota_password - -wifi: - ssid: !secret wifi_ssid - password: !secret wifi_password - domain: "" diff --git a/boiler.yaml b/boiler.yaml index 9d51c10..76d1267 100644 --- a/boiler.yaml +++ b/boiler.yaml @@ -5,10 +5,8 @@ esphome: name: dasfoo.boiler version: "1.0" -esp8266: - board: nodemcuv2 - -logger: +packages: + device_base: !include templates/esp8266.yaml i2c: sda: D3 @@ -36,11 +34,6 @@ display: it.circle(112, 16, 12); } -mqtt: - broker: homeassistant - username: esphome - password: !secret mqtt_password - dallas: - pin: D1 @@ -54,7 +47,6 @@ sensor: - platform: adc pin: A0 - name: "Furnace LED brightness" update_interval: 1s id: furnace_led_brightness @@ -66,11 +58,3 @@ binary_sensor: threshold: 0.7 filters: - invert: - -ota: - password: !secret ota_password - -wifi: - ssid: !secret wifi_ssid - password: !secret wifi_password - domain: "" diff --git a/btproxy.yaml b/btproxy.yaml index 81065c1..580001a 100644 --- a/btproxy.yaml +++ b/btproxy.yaml @@ -6,14 +6,8 @@ esphome: name: dasfoo.btproxy version: "1.0" -esp32: - board: esp32-poe - # Required for BLE. - framework: - type: esp-idf - -# Enable logging. -logger: +packages: + device_base: !include templates/esp32-poe.yaml # Allow HA to use our proxy. # Don't enable MQTT as the device will be "discovered" twice. @@ -33,14 +27,3 @@ bluetooth_proxy: button: - platform: restart name: "btproxy Restart" - -ota: - password: !secret ota_password - -ethernet: - type: LAN8720 - mdc_pin: GPIO23 - mdio_pin: GPIO18 - clk_mode: GPIO17_OUT - phy_addr: 0 - power_pin: GPIO12 diff --git a/ruuvi.yaml b/ruuvi.yaml index bdc9812..a4e22f9 100644 --- a/ruuvi.yaml +++ b/ruuvi.yaml @@ -5,19 +5,9 @@ esphome: name: dasfoo.ruuvi version: "1.0" -esp32: - board: esp32-poe - # Required for BLE. - framework: - type: esp-idf - -# Enable logging -logger: - -mqtt: - broker: homeassistant - username: esphome - password: !secret mqtt_password +packages: + device_base: !include templates/esp32-poe.yaml + mqtt: !include templates/mqtt.yaml # Required for ruuvitag. esp32_ble_tracker: @@ -47,14 +37,3 @@ sensor: name: "Outdoor West Acceleration" battery_voltage: name: "Outdoor West Sensor Battery Voltage" - -ota: - password: !secret ota_password - -ethernet: - type: LAN8720 - mdc_pin: GPIO23 - mdio_pin: GPIO18 - clk_mode: GPIO17_OUT - phy_addr: 0 - power_pin: GPIO12 diff --git a/secrets.yaml.sample b/secrets.yaml.sample new file mode 100644 index 0000000..98dcd6e --- /dev/null +++ b/secrets.yaml.sample @@ -0,0 +1 @@ +somfy_remote_id_base: "11111" diff --git a/templates/esp32-poe.yaml b/templates/esp32-poe.yaml new file mode 100644 index 0000000..ed6ef1b --- /dev/null +++ b/templates/esp32-poe.yaml @@ -0,0 +1,21 @@ +esp32: + board: esp32-poe + # Required for BLE. + framework: + type: esp-idf + +status_led: + pin: GPIO2 + +ethernet: + type: LAN8720 + mdc_pin: GPIO23 + mdio_pin: GPIO18 + clk_mode: GPIO17_OUT + phy_addr: 0 + power_pin: GPIO12 + +logger: + +packages: + ota: !include ota.yaml diff --git a/templates/esp8266.yaml b/templates/esp8266.yaml new file mode 100644 index 0000000..73065e0 --- /dev/null +++ b/templates/esp8266.yaml @@ -0,0 +1,19 @@ +esp8266: + board: nodemcuv2 + +packages: + wifi: !include wifi.yaml + ota: !include ota.yaml + mqtt: !include mqtt.yaml + +logger: + +status_led: + pin: + # There are 2 LEDs on NodeMCU v2, one next to the WiFi + # antenna, another near the power socket / RST button. + # The one at WiFi is connected to UART so it blinks on + # flash, thus we will use the other one for status. + # https://lowvoltage.github.io/2017/07/09/Onboard-LEDs-NodeMCU-Got-Two + number: GPIO16 + inverted: true diff --git a/templates/mqtt.yaml b/templates/mqtt.yaml new file mode 100644 index 0000000..f76fb6e --- /dev/null +++ b/templates/mqtt.yaml @@ -0,0 +1,5 @@ +mqtt: + broker: homeassistant + username: esphome + password: !secret mqtt_password + id: mqtt_homeassistant diff --git a/templates/ota.yaml b/templates/ota.yaml new file mode 100644 index 0000000..e43531f --- /dev/null +++ b/templates/ota.yaml @@ -0,0 +1,2 @@ +ota: + password: !secret ota_password diff --git a/templates/secrets.yaml.sample b/templates/secrets.yaml.sample new file mode 100644 index 0000000..73a16c5 --- /dev/null +++ b/templates/secrets.yaml.sample @@ -0,0 +1,4 @@ +wifi_ssid: IoT +wifi_password: "IoT$eKuRe" +ota_password: "OTA_ALS0_SECCUR" +mqtt_password: "ttqm" diff --git a/templates/wifi.yaml b/templates/wifi.yaml new file mode 100644 index 0000000..f41859e --- /dev/null +++ b/templates/wifi.yaml @@ -0,0 +1,4 @@ +wifi: + ssid: !secret wifi_ssid + password: !secret wifi_password + domain: "" diff --git a/watermeter.yaml b/watermeter.yaml index 75b4279..8a34ba3 100644 --- a/watermeter.yaml +++ b/watermeter.yaml @@ -5,20 +5,8 @@ esphome: name: dasfoo.watermeter version: "1.0" -esp8266: - board: nodemcuv2 - -logger: - -mqtt: - broker: homeassistant - username: esphome - password: !secret mqtt_password - -status_led: - pin: - number: D4 # WiFi LED. - inverted: true +packages: + device_base: !include templates/esp8266.yaml sensor: - platform: pulse_meter @@ -38,11 +26,3 @@ sensor: unit_of_measurement: "L" device_class: "water" state_class: "total_increasing" - -ota: - password: !secret ota_password - -wifi: - ssid: !secret wifi_ssid - password: !secret wifi_password - domain: ""