143 lines
3.1 KiB
YAML
143 lines
3.1 KiB
YAML
# ----------- User configutaion ------------------
|
|
substitutions:
|
|
devicename: watercontrol
|
|
upper_devicename: Watercontrol
|
|
pin_cold: D1
|
|
init_cold: '216.08'
|
|
pin_hot: D2
|
|
init_hot: '112.3'
|
|
water_open_pin: D5
|
|
water_close_pin: D3
|
|
ultrasonic_echo_pin: D6
|
|
ultrasonic_trig_pin: D7
|
|
# ----------- /User configutaion ------------------
|
|
|
|
# Need to turn off logging because senseair uses uart and have conflicts with logging
|
|
logger:
|
|
|
|
esphome:
|
|
name: $devicename
|
|
platform: ESP8266
|
|
board: d1_mini
|
|
|
|
wifi:
|
|
ssid: !secret wifi_24_name
|
|
password: !secret wifi_24_pass
|
|
|
|
# Enable fallback hotspot (captive portal) in case wifi connection fails
|
|
ap:
|
|
ssid: "$upper_devicename Fallback Hotspot"
|
|
password: !secret esphome_captive_pass
|
|
|
|
captive_portal:
|
|
|
|
# Enable Home Assistant API
|
|
api:
|
|
password: !secret esphome_pass
|
|
|
|
ota:
|
|
password: !secret esphome_pass
|
|
|
|
globals:
|
|
- id: water_state
|
|
type: bool
|
|
restore_value: yes
|
|
initial_value: 'true'
|
|
- id: counter_cold_value
|
|
type: float
|
|
restore_value: yes
|
|
initial_value: $init_cold
|
|
- id: counter_hot_value
|
|
type: float
|
|
restore_value: yes
|
|
initial_value: $init_hot
|
|
|
|
binary_sensor:
|
|
- platform: gpio
|
|
id: pulse_cold
|
|
pin:
|
|
number: $pin_cold
|
|
mode: INPUT_PULLUP
|
|
filters:
|
|
- delayed_on: 1s
|
|
- delayed_off: 1s
|
|
on_press:
|
|
then:
|
|
- lambda: 'id(counter_cold_value) += 0.01;'
|
|
|
|
- platform: gpio
|
|
id: pulse_hot
|
|
pin:
|
|
number: $pin_hot
|
|
mode: INPUT_PULLUP
|
|
filters:
|
|
- delayed_on: 1s
|
|
- delayed_off: 1s
|
|
on_press:
|
|
then:
|
|
- lambda: 'id(counter_hot_value) += 0.01;'
|
|
|
|
sensor:
|
|
- platform: uptime
|
|
name: "$upper_devicename Uptime"
|
|
|
|
- platform: template
|
|
name: "counter_hot"
|
|
accuracy_decimals: 2
|
|
lambda: |-
|
|
return id(counter_hot_value);
|
|
update_interval: 60s
|
|
|
|
- platform: template
|
|
name: "counter_cold"
|
|
accuracy_decimals: 2
|
|
lambda: |-
|
|
return id(counter_cold_value);
|
|
update_interval: 60s
|
|
|
|
- platform: ultrasonic
|
|
trigger_pin: $ultrasonic_trig_pin
|
|
echo_pin: $ultrasonic_echo_pin
|
|
name: "Toilet Distance"
|
|
update_interval: 5s
|
|
|
|
switch:
|
|
- platform: gpio
|
|
pin:
|
|
number: $water_open_pin
|
|
inverted: yes
|
|
id: water_open
|
|
interlock: [water_close]
|
|
|
|
- platform: gpio
|
|
pin:
|
|
number: $water_close_pin
|
|
inverted: yes
|
|
id: water_close
|
|
interlock: [water_open]
|
|
|
|
- platform: template
|
|
name: "Water valve"
|
|
icon: "mdi:cup-water"
|
|
lambda: |-
|
|
return id(water_state);
|
|
turn_on_action:
|
|
- switch.turn_on: water_open
|
|
- delay: 5s
|
|
- switch.turn_off: water_open
|
|
- lambda: 'id(water_state) = true;'
|
|
turn_off_action:
|
|
- switch.turn_on: water_close
|
|
- delay: 5s
|
|
- switch.turn_off: water_close
|
|
- lambda: 'id(water_state) = false;'
|
|
|
|
- platform: template
|
|
name: "Reset"
|
|
turn_on_action:
|
|
- lambda: 'id(counter_cold_value) = 216.08;'
|
|
- lambda: 'id(counter_hot_value) = 112.3;'
|
|
turn_off_action:
|
|
- lambda: 'id(counter_cold_value) = 216.08;'
|
|
- lambda: 'id(counter_hot_value) = 112.3;'
|