esphome:
name: catgenie
platform: ESP8266
board: d1_mini
on_boot:
- switch.turn_off: water_detect
wifi:
ssid: "COOLDOG1"
password: !secret wifi_password
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "Catgenie Fallback Hotspot"
password: !secret fallback_password
web_server:
port: 80
captive_portal:
# Enable logging
logger:
# Enable Home Assistant API
api:
password: !secret api_password
ota:
password: !secret ota_password
globals:
- id: timeout_shutdown
type: bool
restore_value: no
initial_value: 'false'
binary_sensor:
- platform: gpio
pin:
number: GPIO5 # D1
mode: INPUT
name: "CatGenie Arm"
id: catgenie_arm
filters:
- delayed_on: 50ms
- delayed_off: 50ms
- platform: gpio
pin:
number: GPIO4 # D2
mode: INPUT
name: "CatGenie Bowl"
id: catgenie_bowl
filters:
- delayed_on: 50ms
- delayed_off: 50ms
- platform: gpio
pin:
number: GPIO14 # D5
mode: INPUT
name: "CatGenie Water Valve"
id: catgenie_water_valve
filters:
- delayed_on: 50ms
- delayed_off: 200ms
- platform: gpio
pin:
number: GPIO12 # D6
mode: INPUT
name: "CatGenie Dryer"
id: catgenie_dryer
filters:
- delayed_on: 50ms
- delayed_off: 50ms
- platform: gpio
pin:
number: GPIO13 # D7
mode: INPUT
name: "CatGenie Cat Sensor"
id: catgenie_cat_sensor
filters:
- invert
- platform: gpio
pin:
number: GPIO16 # D0
mode: INPUT
name: "CatGenie Pump"
id: catgenie_pump
filters:
- delayed_on: 50ms
- delayed_off: 250ms
- platform: template
name: "CatGenie Emergency Shutdown"
id: catgenie_emergency_shutdown
lambda: 'return id(timeout_shutdown);'
# do a sanity check on the water valve, once per second
interval:
- interval: 1sec
then:
- if:
condition:
for:
# this value is about 15 seconds longer than it takes to fill the bowl, YMMV
time: 110sec
condition:
binary_sensor.is_on: catgenie_water_valve
then:
# we have a potential flooding problem
- globals.set:
id: timeout_shutdown
value: 'true'
- binary_sensor.template.publish:
id: catgenie_emergency_shutdown
state: ON
# tell the CatGenie we have detected water
- switch.turn_on: water_detect
- logger.log: "Water Valve open for too long! Shutdown triggered"
# politely ask Home Assistant to shut us down by turning of the AC power
- homeassistant.service:
service: switch.turn_off
data_template:
entity_id: 'switch.catgenie_power'
sensor:
- platform: wifi_signal
name: "CatGenie WiFi Signal"
update_interval: 60s
id: catgenie_wifi_signal
# The A0 analog input is connected to water probe 1
# Water probe 2 connects to 3.3VDC
- platform: adc
pin: A0
name: "CatGenie Internal Water Probe Voltage"
update_interval: 0.5s
internal: true
filters:
- multiply: 3.3
- sliding_window_moving_average:
window_size: 20
send_every: 10
on_value_range:
- above: 0.1
then:
- switch.turn_on: water_detect
- below: 0.05
then:
- if:
condition:
lambda: 'return !id(timeout_shutdown);'
then:
- switch.turn_off: water_detect
switch:
- platform: gpio
name: "CatGenie Water Detect"
pin: GPIO2 # D4
id: water_detect