Skip to content

Instantly share code, notes, and snippets.

@det-peralta
Created June 3, 2020 11:50
Show Gist options
  • Save det-peralta/54a7e244f449eaddd0e2d7f8490c7c85 to your computer and use it in GitHub Desktop.
Save det-peralta/54a7e244f449eaddd0e2d7f8490c7c85 to your computer and use it in GitHub Desktop.
Esphome + relay + ultrasonic
esphome:
name: airwick_kitchen
platform: ESP8266
board: nodemcuv2
wifi:
ssid: "ssid"
password: "pass"
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "Airwick Kitchen Fallback Hotspot"
password: "pass"
captive_portal:
# Enable logging
logger:
# Enable Home Assistant API
api:
ota:
switch:
- platform: gpio
id: relay
pin: D5
inverted: True
restore_mode: RESTORE_DEFAULT_OFF
- platform: template
name: "switch_airwick"
icon: "mdi:spray"
turn_on_action:
- switch.turn_on: relay
- delay: 500ms
- switch.turn_off: relay
- platform: template
id: ultra_wick
lambda: |-
if (id(ultrasonic_wick).state < 0.07) {
//id(relay).toggle();
id(relay).turn_on();
delay(250);
id(relay).turn_off();
delay(1000);
return true;
}
sensor:
- platform: ultrasonic
trigger_pin: D2
echo_pin: D1
id: ultrasonic_wick
update_interval: '0.5s'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment