## this part is the ESPhome Yaml file ##
esphome:
name: window_control_linear
platform: ESP8266
board: d1_mini
wifi:
ssid: !secret wifi
password: !secret wifi_pw
# Enable logging
logger:
# Enable Home Assistant API
api:
ota:
output:
- platform: gpio
id: 'win_1'
pin: D1
- platform: gpio
id: 'win_2'
pin: D2
switch:
- platform: output
name: "win1"
output: 'win_1'
id: win1
- platform: output
name: "win2"
output: 'win_2'
id: win2
cover:
- platform: template
name: "Window Control"
id: win_open
optimistic: true
open_action:
- switch.turn_off: win2
- switch.turn_on: win1
- delay: 360s
- switch.turn_off: win1
close_action:
- switch.turn_off: win1
- switch.turn_on: win2
- delay: 360s
- switch.turn_off: win2
stop_action:
- switch.turn_off: win1
- switch.turn_off: win2
binary_sensor:
- platform: gpio
pin: D3
name: "Window Control Button"
filters:
invert:
on_press:
then:
- lambda: |
if (id(win_open).state == cover::COVER_OPEN) {
if (id(win1).state){
// window is opening
id(win_open).stop();
} else {
// window is open and not moving
id(win_open).close();
}
} else {
if (id(win2).state){
// window is closing
id(win_open).stop();
} else {
// win is closed and not moving
id(win_open).open();
}
}
## this part goes in your Configuration.yaml ##
switch:
- platform: mqtt
name: "QuietCool Low"
command_topic: "cmnd/QuietCool/power1"
state_topic: "stat/QuietCool/POWER1"
qos: 1
payload_on: "ON"
payload_off: "OFF"
retain: false
- platform: mqtt
name: "QuietCool Med"
command_topic: "cmnd/QuietCool/power2"
state_topic: "stat/QuietCool/POWER2"
qos: 1
payload_on: "ON"
payload_off: "OFF"
retain: false
- platform: mqtt
name: "QuietCool High"
command_topic: "cmnd/QuietCool/power3"
state_topic: "stat/QuietCool/POWER3"
qos: 1
payload_on: "ON"
payload_off: "OFF"
retain: false
Link for code sliding_window_opener.yaml · GitHub

