Skip to content

Instantly share code, notes, and snippets.

@yufeikang
Created June 27, 2022 02:57
Show Gist options
  • Save yufeikang/aa21ad464a992d4b47f1b0f7ed1ebb79 to your computer and use it in GitHub Desktop.
Save yufeikang/aa21ad464a992d4b47f1b0f7ed1ebb79 to your computer and use it in GitHub Desktop.
esphome fan
esphome:
name: fan
platform: ESP8266
board: esp12e
platformio_options:
board_build.ldscript: eagle.flash.2m.ld
on_loop:
then:
- if:
condition:
sensor.in_range:
id: vcc
below: 3.82
then:
- logger.log: "Enter Deep Sleep"
- deep_sleep.enter:
id: deep_sleep_1
sleep_duration: 20min
else:
- deep_sleep.prevent: deep_sleep_1
wifi:
ssid: "SSID"
password: "PASSOWRD"
deep_sleep:
id: deep_sleep_1
run_duration: 60s
sleep_duration: 20min
fan:
- platform: binary
output: fake_out
name: Fan
restore_mode: RESTORE_DEFAULT_OFF
on_turn_on:
then:
- logger.log: "Turn On Fan"
- script.execute: button_press
- script.wait: button_press
- logger.log: "Turn On Fan End"
on_turn_off:
then:
- logger.log: "Turn Off Fan"
- script.execute: always_press_until_off
- script.wait: always_press_until_off
- logger.log: "Turn Off Fan End"
button:
- platform: template
name: "Fan Speed +"
# icon: "mdi:speed+"
on_press:
- script.execute: button_press
- script.wait: button_press
sensor:
- platform: adc
pin: VCC
id: vcc
name: "Fan VCC"
# internal: true
update_interval: 100ms
# filters:
# - multiply: 3.7
binary_sensor:
- platform: gpio
pin: GPIO5
id: fan_power
name: "Fan Power"
filters:
- delayed_on: 10ms
output:
- id: output_io
platform: gpio
pin: GPIO14
inverted: true
- platform: template
id: fake_out
type: float
write_action:
- logger.log: "NoThing"
script:
- id: button_press
then:
- logger.log: "Press Start"
- output.turn_on: output_io
- delay: 200ms
- output.turn_off: output_io
- logger.log: "Press End"
- id: always_press_until_off
then:
- repeat:
count: 4
then:
- if:
condition:
binary_sensor.is_on: fan_power
then:
- logger.log: "Press Start"
- output.turn_on: output_io
- delay: 100ms
- output.turn_off: output_io
- delay: 500ms # 电源关机有一定延迟
- logger.log: "Press End"
else:
- logger.log: "Check Else"
captive_portal:
# Enable logging
logger:
logs:
sensor: INFO
# Enable Home Assistant API
api:
password: "PASSWORD"
ota:
password: "PASSWORD"
web_server:#
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment