Automate adding secrets and change to dashes (#27)

This commit is contained in:
Chris Nussbaum 2021-09-24 21:51:31 -05:00 committed by GitHub
parent 0e61142081
commit e8717deb6c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
29 changed files with 193 additions and 114 deletions

View File

@ -3,10 +3,10 @@ substitutions:
device_name: Basement Bathroom Light and Fan
platform: ESP8266
board: esp01_1m
ip_address: !secret basement_bathroom_light_fan_ip
ota_pwd: !secret basement_bathroom_light_fan_ota_pwd
api_pwd: !secret basement_bathroom_light_fan_api_pwd
ap_wifi_pwd: !secret basement_bathroom_light_fan_ap_wifi_pwd
ip_address: !secret basement-bathroom-light-fan-ip
ota_pwd: !secret basement-bathroom-light-fan-ota-pwd
api_pwd: !secret basement-bathroom-light-fan-api-pwd
ap_wifi_pwd: !secret basement-bathroom-light-fan-ap-pwd
packages:
device_base: !include ../packages/device_base.yaml

View File

@ -3,10 +3,10 @@ substitutions:
device_name: Basement Bathroom Sensor
platform: ESP8266
board: d1_mini
ip_address: !secret basement_bathroom_sensor_ip
ota_pwd: !secret basement_bathroom_sensor_ota_pwd
api_pwd: !secret basement_bathroom_sensor_api_pwd
ap_wifi_pwd: !secret basement_bathroom_sensor_ap_wifi_pwd
ip_address: !secret basement-bathroom-sensor-ip
ota_pwd: !secret basement-bathroom-sensor-ota-pwd
api_pwd: !secret basement-bathroom-sensor-api-pwd
ap_wifi_pwd: !secret basement-bathroom-sensor-ap-pwd
packages:
device_base: !include ../packages/device_base.yaml

View File

@ -3,10 +3,10 @@ substitutions:
device_name: Basement Bathroom Shower Light and Heater
platform: ESP8266
board: esp01_1m
ip_address: !secret basement_bathroom_shower_light_heater_ip
ota_pwd: !secret basement_bathroom_shower_light_heater_ota_pwd
api_pwd: !secret basement_bathroom_shower_light_heater_api_pwd
ap_wifi_pwd: !secret basement_bathroom_shower_light_heater_ap_wifi_pwd
ip_address: !secret basement-bathroom-shower-light-heater-ip
ota_pwd: !secret basement-bathroom-shower-light-heater-ota-pwd
api_pwd: !secret basement-bathroom-shower-light-heater-api-pwd
ap_wifi_pwd: !secret basement-bathroom-shower-light-heater-ap-pwd
packages:
device_base: !include ../packages/device_base.yaml

View File

@ -1,10 +1,10 @@
substitutions:
device_id: basement_stair_lights
device_name: Basement Stair Lights
ip_address: !secret basement_stair_lights_ip
ota_pwd: !secret basement_stair_lights_ota_pwd
api_pwd: !secret basement_stair_lights_api_pwd
ap_wifi_pwd: !secret basement_stair_lights_ap_wifi_pwd
ip_address: !secret basement-stair-lights-ip
ota_pwd: !secret basement-stair-lights-ota-pwd
api_pwd: !secret basement-stair-lights-api-pwd
ap_wifi_pwd: !secret basement-stair-lights-ap-pwd
script:
- id: double_click

View File

@ -1,10 +1,10 @@
substitutions:
device_id: basement_stair_lights_2
device_name: Basement Stair Lights 2
ip_address: !secret basement_stair_lights_2_ip
ota_pwd: !secret basement_stair_lights_2_ota_pwd
api_pwd: !secret basement_stair_lights_2_api_pwd
ap_wifi_pwd: !secret basement_stair_lights_2_ap_wifi_pwd
ip_address: !secret basement-stair-lights-2-ip
ota_pwd: !secret basement-stair-lights-2-ota-pwd
api_pwd: !secret basement-stair-lights-2-api-pwd
ap_wifi_pwd: !secret basement-stair-lights-2-ap-pwd
script:
- id: double_click

View File

@ -3,10 +3,10 @@ substitutions:
device_name: Coffee Maker
platform: ESP8266
board: nodemcuv2
ip_address: !secret coffee_maker_ip
ota_pwd: !secret coffee_maker_ota_pwd
api_pwd: !secret coffee_maker_api_pwd
ap_wifi_pwd: !secret coffee_maker_ap_wifi_pwd
ip_address: !secret coffee-maker-ip
ota_pwd: !secret coffee-maker-ota-pwd
api_pwd: !secret coffee-maker-api-pwd
ap_wifi_pwd: !secret coffee-maker-ap-pwd
packages:
device_base: !include ../packages/device_base.yaml

View File

@ -1,10 +1,10 @@
substitutions:
device_id: computer_light
device_name: Computer Light
ip_address: !secret computer_light_ip
ota_pwd: !secret computer_light_ota_pwd
api_pwd: !secret computer_light_api_pwd
ap_wifi_pwd: !secret computer_light_ap_wifi_pwd
ip_address: !secret computer-light-ip
ota_pwd: !secret computer-light-ota-pwd
api_pwd: !secret computer-light-api-pwd
ap_wifi_pwd: !secret computer-light-ap-pwd
packages:
feit_dimmer: !include ../packages/feit_dimmer.yaml

View File

@ -1,10 +1,10 @@
substitutions:
device_id: dining_room_light
device_name: Dining Room Light
ip_address: !secret dining_room_light_ip
ota_pwd: !secret dining_room_light_ota_pwd
api_pwd: !secret dining_room_light_api_pwd
ap_wifi_pwd: !secret dining_room_light_ap_wifi_pwd
ip_address: !secret dining-room-light-ip
ota_pwd: !secret dining-room-light-ota-pwd
api_pwd: !secret dining-room-light-api-pwd
ap_wifi_pwd: !secret dining-room-light-ap-pwd
packages:
feit_dimmer: !include ../packages/feit_dimmer.yaml

View File

@ -1,10 +1,10 @@
substitutions:
device_id: family_room_light
device_name: Family Room Light
ip_address: !secret family_room_light_ip
ota_pwd: !secret family_room_light_ota_pwd
api_pwd: !secret family_room_light_api_pwd
ap_wifi_pwd: !secret family_room_light_ap_wifi_pwd
ip_address: !secret family-room-light-ip
ota_pwd: !secret family-room-light-ota-pwd
api_pwd: !secret family-room-light-api-pwd
ap_wifi_pwd: !secret family-room-light-ap-pwd
packages:
feit_dimmer: !include ../packages/feit_dimmer.yaml

View File

@ -3,10 +3,10 @@ substitutions:
device_name: Fire Pit and Fountain
platform: ESP8266
board: d1_mini
ip_address: !secret fire_pit_fountain_ip
ota_pwd: !secret fire_pit_fountain_ota_pwd
api_pwd: !secret fire_pit_fountain_api_pwd
ap_wifi_pwd: !secret fire_pit_fountain_ap_wifi_pwd
ip_address: !secret fire-pit-fountain-ip
ota_pwd: !secret fire-pit-fountain-ota-pwd
api_pwd: !secret fire-pit-fountain-api-pwd
ap_wifi_pwd: !secret fire-pit-fountain-ap-pwd
packages:
device_base: !include ../packages/device_base.yaml

View File

@ -1,10 +1,10 @@
substitutions:
device_id: front_entry_lights
device_name: Front Entry Lights
ip_address: !secret front_entry_lights_ip
ota_pwd: !secret front_entry_lights_ota_pwd
api_pwd: !secret front_entry_lights_api_pwd
ap_wifi_pwd: !secret front_entry_lights_ap_wifi_pwd
ip_address: !secret front-entry-lights-ip
ota_pwd: !secret front-entry-lights-ota-pwd
api_pwd: !secret front-entry-lights-api-pwd
ap_wifi_pwd: !secret front-entry-lights-ap-pwd
packages:
feit_dimmer: !include ../packages/feit_dimmer.yaml

View File

@ -1,10 +1,10 @@
substitutions:
device_id: front_entry_lights_2
device_name: Front Entry Lights 2
ip_address: !secret front_entry_lights_2_ip
ota_pwd: !secret front_entry_lights_2_ota_pwd
api_pwd: !secret front_entry_lights_2_api_pwd
ap_wifi_pwd: !secret front_entry_lights_2_ap_wifi_pwd
ip_address: !secret front-entry-lights_2-ip
ota_pwd: !secret front-entry-lights-2-ota-pwd
api_pwd: !secret front-entry-lights-2-api-pwd
ap_wifi_pwd: !secret front-entry-lights-2-ap-pwd
packages:
feit_dimmer: !include ../packages/feit_dimmer_without_power.yaml

View File

@ -1,10 +1,10 @@
substitutions:
device_id: front_lights
device_name: Front Lights
ip_address: !secret front_lights_ip
ota_pwd: !secret front_lights_ota_pwd
api_pwd: !secret front_lights_api_pwd
ap_wifi_pwd: !secret front_lights_ap_wifi_pwd
ip_address: !secret front-lights-ip
ota_pwd: !secret front-lights-ota-pwd
api_pwd: !secret front-lights-api-pwd
ap_wifi_pwd: !secret front-lights-ap-pwd
packages:
feit_dimmer: !include ../packages/feit_dimmer.yaml

View File

@ -3,10 +3,10 @@ substitutions:
device_name: Garage Fridge
platform: ESP8266
board: nodemcuv2
ip_address: !secret garage_fridge_ip
ota_pwd: !secret garage_fridge_ota_pwd
api_pwd: !secret garage_fridge_api_pwd
ap_wifi_pwd: !secret garage_fridge_ap_wifi_pwd
ip_address: !secret garage-fridge-ip
ota_pwd: !secret garage-fridge-ota-pwd
api_pwd: !secret garage-fridge-api-pwd
ap_wifi_pwd: !secret garage-fridge-ap-pwd
packages:
device_base: !include ../packages/device_base.yaml

View File

@ -1,10 +1,10 @@
substitutions:
device_id: kitchen_bar_lights
device_name: Kitchen Bar Lights
ip_address: !secret kitchen_bar_lights_ip
ota_pwd: !secret kitchen_bar_lights_ota_pwd
api_pwd: !secret kitchen_bar_lights_api_pwd
ap_wifi_pwd: !secret kitchen_bar_lights_ap_wifi_pwd
ip_address: !secret kitchen-bar-lights-ip
ota_pwd: !secret kitchen-bar-lights-ota-pwd
api_pwd: !secret kitchen-bar-lights-api-pwd
ap_wifi_pwd: !secret kitchen-bar-lights-ap-pwd
packages:
feit_dimmer: !include ../packages/feit_dimmer.yaml

View File

@ -1,10 +1,10 @@
substitutions:
device_id: kitchen_table_light
device_name: Kitchen Table Light
ip_address: !secret kitchen_table_light_ip
ota_pwd: !secret kitchen_table_light_ota_pwd
api_pwd: !secret kitchen_table_light_api_pwd
ap_wifi_pwd: !secret kitchen_table_light_ap_wifi_pwd
ip_address: !secret kitchen-table-light-ip
ota_pwd: !secret kitchen-table-light-ota-pwd
api_pwd: !secret kitchen-table-light-api-pwd
ap_wifi_pwd: !secret kitchen-table-light-ap-pwd
packages:
feit_dimmer: !include ../packages/feit_dimmer.yaml

View File

@ -1,10 +1,10 @@
substitutions:
device_id: living_room_lights
device_name: Living Room Lights
ip_address: !secret living_room_lights_ip
ota_pwd: !secret living_room_lights_ota_pwd
api_pwd: !secret living_room_lights_api_pwd
ap_wifi_pwd: !secret living_room_lights_ap_wifi_pwd
ip_address: !secret living-room-lights-ip
ota_pwd: !secret living-room-lights-ota-pwd
api_pwd: !secret living-room-lights-api-pwd
ap_wifi_pwd: !secret living-room-lights-ap-pwd
packages:
feit_dimmer: !include ../packages/feit_dimmer.yaml

View File

@ -1,10 +1,10 @@
substitutions:
device_id: master_bath_fan
device_name: Master Bathroom Fan
ip_address: !secret master_bath_fan_ip
ota_pwd: !secret master_bath_fan_ota_pwd
api_pwd: !secret master_bath_fan_api_pwd
ap_wifi_pwd: !secret master_bath_fan_ap_wifi_pwd
ip_address: !secret master-bath-fan-ip
ota_pwd: !secret master-bath-fan-ota-pwd
api_pwd: !secret master-bath-fan-api-pwd
ap_wifi_pwd: !secret master-bath-fan-ap-pwd
fan_wattage: "26.6"
packages:

View File

@ -3,10 +3,10 @@ substitutions:
device_name: Master Bathroom Humidity and Temperature Sensor
platform: ESP8266
board: d1_mini
ip_address: !secret master_bath_humidity_temp_sensor_ip
ota_pwd: !secret master_bath_humidity_temp_sensor_ota_pwd
api_pwd: !secret master_bath_humidity_temp_sensor_api_pwd
ap_wifi_pwd: !secret master_bath_humidity_temp_sensor_ap_wifi_pwd
ip_address: !secret master-bath-humidity-temp-sensor-ip
ota_pwd: !secret master-bath-humidity-temp-sensor-ota-pwd
api_pwd: !secret master-bath-humidity-temp-sensor-api-pwd
ap_wifi_pwd: !secret master-bath-humidity-temp-sensor-ap-pwd
packages:
device_base: !include ../packages/device_base.yaml

View File

@ -1,10 +1,10 @@
substitutions:
device_id: master_bath_lights
device_name: Master Bathroom Lights
ip_address: !secret master_bath_lights_ip
ota_pwd: !secret master_bath_lights_ota_pwd
api_pwd: !secret master_bath_lights_api_pwd
ap_wifi_pwd: !secret master_bath_lights_ap_wifi_pwd
ip_address: !secret master-bath-lights-ip
ota_pwd: !secret master-bath-lights-ota-pwd
api_pwd: !secret master-bath-lights-api-pwd
ap_wifi_pwd: !secret master-bath-lights-ap-pwd
packages:
feit_dimmer: !include ../packages/feit_dimmer.yaml

View File

@ -1,10 +1,10 @@
substitutions:
device_id: master_bath_lights_2
device_name: Master Bathroom Lights 2
ip_address: !secret master_bath_lights_2_ip
ota_pwd: !secret master_bath_lights_2_ota_pwd
api_pwd: !secret master_bath_lights_2_api_pwd
ap_wifi_pwd: !secret master_bath_lights_2_ap_wifi_pwd
ip_address: !secret master-bath-lights-2-ip
ota_pwd: !secret master-bath-lights-2-ota-pwd
api_pwd: !secret master-bath-lights-2-api-pwd
ap_wifi_pwd: !secret master-bath-lights-2-ap-pwd
packages:
feit_dimmer: !include ../packages/feit_dimmer_without_power.yaml

View File

@ -3,10 +3,10 @@ substitutions:
device_name: Master Bed
platform: ESP8266
board: nodemcuv2
ip_address: !secret master_bed_ip
ota_pwd: !secret master_bed_ota_pwd
api_pwd: !secret master_bed_api_pwd
ap_wifi_pwd: !secret master_bed_ap_wifi_pwd
ip_address: !secret master-bed-ip
ota_pwd: !secret master-bed-ota-pwd
api_pwd: !secret master-bed-api-pwd
ap_wifi_pwd: !secret master-bed-ap-pwd
packages:
device_base: !include ../packages/device_base.yaml

View File

@ -1,10 +1,10 @@
substitutions:
device_id: office_light
device_name: Office Light
ip_address: !secret office_light_ip
ota_pwd: !secret office_light_ota_pwd
api_pwd: !secret office_light_api_pwd
ap_wifi_pwd: !secret office_light_ap_wifi_pwd
ip_address: !secret office-light-ip
ota_pwd: !secret office-light-ota-pwd
api_pwd: !secret office-light-api-pwd
ap_wifi_pwd: !secret office-light-ap-pwd
packages:
feit_dimmer: !include ../packages/feit_dimmer.yaml

View File

@ -3,10 +3,10 @@ substitutions:
device_name: Patio Lights
platform: ESP8266
board: d1_mini
ip_address: !secret patio_lights_ip
ota_pwd: !secret patio_lights_ota_pwd
api_pwd: !secret patio_lights_api_pwd
ap_wifi_pwd: !secret patio_lights_ap_wifi_pwd
ip_address: !secret patio-lights-ip
ota_pwd: !secret patio-lights-ota-pwd
api_pwd: !secret patio-lights-api-pwd
ap_wifi_pwd: !secret patio-lights-ap-pwd
packages:
device_base: !include ../packages/device_base.yaml

View File

@ -3,10 +3,10 @@ substitutions:
device_name: Pool and Patio Lights
platform: ESP8266
board: esp01_1m
ip_address: !secret pool_and_patio_lights_ip
ota_pwd: !secret pool_and_patio_lights_ota_pwd
api_pwd: !secret pool_and_patio_lights_api_pwd
ap_wifi_pwd: !secret pool_and_patio_lights_ap_wifi_pwd
ip_address: !secret pool-and-patio-lights-ip
ota_pwd: !secret pool-and-patio-lights-ota-pwd
api_pwd: !secret pool-and-patio-lights-api-pwd
ap_wifi_pwd: !secret pool-and-patio-lights-ap-pwd
packages:
device_base: !include ../packages/device_base.yaml

View File

@ -3,10 +3,10 @@ substitutions:
device_name: Pool Pumps
platform: ESP8266
board: modwifi
ip_address: !secret pool_pumps_ip
ota_pwd: !secret pool_pumps_ota_pwd
api_pwd: !secret pool_pumps_api_pwd
ap_wifi_pwd: !secret pool_pumps_ap_wifi_pwd
ip_address: !secret pool-pumps-ip
ota_pwd: !secret pool-pumps-ota-pwd
api_pwd: !secret pool-pumps-api-pwd
ap_wifi_pwd: !secret pool-pumps-ap-pwd
packages:
device_base: !include ../packages/device_base.yaml
@ -38,7 +38,7 @@ pool_controller:
pump:
switch_id: pool_pump
current_id: pool_pump_current
min_current: 6.45
min_current: 3.45
max_current: 6.75
max_out_of_range_duration: 5s
cleaner:

View File

@ -1,9 +1,9 @@
substitutions:
log_level: none
wifi_ssid: !secret wifi_ssid
wifi_password: !secret wifi_password
ip_subnet: !secret ip_subnet
ip_gateway: !secret ip_gateway
wifi_ssid: !secret wifi-ssid
wifi_password: !secret wifi-password
ip_subnet: !secret ip-subnet
ip_gateway: !secret ip-gateway
esphome:
name: ${device_id}

View File

@ -10,17 +10,17 @@ external_components:
- source: github://cbpowell/ESPSense
components: [ espsense ]
packages:
base: !include device_base.yaml
logger: !include logger/logger_no_serial.yaml
uart: !include uart/tuya.yaml
espsense:
plugs:
- name: ${device_name}
power_sensor: power
voltage: 120
packages:
base: !include device_base.yaml
logger: !include logger/logger_no_serial.yaml
uart: !include uart/tuya.yaml
sensor:
- platform: total_daily_energy
name: ${device_name}

79
scripts/secrets.ps1 Normal file
View File

@ -0,0 +1,79 @@
if ($Args.Count -ne 2 -or ($Args[0] -ne "add" -and $Args[0] -ne "get"))
{
Write-Output "Invalid parameters"
exit 1
}
Add-Type -AssemblyName 'System.Web'
if (!(Get-InstalledModule -Name powershell-yaml -ErrorAction SilentlyContinue))
{
Install-Module -Scope CurrentUser powershell-yaml
}
$device = $Args[1]
if ($device.Contains("_"))
{
Write-Output "Invalid device id"
exit 1
}
[string[]]$secretsFile = Get-Content $PSScriptRoot\..\secrets.yaml
$yaml = ''
foreach ($line in $secretsFile) { $yaml = $yaml + "`n" + $line }
$secrets = ConvertFrom-YAML $yaml -Ordered
if ($Args[0] -eq "add")
{
if ($secrets.Contains("${device}-ip"))
{
Write-Output "Device already exists"
exit 1
}
$lastIp = ([IPAddress] "192.168.0.0").GetAddressBytes()
foreach ($key in $secrets.Keys)
{
if ($key.EndsWith("ip"))
{
$ip = ([IPAddress] $secrets.$key).GetAddressBytes()
if ($ip[2] -gt $lastIp[2] -or ($ip[2] -eq $lastIp[2] -and $ip[3] -gt $lastIp[3]))
{
$lastIp = $ip
}
}
}
$nextIp = $lastIp
if ($nextIp[3] -eq 255)
{
$nextIp[3] = 0
$nextIp[2] += 1
}
else
{
$nextIp[3] += 1
}
$secrets["${device}-ip"] = ([IPAddress]$nextIp).ToString()
$secrets["${device}-api-pwd"] = -join ((48..57) + (65..90) + (97..122) | Get-Random -Count 16 | % {[char]$_})
$secrets["${device}-ota-pwd"] = -join ((48..57) + (65..90) + (97..122) | Get-Random -Count 16 | % {[char]$_})
$secrets["${device}-ap-pwd"] = -join ((48..57) + (65..90) + (97..122) | Get-Random -Count 16 | % {[char]$_})
Out-File $PSScriptRoot\..\secrets.yaml -InputObject (ConvertTo-YAML $secrets)
}
if (!$secrets.Contains("${device}-ip"))
{
Write-Output "Device not found"
exit 1
}
$ip = $secrets["${device}-ip"]
$api = $secrets["${device}-api-pwd"]
$ota = $secrets["${device}-ota-pwd"]
$ap = $secrets["${device}-ap-pwd"]
Write-Output ${device}:
Write-Output " IP Address: ${ip}"
Write-Output " API Password: ${api}"
Write-Output " OTA Password: ${ota}"
Write-Output " AP Password: ${ap}"