diff --git a/kube/deploy/apps/esphome/app/config/mitsubishi-cn105-bt-proxy.yaml b/kube/deploy/apps/esphome/app/config/.bluetooth-proxy.yaml similarity index 52% rename from kube/deploy/apps/esphome/app/config/mitsubishi-cn105-bt-proxy.yaml rename to kube/deploy/apps/esphome/app/config/.bluetooth-proxy.yaml index 75e963c5..4fbd0e7e 100644 --- a/kube/deploy/apps/esphome/app/config/mitsubishi-cn105-bt-proxy.yaml +++ b/kube/deploy/apps/esphome/app/config/.bluetooth-proxy.yaml @@ -1,29 +1,3 @@ ---- -substitutions: - area: "$${area}" - name: "AC - CN105" - description: "Mitsubishi CN105 compatible ESP32 serial air conditioner controller for $${area}" -packages: - common: !include - file: ./common.yaml - wifi: !include - file: ./wifi.yaml - -# Mitsubishi CN105 air conditioner controller -external_components: - - source: github://echavet/MitsubishiCN105ESPHome -climate: # Climate entity config - - platform: cn105 - id: > - aircon_${AREA_ID} - name: "Air Conditioner - $${area}" - update_interval: 2s # update interval can be adjusted after a first run and logs monitoring -uart: - id: HP_UART - baud_rate: 2400 - tx_pin: GPIO17 - rx_pin: GPIO16 - # Bluetooth Proxy bluetooth_proxy: active: true @@ -42,14 +16,8 @@ api: # then: # - esp32_ble_tracker.stop_scan: -# Optimizations -logger: - level: INFO - baud_rate: 0 # 0 Enables logging, but disables serial-port logging to free CPU and memory esp32: - board: esp32-s3-devkitc-1 framework: - type: esp-idf # This is important: the default "arduino" framework does not perform well. sdkconfig_options: # @grigi found in testing that these options resulted in better responsiveness. # BLE 4.2 is supported by ALL ESP32 boards that have bluetooth, the original and derivatives. @@ -58,7 +26,3 @@ esp32: CONFIG_BT_BLE_50_FEATURES_SUPPORTED: y # Extend the watchdog timeout, so the device reboots if the device appears locked up for over 10 seconds. CONFIG_ESP_TASK_WDT_TIMEOUT_S: "10" - -# Enable esphome OTA updates -ota: - - platform: esphome diff --git a/kube/deploy/apps/esphome/app/config/.common.yaml b/kube/deploy/apps/esphome/app/config/.common.yaml new file mode 100644 index 00000000..318bc984 --- /dev/null +++ b/kube/deploy/apps/esphome/app/config/.common.yaml @@ -0,0 +1,62 @@ +.substitutions: &subs !include { file: "./.metadata.yaml", vars: { area: "$${area}", name: "$${name}" } } +substitutions: + <<: *subs + system_name: > + ${AREA_DNS}-${NAME_DNS} + device_description: "$${description}" + friendly_name: "$${area} - $${name}" + board: "$${board | default('esp32-s3-devkitc-1')}" + framework: "$${framework | default('esp-idf')}" # This is important: the default "arduino" framework does not perform well. + log: "$${log | default('INFO')}" + +esphome: + name: "$${area_dns}-$${name_dns}" + #!include { file: "./metadata/esphome-name.yaml", vars: { area: "$${area}", name: "$${name}" } } + comment: "$${device_description}" + friendly_name: "$${friendly_name}" + area: + id: "$${area_id}" + #!include { file: "./metadata/area-id.yaml", vars: { area: "$${area}" } } + name: "$${area}" + +esp32: + board: "$${board}" + framework: + type: "$${framework}" + +api: {} + +ota: # Enable esphome OTA updates + - platform: esphome + +binary_sensor: + - platform: status + id: "status_sensor" + name: Status + entity_category: diagnostic + +button: + - platform: restart + name: Restart + id: "restart_button" + icon: mdi:restart + entity_category: config + +sensor: + - platform: uptime + type: seconds + id: "uptime_sensor" + name: Uptime + entity_category: diagnostic + update_interval: 60s + +time: + - platform: sntp + id: time_sntp + timezone: "Asia/Singapore" + update_interval: 6h + +# Optimizations +logger: + level: "$${log}" + baud_rate: 0 # 0 Enables logging, but disables serial-port logging to free CPU and memory diff --git a/kube/deploy/apps/esphome/app/config/.metadata.yaml b/kube/deploy/apps/esphome/app/config/.metadata.yaml new file mode 100644 index 00000000..fd13fe17 --- /dev/null +++ b/kube/deploy/apps/esphome/app/config/.metadata.yaml @@ -0,0 +1,6 @@ +area_dns: > + $${area | replace("'s", "") | replace("_", "-") | replace(" - ", "-") | replace(" ", "-") | lower} +area_id: > + $${area | replace("'", "_") | replace(" - ", "-") | replace(" ", "-") | replace("-", "_") | lower} +name_dns: > + $${name | replace("_", "-") | replace(" - ", "-") | replace(" ", "-") | lower} diff --git a/kube/deploy/apps/esphome/app/config/.mitsubishi-cn105.yaml b/kube/deploy/apps/esphome/app/config/.mitsubishi-cn105.yaml new file mode 100644 index 00000000..7f11de28 --- /dev/null +++ b/kube/deploy/apps/esphome/app/config/.mitsubishi-cn105.yaml @@ -0,0 +1,27 @@ +--- +.substitutions: &subs !include { file: "./.metadata.yaml", vars: { area: "$${area}", name: &name "AC - CN105" } } +substitutions: + <<: *subs + area: "$${area}" + name: *name + description: "Mitsubishi CN105 compatible ESP32 serial air conditioner controller for $${area}" +packages: + common: !include + file: ./.common.yaml + wifi: !include + file: ./.wifi.yaml + +# Mitsubishi CN105 air conditioner controller +external_components: + - source: github://echavet/MitsubishiCN105ESPHome +climate: # Climate entity config + - platform: cn105 + id: "aircon_$${area_id}" + #!include { file: "./metadata/area-id.yaml", vars: { area: "$${area}", prefix: "aircon_" } } + name: "Air Conditioner - $${area}" + update_interval: 2s # update interval can be adjusted after a first run and logs monitoring +uart: + id: HP_UART + baud_rate: 2400 + tx_pin: GPIO17 + rx_pin: GPIO16 diff --git a/kube/deploy/apps/esphome/app/config/wifi.yaml b/kube/deploy/apps/esphome/app/config/.wifi.yaml similarity index 76% rename from kube/deploy/apps/esphome/app/config/wifi.yaml rename to kube/deploy/apps/esphome/app/config/.wifi.yaml index 57cb50aa..926ed3d1 100644 --- a/kube/deploy/apps/esphome/app/config/wifi.yaml +++ b/kube/deploy/apps/esphome/app/config/.wifi.yaml @@ -1,8 +1,4 @@ --- -substitutions: - wifi_db_id: wifi_signal_db - wifi_percent_id: wifi_signal_percent - wifi: domain: .esp.dhcp.internal ssid: !secret wifi_ssid @@ -13,14 +9,14 @@ wifi: sensor: - platform: wifi_signal # Reports the WiFi signal strength in dB name: WiFi Signal dB - id: $${wifi_db_id} + id: &src wifi_signal_db update_interval: 60s entity_category: diagnostic - platform: copy # Reports the WiFi signal strength in % - source_id: $${wifi_db_id} + source_id: *src name: WiFi Signal Percent - id: $${wifi_percent_id} + id: wifi_signal_percent filters: - lambda: return min(max(2 * (x + 100.0), 0.0), 100.0); unit_of_measurement: "%" diff --git a/kube/deploy/apps/esphome/app/config/common.yaml b/kube/deploy/apps/esphome/app/config/common.yaml deleted file mode 100644 index 0b53c07a..00000000 --- a/kube/deploy/apps/esphome/app/config/common.yaml +++ /dev/null @@ -1,45 +0,0 @@ -substitutions: - system_name: > - ${AREA_DNS}-${NAME_DNS} - device_description: "$${description}" - friendly_name: "$${area} - $${name}" - - status_id: status_sensor - restart_id: restart_button - uptime_id: uptime_sensor - -esphome: - name: "$${system_name}" - comment: "$${device_description}" - friendly_name: "$${friendly_name}" - area: - id: > - ${AREA_ID} - name: "$${area}" - -binary_sensor: - - platform: status - id: "$${status_id}" - name: Status - entity_category: diagnostic - -button: - - platform: restart - name: Restart - id: "$${restart_id}" - icon: mdi:restart - entity_category: config - -sensor: - - platform: uptime - type: seconds - id: "$${uptime_id}" - name: Uptime - entity_category: diagnostic - update_interval: 60s - -time: - - platform: sntp - id: time_sntp - timezone: "Asia/Singapore" - update_interval: 6h diff --git a/kube/deploy/apps/esphome/app/config/jj-room-ac.yaml b/kube/deploy/apps/esphome/app/config/jj-room-ac.yaml index 49cf33af..989d96af 100644 --- a/kube/deploy/apps/esphome/app/config/jj-room-ac.yaml +++ b/kube/deploy/apps/esphome/app/config/jj-room-ac.yaml @@ -1,4 +1,6 @@ --- substitutions: area: "JJ's Room" -packages: !include ./mitsubishi-cn105-bt-proxy.yaml +packages: + - !include ./.mitsubishi-cn105.yaml + - !include ./.bluetooth-proxy.yaml diff --git a/kube/deploy/apps/esphome/app/config/kustomization.yaml b/kube/deploy/apps/esphome/app/config/kustomization.yaml index d8ef2de8..77c18b0f 100644 --- a/kube/deploy/apps/esphome/app/config/kustomization.yaml +++ b/kube/deploy/apps/esphome/app/config/kustomization.yaml @@ -4,9 +4,11 @@ kind: Kustomization configMapGenerator: - name: esphome-config files: - - ./common.yaml - - ./wifi.yaml - - ./mitsubishi-cn105-bt-proxy.yaml + - ./.common.yaml + - ./.wifi.yaml + - ./.metadata.yaml + - ./.bluetooth-proxy.yaml + - ./.mitsubishi-cn105.yaml - ./jj-room-ac.yaml - ./master-bedroom-ac.yaml generatorOptions: diff --git a/kube/deploy/apps/esphome/app/config/master-bedroom-ac.yaml b/kube/deploy/apps/esphome/app/config/master-bedroom-ac.yaml index 3e59b658..58142bbd 100644 --- a/kube/deploy/apps/esphome/app/config/master-bedroom-ac.yaml +++ b/kube/deploy/apps/esphome/app/config/master-bedroom-ac.yaml @@ -1,4 +1,6 @@ --- substitutions: area: "Master Bedroom" -packages: !include ./mitsubishi-cn105-bt-proxy.yaml +packages: + - !include ./.mitsubishi-cn105.yaml + - !include ./.bluetooth-proxy.yaml