Skip to content

Commit

Permalink
refactoring: finished simplifying and merging common code into includes
Browse files Browse the repository at this point in the history
  • Loading branch information
brianhanifin committed Nov 10, 2019
1 parent 142c584 commit 1e4cd87
Show file tree
Hide file tree
Showing 28 changed files with 48 additions and 227 deletions.
5 changes: 4 additions & 1 deletion .vscode/settings.json
@@ -1,6 +1,9 @@
{
"cSpell.ignoreWords": [
"espressif",
"pioenvs"
"luntak",
"pioenvs",
"sonoff",
"tuya"
]
}
12 changes: 9 additions & 3 deletions README.md
Expand Up @@ -13,14 +13,20 @@ I started with the [ESP32 Bluetooth Low Energy Tracker Hub][esphome-ble-hub] exa
### dog_water.yaml
A **FAILED** attempt at making a dog water bowl sensor with an ESP8266 board. By inserting two insulated wires (cut at the end) into the bowl I hoped it would become a "switch" that would turn on and off when submerged in the water or dry. It did not work, someday I will try to find a more reliable way to sense water.

### Irrigation Controller: irrigation.yaml
#### [Sonoff 4ch Pro R2][esphome-sonoff4pro]
Our battery and cloud powered Melnor Raincloud/Aquatimer has been flaky off and on for years. Now even new batteries aren't resolving the problem. Also, there appears to be possible battery acid inside the battery compartment. I suspect the wireless radio may be dead despite being able to manually toggle the valves.

The ESPHome projects I have done around our house have been extremely reliable and useful additions to our smart home. Recently, the ESPHome site featured a user's project that turned a Sonoff 4 channel Pro unit into an irrigation controller, which inspired me. That project features a nifty touch screen display. But I want to start simple. We can start with a dumb relay controller, with the brains being controlled from Home Assistant.

### Standard plugs: plug01.yaml - plug03.yaml
#### ZooZee brand Tuya plugs
These are simple round wall plug were flashed with over the air with tasmota-convert, then ESPHome was uploaded via the Tasmota UI. The ESPHome code attempts to recreate their original functionality.

### Hot Water Pump: plug05.yaml
This plug controls the whole house hot water recirculation pump. When we turn this on we don't want it to keep running forever. So I set a timeout that turns the pump off after 10 minutes. This timeout is a backup to the Home Assistant automation that automatically turns it off after 5 minutes.

### Standard plugs: plug06.yaml - plug08.yaml
### Standard plugs: plug04.yaml - plug07.yaml
#### Luntak brand Tuya plugs
These are simple round wall plugs were flashed with over the air with tasmota-convert, then ESPHome was uploaded via the Tasmota UI. The ESPHome code attempts to recreate their original functionality.

Expand All @@ -38,7 +44,7 @@ The ESPHome code gets the humidity from Home Assistant and handles all automatio
The switch will also fail gracefully when Home Assistant is not available to act as a dumb toggle switch.

### Standard plugs: sonoff_basic_01.yaml, sonoff_basic_02.yaml
These are Sonoff Basics, with plugs on either side. One is used to switch on a floor fan, and the other is being reserved possibly to control a bathroom vent fan.
These are [Sonoff Basics][esphome-sonoff-basic], with plugs on either side. One is used to switch on a floor fan, and the other is being reserved possibly to control a bathroom vent fan.

