Skip to content

Instantly share code, notes, and snippets.

@Snipercaine
Last active April 27, 2023 02:20
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Snipercaine/75fcfbb14f8dabc8918d7d6723501821 to your computer and use it in GitHub Desktop.
Save Snipercaine/75fcfbb14f8dabc8918d7d6723501821 to your computer and use it in GitHub Desktop.
## 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
## if you want to use the iOS Notifications (you'll need the iOS app too, duh)##
ios:
push:
categories:
- name: quietcool
identifier: 'quietcool'
actions:
- identifier: 'QC_LOW'
title: 'Fan on Low 1 hr'
- identifier: 'QC_MED'
title: 'Fan on Medium 1 hr'
- identifier: 'QC_HIGH'
title: 'Fan on High 1 hr'
## this part goes in your Automations.yaml ##
- alias: window open when quietcool fan is on
id: openwindowwhenquietcoolfanison2875478945y34y
trigger:
- platform: state
entity_id: switch.quietcool_low
from: 'off'
to: 'on'
- platform: state
entity_id: switch.quietcool_med
from: 'off'
to: 'on'
- platform: state
entity_id: switch.quietcool_high
from: 'off'
to: 'on'
condition:
- condition: state
entity_id: binary_sensor.theater_windows
state: 'off'
action:
- service: cover.open_cover
entity_id: cover.window_control
- alias: window close when quietcool fan is off
id: openwindowwhenquietcoolfanisoff28543545345345
trigger:
- platform: state
entity_id: switch.quietcool_low
from: 'on'
to: 'off'
- platform: state
entity_id: switch.quietcool_med
from: 'on'
to: 'off'
- platform: state
entity_id: switch.quietcool_high
from: 'on'
to: 'off'
condition:
- condition: state
entity_id: binary_sensor.theater_windows
state: 'on'
action:
- service: cover.close_cover
entity_id: cover.window_control
- alias: temperature to start quietcool fan
id: temptostartqcfan7487238945y
trigger:
- platform: time
at: '07:00:00'
- platform: time
at: '20:00:00'
condition:
- condition: numeric_state
entity_id: sensor.yr_temperature
above: 50
below: 68
- condition: numeric_state
entity_id: sensor.upstairs_temp
above: 70
action:
- service: notify.ios_justin_iphone7
data:
title: It's really nice outside
message: Shall I open the window and turn on the fan?
data:
push:
category: "quietcool"
- alias: QCfanlow
id: qcfanlow234234234
trigger:
platform: event
event_type: ios.notification_action_fired
event_data:
actionName: QC_LOW
action:
- service: switch.turn_on
entity_id: switch.quietcool_low
- delay: 01:00:00
- service: switch.turn_off
entity_id: switch.quietcool_low
- alias: QCfanMed
id: qcfanmed234234234
trigger:
platform: event
event_type: ios.notification_action_fired
event_data:
actionName: QC_MED
action:
- service: switch.turn_on
entity_id: switch.quietcool_med
- delay: 01:00:00
- service: switch.turn_off
entity_id: switch.quietcool_med
- alias: QCfanHigh
id: qcfanhigh234234234
trigger:
platform: event
event_type: ios.notification_action_fired
event_data:
actionName: QC_HIGH
action:
- service: switch.turn_on
entity_id: switch.quietcool_high
- delay: 01:00:00
- service: switch.turn_off
entity_id: switch.quietcool_high
@brianhanifin
Copy link

Thank you for all that you have taught me Justin!

Github is awesome for my workflow! I code in VSCode on my laptop, and the VSCode "Source Control" feature to commit changes to my repository with comments (see the photo at the bottom). I use the hide-gitignored extension to hide/unhide all of the files and folders specified in my .gitignore file.

I recently decided to switch to Hass.io so I reinstalled Ubuntu on my server. At first I had trouble setting up the repository because I tried to set it up directly on the server. I found the trick was to set it up from my laptop, using the GitHub Desktop app via the HASS.io SAMBA path. However I had to stop hass.io and rename the homeassistant folder because your repository folder has be created by the app. Then I copied/moved the files over from the backup folder. Then, I could sync it with my GitHub.com repository.

It is really a good feeling to always have my latest config backed up.... even if I have to recreate my secrets file. Let me know if I can help you with getting it setup. I'm on your Discord.

Screen Shot 2019-06-05 at 6 55 23 PM

@jasonblake46
Copy link

Can someone tell me within the first 81 lines what part sets up the window icon in the Lovelace card for this?

@marc-gist
Copy link

with latest esphome this doesn't work, need to change
id(win_open).state to id(win_open).position in the Lamda function

@didi767
Copy link

didi767 commented Apr 27, 2023

Hi guys.

could you please help me to get this to work with a PIR sensor?
thanks, Justin! (@Snipercaine) it works great with the contact sensor, but I have no idea how to accomplish that with PIR to make sure that if there's an obstacle next to the door, it won't close (my dog...)

in the cover, could I achieve that? to have conditions that the PIR will act as the safety mechanism so that it won't close on my dog's head?
`cover:

  • platform: template
    name: "Nella Window Controller"
    id: win_open
    optimistic: true
    open_action:
    • switch.turn_off: win2
    • switch.turn_on: win1
    • delay: 50s
    • switch.turn_off: win1
      close_action:
    • while:
      condition: {lambda: "while (binary_sensor.pir_sensor)"}
      then:

    - condition: state

      # entity_id: sensor.breakbeam_sensor_dist
      ### maybe we need a while loop? to constantly check if the beam is not broken while closing the window?
      # state: "off"
      - switch.turn_on: win2
      - delay: 50s
      - switch.turn_off: win2
    
    stop_action:
    • switch.turn_off: win1
    • switch.turn_off: win2`

am I getting close? :/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment