refactoring: imports + cleanup

This commit is contained in:
Brian Hanifin
2019-11-07 08:49:22 -08:00
parent 7dd2d0e2b0
commit 4d4b81ac84
9 changed files with 179 additions and 249 deletions
+1 -1
View File
@@ -27,7 +27,7 @@ These are simple round wall plugs were flashed with over the air with tasmota-co
### Shelly1's
These devices are great for shoving in a box behind a light switch to add smarts.
#### Dining Room Wall Switch: shelly01.yaml
#### Dining Room Wall Switch: shelly1_01.yaml
I coded this to be create a smart switch that is compatible with a chandelier with 9 hue bulbs. It's relay is disabled, unless Home Assistant is unavailable. This allows it to operate as a virtual 3-way switch with Home Assistant, as well as failing gracefully should Home Assistant be offline to act as a dumb toggle switch.
#### Upstairs Bathroom Fan: shelly1_02.yaml
+93 -155
View File
@@ -3,269 +3,207 @@
substitutions:
devicename: bluetooth_hub
upper_devicename: BLE Hub
<<: !include common/substitutions/bluetooth_hub.yaml
# Xiaomi Digital Thermometer + Humidity Sensor
temp1_mac: !secret temp1_mac
temp1: xiaomi_mijia_01
temp1_upper: Xiaomi MiJia 01
# Xiaomi Mi Flora 01
plant1_mac: !secret plant1_mac
plant1: xiaomi_miflora_01
plant1_upper: Xiaomi MiFlora 01
# Xiaomi Mi Flora 02: "North" Plant Monitor
plant2_mac: !secret plant2_mac
plant2: xiaomi_miflora_02
plant2_upper: Xiaomi MiFlora 02
# Xiaomi Mi Flora 03: "North" Plant Monitor
plant3_mac: !secret plant3_mac
plant3: xiaomi_miflora_03
plant3_upper: Xiaomi MiFlora 03
# Xiaomi Mi Flora 04: "North" Plant Monitor
plant4_mac: !secret plant4_mac
plant4: xiaomi_miflora_04
plant4_upper: Xiaomi MiFlora 04
# Xiaomi Mi Flora 05: "North" Plant Monitor
plant5_mac: !secret plant5_mac
plant5: xiaomi_miflora_05
plant5_upper: Xiaomi MiFlora 05
# Xiaomi Mi Flora 06: "North" Plant Monitor
plant6_mac: !secret plant6_mac
plant6: xiaomi_miflora_06
plant6_upper: Xiaomi MiFlora 06
esphome:
name: ${devicename}
platform: ESP32
board: esp-wrover-kit
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_pass
# Enable logging
logger:
# Enable Home Assistant API
api:
ota:
binary_sensor:
- platform: status
name: ${upper_devicename} Status
id: ${devicename}_status
<<: !include common/esphome/esp32_wrover.yaml
<<: !include common/wifi.yaml
<<: !include common/ota.yaml
<<: !include common/logger.yaml
<<: !include common/api.yaml
esp32_ble_tracker:
scan_interval: 30s
sensor:
- platform: ble_rssi
mac_address: ${temp1_mac}
id: ${temp1}
name: ${temp1_upper}
- platform: ble_rssi
mac_address: ${plant1_mac}
id: ${plant1}
name: ${plant1_upper}
- platform: ble_rssi
mac_address: ${plant2_mac}
id: ${plant2}
name: ${plant2_upper}
- platform: ble_rssi
mac_address: ${plant3_mac}
id: ${plant3}
name: ${plant3_upper}
- platform: ble_rssi
mac_address: ${plant4_mac}
id: ${plant4}
name: ${plant4_upper}
- platform: ble_rssi
mac_address: ${plant5_mac}
id: ${plant5}
name: ${plant5_upper}
- platform: ble_rssi
mac_address: ${plant6_mac}
id: ${plant6}
name: ${plant6_upper}
# - platform: ble_rssi
# mac_address: $temp1_mac
# id: $temp1
# name: $temp1_upper
# - platform: ble_rssi
# mac_address: $plant1_mac
# id: $plant1
# name: $plant1_upper
# - platform: ble_rssi
# mac_address: $plant2_mac
# id: $plant2
# name: $plant2_upper
# - platform: ble_rssi
# mac_address: $plant3_mac
# id: $plant3
# name: $plant3_upper
# - platform: ble_rssi
# mac_address: $plant4_mac
# id: $plant4
# name: $plant4_upper
# - platform: ble_rssi
# mac_address: $plant5_mac
# id: $plant5
# name: $plant5_upper
# - platform: ble_rssi
# mac_address: $plant6_mac
# id: $plant6
# name: $plant6_upper
- platform: wifi_signal
name: ${devicename} WiFi Signal
update_interval: 30s
- platform: uptime
name: ${devicename} Uptime
- platform: xiaomi_mijia
mac_address: ${temp1_mac}
- platform: xiaomi_lywsdcgq
mac_address: $temp1_mac
temperature:
name: ${temp1_upper} Temperature
name: $temp1_upper Temperature
id: ${temp1}_temperature
humidity:
name: ${temp1_upper} Humidity
name: $temp1_upper Humidity
id: ${temp1}_humidity
- platform: xiaomi_miflora
mac_address: ${plant1_mac}
- platform: xiaomi_hhccjcy01
mac_address: $plant1_mac
temperature:
name: ${plant1_upper} Temperature
name: $plant1_upper Temperature
id: ${plant1}_temperature
filters:
- filter_out: nan
- lambda: return x * (9.0/5.0) + 32.0;
unit_of_measurement: "°F"
moisture:
name: ${plant1_upper} Moisture
name: $plant1_upper Moisture
icon: mdi:water-percent
id: ${plant1}_moisture
filters:
- filter_out: nan
illuminance:
name: ${plant1_upper} Illuminance
name: $plant1_upper Illuminance
id: ${plant1}_illuminance
filters:
- filter_out: nan
conductivity:
name: ${plant1_upper} Soil Conductivity
name: $plant1_upper Soil Conductivity
id: ${plant1}_conductivity
filters:
- filter_out: nan
- platform: xiaomi_miflora
mac_address: ${plant2_mac}
- platform: xiaomi_hhccjcy01
mac_address: $plant2_mac
temperature:
name: ${plant2_upper} Temperature
name: $plant2_upper Temperature
id: ${plant2}_temperature
filters:
- filter_out: nan
- lambda: return x * (9.0/5.0) + 32.0;
unit_of_measurement: "°F"
moisture:
name: ${plant2_upper} Moisture
name: $plant2_upper Moisture
icon: mdi:water-percent
id: ${plant2}_moisture
filters:
- filter_out: nan
illuminance:
name: ${plant2_upper} Illuminance
name: $plant2_upper Illuminance
id: ${plant2}_illuminance
filters:
- filter_out: nan
conductivity:
name: ${plant2_upper} Soil Conductivity
name: $plant2_upper Soil Conductivity
id: ${plant2}_conductivity
filters:
- filter_out: nan
- platform: xiaomi_miflora
mac_address: ${plant3_mac}
- platform: xiaomi_hhccjcy01
mac_address: $plant3_mac
temperature:
name: ${plant3_upper} Temperature
name: $plant3_upper Temperature
id: ${plant3}_temperature
filters:
- filter_out: nan
- lambda: return x * (9.0/5.0) + 32.0;
unit_of_measurement: "°F"
moisture:
name: ${plant3_upper} Moisture
name: $plant3_upper Moisture
icon: mdi:water-percent
id: ${plant3}_moisture
filters:
- filter_out: nan
illuminance:
name: ${plant3_upper} Illuminance
name: $plant3_upper Illuminance
id: ${plant3}_illuminance
filters:
- filter_out: nan
conductivity:
name: ${plant3_upper} Soil Conductivity
name: $plant3_upper Soil Conductivity
id: ${plant3}_conductivity
filters:
- filter_out: nan
- platform: xiaomi_miflora
mac_address: ${plant4_mac}
- platform: xiaomi_hhccjcy01
mac_address: $plant4_mac
temperature:
name: ${plant4_upper} Temperature
name: $plant4_upper Temperature
id: ${plant4}_temperature
filters:
- filter_out: nan
- lambda: return x * (9.0/5.0) + 32.0;
unit_of_measurement: "°F"
moisture:
name: ${plant4_upper} Moisture
name: $plant4_upper Moisture
icon: mdi:water-percent
id: ${plant4}_moisture
filters:
- filter_out: nan
illuminance:
name: ${plant4_upper} Illuminance
name: $plant4_upper Illuminance
id: ${plant4}_illuminance
filters:
- filter_out: nan
conductivity:
name: ${plant4_upper} Soil Conductivity
name: $plant4_upper Soil Conductivity
id: ${plant4}_conductivity
filters:
- filter_out: nan
- platform: xiaomi_miflora
mac_address: ${plant5_mac}
- platform: xiaomi_hhccjcy01
mac_address: $plant5_mac
temperature:
name: ${plant5_upper} Temperature
name: $plant5_upper Temperature
id: ${plant5}_temperature
filters:
- filter_out: nan
- lambda: return x * (9.0/5.0) + 32.0;
unit_of_measurement: "°F"
moisture:
name: ${plant5_upper} Moisture
name: $plant5_upper Moisture
icon: mdi:water-percent
id: ${plant5}_moisture
filters:
- filter_out: nan
illuminance:
name: ${plant5_upper} Illuminance
name: $plant5_upper Illuminance
id: ${plant5}_illuminance
filters:
- filter_out: nan
conductivity:
name: ${plant5_upper} Soil Conductivity
name: $plant5_upper Soil Conductivity
id: ${plant5}_conductivity
filters:
- filter_out: nan
- platform: xiaomi_miflora
mac_address: ${plant6_mac}
temperature:
name: ${plant6_upper} Temperature
id: ${plant6}_temperature
filters:
- filter_out: nan
- lambda: return x * (9.0/5.0) + 32.0;
unit_of_measurement: "°F"
moisture:
name: ${plant6_upper} Moisture
icon: mdi:water-percent
id: ${plant6}_moisture
filters:
- filter_out: nan
illuminance:
name: ${plant6_upper} Illuminance
id: ${plant6}_illuminance
filters:
- filter_out: nan
conductivity:
name: ${plant6_upper} Soil Conductivity
id: ${plant6}_conductivity
filters:
- filter_out: nan
# text_sensor:
# - platform: version
# name: ${devicename} Esphome Version
# - platform: xiaomi_hhccjcy01
# mac_address: $plant6_mac
# temperature:
# name: $plant6_upper Temperature
# id: ${plant6}_temperature
# filters:
# - filter_out: nan
# - lambda: return x * (9.0/5.0) + 32.0;
# unit_of_measurement: "°F"
# moisture:
# name: $plant6_upper Moisture
# icon: mdi:water-percent
# id: ${plant6}_moisture
# filters:
# - filter_out: nan
# illuminance:
# name: $plant6_upper Illuminance
# id: ${plant6}_illuminance
# filters:
# - filter_out: nan
# conductivity:
# name: $plant6_upper Soil Conductivity
# id: ${plant6}_conductivity
# filters:
# - filter_out: nan
+7
View File
@@ -18,6 +18,13 @@ esphome:
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_pass
# Fallback Hotspot (requires "captive_portal:").
ap:
ssid: ${devicename}
password: "12345678"
captive_portal:
# Enable Home Assistant API
api:
+13 -22
View File
@@ -1,27 +1,18 @@
# Shelly 1 Power Module
# Location: Dining Room Light Switch
#
substitutions:
devicename: shelly1_01
upper_devicename: Shelly1 01
hass_light: light.dining_room
<<: !include common/substitutions/shelly1_gpio.yaml
esphome:
name: ${devicename}
platform: ESP8266
board: esp01_1m
board_flash_mode: dout
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_pass
# Enable Home Assistant API
api:
ota:
safe_mode: True
logger:
<<: !include common/esphome/esp8266.yaml
<<: !include common/wifi.yaml
<<: !include common/api.yaml
<<: !include common/ota.yaml
<<: !include common/logger.yaml
script:
- id: hass_light_toggle
@@ -40,13 +31,13 @@ script:
- homeassistant.service:
service: light.turn_on
data:
entity_id: ${hass_light}
entity_id: $hass_light
else:
# Have Home Assistant toggle the light.
- homeassistant.service:
service: light.toggle
data:
entity_id: ${hass_light}
entity_id: $hass_light
else:
# When HA is unavailable, toggle the relay.
- switch.toggle: relay
@@ -54,9 +45,9 @@ script:
binary_sensor:
- platform: gpio
pin:
number: GPIO5
number: $button_pin
inverted: True
name: ${upper_devicename} Button
name: $upper_devicename Button
id: button
filters:
- delayed_on: 10ms
@@ -70,5 +61,5 @@ switch:
# Relay is for internal use only. Do not expose to Home Assistant.
- platform: gpio
id: relay
pin: GPIO4
pin: $relay_pin
restore_mode: ALWAYS_ON
+8 -26
View File
@@ -4,31 +4,13 @@ substitutions:
devicename: shelly1_02
upper_devicename: Shelly1 02
esphome:
name: ${devicename}
platform: ESP8266
board: esp01_1m
board_flash_mode: dout
<<: !include common/substitutions/shelly1_gpio.yaml
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_pass
# Fallback Hotspot (requires "captive_portal:").
ap:
ssid: "shelly1_02" #${devicename}
password: "12345678"
captive_portal:
# Enable Home Assistant API
api:
ota:
safe_mode: True
logger:
<<: !include common/esphome/esp8266.yaml
<<: !include common/wifi.yaml
<<: !include common/api.yaml
<<: !include common/ota.yaml
<<: !include common/logger.yaml
script:
- id: relay_off_after_delay
@@ -75,7 +57,7 @@ binary_sensor:
pin:
number: GPIO5
inverted: True
#name: ${upper_devicename} Button
#name: $upper_devicename Button
id: button
filters:
- delayed_on: 10ms
@@ -102,6 +84,6 @@ switch:
# Physical relay to turn power on and off.
- platform: gpio
id: relay
name: ${devicename}
name: $devicename
pin: GPIO4
restore_mode: ALWAYS_OFF
+20 -9
View File
@@ -13,6 +13,13 @@ esphome:
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_pass
# Fallback Hotspot (requires "captive_portal:").
# ap:
# ssid: ${devicename}
# password: "12345678"
# captive_portal:
# Enable Home Assistant API
api:
@@ -20,16 +27,20 @@ api:
ota:
safe_mode: True
logger:
binary_sensor:
- platform: gpio
pin:
number: GPIO0
mode: INPUT_PULLUP
inverted: True
name: ${upper_devicename} Button
id: ${devicename}_button
on_press:
- switch.toggle: relay
## DISABLED due to the button being broken.
# - platform: gpio
# pin:
# number: GPIO0
# mode: INPUT_PULLUP
# inverted: True
# name: ${upper_devicename} Button
# id: ${devicename}_button
# on_press:
# - switch.toggle: relay
# - platform: status
# name: ${upper_devicename} Status
# id: ${devicename}_status
+12 -11
View File
@@ -44,9 +44,10 @@ binary_sensor:
id: ${devicename}_button
on_press:
- switch.toggle: relay
- platform: status
name: ${upper_devicename} Status
id: ${devicename}_status
# - platform: status
# name: ${upper_devicename} Status
# id: ${devicename}_status
output:
# Register the green LED as a dimmable output ....
@@ -65,12 +66,12 @@ light:
internal: true # hide from Home Assistant
sensor:
- platform: wifi_signal
name: ${devicename}__wifi_signal
update_interval: 30s
# - platform: wifi_signal
# name: ${devicename}__wifi_signal
# update_interval: 30s
- platform: uptime
name: ${devicename}_uptime
# - platform: uptime
# name: ${devicename}_uptime
- platform: cse7766
current:
@@ -87,6 +88,6 @@ switch:
pin: GPIO12
restore_mode: ALWAYS_OFF
text_sensor:
- platform: version
name: ${devicename}_esphome_version
# text_sensor:
# - platform: version
# name: ${devicename}_esphome_version
+12 -11
View File
@@ -44,9 +44,10 @@ binary_sensor:
id: ${devicename}_button
on_press:
- switch.toggle: relay
- platform: status
name: ${upper_devicename} Status
id: ${devicename}_status
# - platform: status
# name: ${upper_devicename} Status
# id: ${devicename}_status
output:
# Register the green LED as a dimmable output ....
@@ -65,12 +66,12 @@ light:
internal: true # hide from Home Assistant
sensor:
- platform: wifi_signal
name: ${devicename}__wifi_signal
update_interval: 30s
# - platform: wifi_signal
# name: ${devicename}__wifi_signal
# update_interval: 30s
- platform: uptime
name: ${devicename}_uptime
# - platform: uptime
# name: ${devicename}_uptime
- platform: cse7766
current:
@@ -87,6 +88,6 @@ switch:
pin: GPIO12
restore_mode: ALWAYS_OFF
text_sensor:
- platform: version
name: ${devicename}_esphome_version
# text_sensor:
# - platform: version
# name: ${devicename}_esphome_version
+13 -14
View File
@@ -34,18 +34,17 @@ api:
ota:
safe_mode: True
binary_sensor:
- platform: status
name: ${upper_devicename} Status
id: ${devicename}_status
# - platform: status
# name: ${upper_devicename} Status
# id: ${devicename}_status
- platform: gpio
pin:
number: GPIO0
mode: INPUT_PULLUP
inverted: True
name: ${upper_devicename} Button
#name: ${upper_devicename} Button
id: ${devicename}_button
on_press:
- switch.toggle: relay
@@ -55,7 +54,7 @@ binary_sensor:
light:
# Expose the "light" to Home Assistant
- platform: monochromatic
name: ${upper_devicename} Green LED
#name: ${upper_devicename} Green LED
id: ${devicename}_green_led
output: green_led
internal: true # hide from Home Assistant
@@ -69,12 +68,12 @@ output:
inverted: True
sensor:
- platform: wifi_signal
name: ${devicename}_wifi_signal
update_interval: 30s
# - platform: wifi_signal
# name: ${devicename}_wifi_signal
# update_interval: 30s
- platform: uptime
name: ${devicename}_uptime
# - platform: uptime
# name: ${devicename}_uptime
- platform: cse7766
current:
@@ -90,6 +89,6 @@ switch:
id: relay
pin: GPIO12
text_sensor:
- platform: version
name: ${devicename}_esphome_version
# text_sensor:
# - platform: version
# name: ${devicename}_esphome_version