### Power monitoring ONLY plugs: sonoff_s31_01.yaml, sonoff_s31_02.yaml
These are Sonoff S31 plugs are set to power on a boot, their physical "power" push buttons are disabled, and the virtual button hidden from Home Assistant. They are being used to monitor the power usage of a clothes washing machine and my wife's Glowforge laser cutter. With this data, I can create automations to alert us when the wash cycle or the laser cycle is complete.
Expand All @@ -51,7 +57,6 @@ These are Sonoff POWs and Sonoff S31s. The code attempts to recreate their funct
Ask on the [ESPHome #general channel on Discord][discord]. Use `#BrianHanifin` to tag me.



[commits-shield]: https://img.shields.io/github/commit-activity/m/brianhanifin/esphome-config.svg
[commits]: https://github.com/brianhanifin/esphome-config/commits/master
[github-last-commit]: https://img.shields.io/github/last-commit/BrianHanifin/esphome-config.svg?style=plasticr
Expand All @@ -65,4 +70,5 @@ Ask on the [ESPHome #general channel on Discord][discord]. Use `#BrianHanifin` t


[esphome-ble-hub]:https://esphome.io/components/esp32_ble_tracker.html
[esphome-sonoff4pro]:https://esphome.io/devices/sonoff_4ch.html
[esphome-sonoff-basic]:https://esphome.io/devices/sonoff_basic.html
Expand Up @@ -2,6 +2,3 @@
button_gpio: GPIO0
led_status_gpio: GPIO13
relay_gpio: GPIO12

# rx_gpio: GPIO3
# tx_gpio: GPIO1
2 changes: 0 additions & 2 deletions common/substitutions/gpio/sonoffpow.yaml

This file was deleted.

1 change: 1 addition & 0 deletions common/substitutions/gpio/tuya_plug.yaml
@@ -1,4 +1,5 @@
---
# These brands share the same pins: Luntak, ZooZee.
button_gpio: GPIO13
led_status_gpio: GPIO2
relay_gpio: GPIO15
File renamed without changes.
File renamed without changes.
File renamed without changes.
28 changes: 0 additions & 28 deletions common/templates/sonoff_s31.yaml

This file was deleted.

47 changes: 0 additions & 47 deletions dog_water.yaml

This file was deleted.

6 changes: 3 additions & 3 deletions irrigation.yaml
Expand Up @@ -23,7 +23,7 @@ esphome:
platform: ESP8266
board: esp01_1m

<<: !include common/esphome/led/status_with_api.yaml
<<: !include common/esphome/leds/status_with_api.yaml

<<: !include common/wifi.yaml
<<: !include common/ota.yaml
Expand Down Expand Up @@ -120,10 +120,10 @@ globals:

# Common housekeeping components.
output:
<<: !include common/output/status_led.yaml
<<: !include common/outputs/status_led.yaml

light:
<<: !include common/light/status_led.yaml
<<: !include common/lights/status_led.yaml

binary_sensor:
- !include common/binary_sensors/status.yaml
Expand Down
2 changes: 1 addition & 1 deletion plug01.yaml
Expand Up @@ -7,4 +7,4 @@ substitutions:

<<: !include common/substitutions/gpio/tuya_plug.yaml

<<: !include common/templates/tuya_plug.yaml
<<: !include common/templates/plug.yaml
2 changes: 1 addition & 1 deletion plug02.yaml
Expand Up @@ -7,4 +7,4 @@ substitutions:

<<: !include common/substitutions/gpio/tuya_plug.yaml

<<: !include common/templates/tuya_plug.yaml
<<: !include common/templates/plug.yaml
2 changes: 1 addition & 1 deletion plug03.yaml
Expand Up @@ -7,4 +7,4 @@ substitutions:

<<: !include common/substitutions/gpio/tuya_plug.yaml

<<: !include common/templates/tuya_plug.yaml
<<: !include common/templates/plug.yaml
2 changes: 1 addition & 1 deletion plug04.yaml
Expand Up @@ -7,4 +7,4 @@ substitutions:

<<: !include common/substitutions/gpio/tuya_plug.yaml

<<: !include common/templates/tuya_plug.yaml
<<: !include common/templates/plug.yaml
2 changes: 1 addition & 1 deletion plug05.yaml
Expand Up @@ -7,4 +7,4 @@ substitutions:

<<: !include common/substitutions/gpio/tuya_plug.yaml

<<: !include common/templates/tuya_plug.yaml
<<: !include common/templates/plug.yaml
2 changes: 1 addition & 1 deletion plug06.yaml
Expand Up @@ -7,4 +7,4 @@ substitutions:

<<: !include common/substitutions/gpio/tuya_plug.yaml

<<: !include common/templates/tuya_plug.yaml
<<: !include common/templates/plug.yaml
2 changes: 1 addition & 1 deletion plug07.yaml
Expand Up @@ -7,4 +7,4 @@ substitutions:

<<: !include common/substitutions/gpio/tuya_plug.yaml

<<: !include common/templates/tuya_plug.yaml
<<: !include common/templates/plug.yaml
57 changes: 4 additions & 53 deletions sonoff_basic_01.yaml
Expand Up @@ -2,58 +2,9 @@
# Sonoff Basic Power Module
#
substitutions:
devicename: sonoff_basic_01
upper_devicename: Sonoff Basic 01
project: Sonoff Basic 01
id: sonoff_basic_01

esphome:
name: ${devicename}
platform: ESP8266
board: esp01_1m
board_flash_mode: dout
<<: !include common/substitutions/gpio/sonoff.yaml

wifi:
ssid: !secret wifi_ssid
password: !secret wifi_pass

# Enable Home Assistant API
api:

ota:
safe_mode: True

binary_sensor:
- 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

output:
# Register the green LED as a dimmable output ....
- platform: esp8266_pwm
id: green_led
pin:
number: GPIO13
inverted: True

light:
# ... and then make a light out of it.
- platform: monochromatic
name: ${upper_devicename} Green LED
id: ${devicename}_green_led
output: green_led
internal: true # hide from Home Assistant

switch:
- platform: gpio
name: ${upper_devicename}
id: relay
pin: GPIO12
restore_mode: ALWAYS_OFF
<<: !include common/templates/plug.yaml
68 changes: 4 additions & 64 deletions sonoff_basic_02.yaml
Expand Up @@ -2,69 +2,9 @@
# Sonoff Basic Power Module
#
substitutions:
devicename: sonoff_basic_02
upper_devicename: Sonoff Basic 02
project: Sonoff Basic 02
id: sonoff_basic_02

esphome:
name: ${devicename}
platform: ESP8266
board: esp01_1m
board_flash_mode: dout
<<: !include common/substitutions/gpio/sonoff.yaml

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:

ota:
safe_mode: True

logger:

binary_sensor:
## 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

output:
# Register the green LED as a dimmable output ....
- platform: esp8266_pwm
id: green_led
pin:
number: GPIO13
inverted: True

light:
# ... and then make a light out of it.
- platform: monochromatic
name: ${upper_devicename} Green LED
id: ${devicename}_green_led
output: green_led
internal: true # hide from Home Assistant

switch:
- platform: gpio
name: ${upper_devicename}
id: relay
pin: GPIO12
restore_mode: ALWAYS_ON
<<: !include common/templates/plug.yaml
4 changes: 2 additions & 2 deletions sonoff_pow_01.yaml
Expand Up @@ -5,6 +5,6 @@ substitutions:
project: Sonoff POW 01
id: sonoff_pow_01

<<: !include common/substitutions/gpio/sonoffpow.yaml
<<: !include common/substitutions/gpio/sonoff.yaml

<<: !include common/templates/sonoff_pow.yaml
<<: !include common/templates/sonoff_power_monitor.yaml
4 changes: 2 additions & 2 deletions sonoff_pow_02.yaml
Expand Up @@ -5,6 +5,6 @@ substitutions:
project: Sonoff POW 02
id: sonoff_pow_02

<<: !include common/substitutions/gpio/sonoffpow.yaml
<<: !include common/substitutions/gpio/sonoff.yaml

<<: !include common/templates/sonoff_pow.yaml
<<: !include common/templates/sonoff_power_monitor.yaml
4 changes: 2 additions & 2 deletions sonoff_s31_01.yaml
Expand Up @@ -5,6 +5,6 @@ substitutions:
project: Sonoff S31 01
id: sonoff_s31_01

<<: !include common/substitutions/gpio/sonoffs31.yaml
<<: !include common/substitutions/gpio/sonoff.yaml

<<: !include common/templates/sonoff_s31_always_on.yaml
<<: !include common/templates/sonoff_power_monitor_always_on.yaml
4 changes: 2 additions & 2 deletions sonoff_s31_02.yaml
Expand Up @@ -5,6 +5,6 @@ substitutions:
project: Sonoff S31 02
id: sonoff_s31_02

<<: !include common/substitutions/gpio/sonoffs31.yaml
<<: !include common/substitutions/gpio/sonoff.yaml

<<: !include common/templates/sonoff_s31_always_on.yaml
<<: !include common/templates/sonoff_power_monitor_always_on.yaml
4 changes: 2 additions & 2 deletions sonoff_s31_03.yaml
Expand Up @@ -5,6 +5,6 @@ substitutions:
project: Sonoff S31 03
id: sonoff_s31_03

<<: !include common/substitutions/gpio/sonoffs31.yaml
<<: !include common/substitutions/gpio/sonoff.yaml

<<: !include common/templates/sonoff_s31.yaml
<<: !include common/templates/sonoff_power_monitor.yaml

0 comments on commit 1e4cd87

Please sign in to comment.