Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
## 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

brianhanifin commented Jun 5, 2019

You can simplify the automation triggers. For example you could combine lines 131-142 as the follows:

  trigger
    - platform: state
      entity_id:
        - switch.quietcool_low
        - switch.quietcool_med
        - switch.quietcool_high
      from: 'off'
      to: 'on'

For example, I use this technique in multiple places throughout my house.

Kitchen Motion Sensors (x2)
https://github.com/brianhanifin/Home-Assistant-Config/blob/fac85d2b54984308ae6cca1ab1598e797165f33a/automations/areas/kitchen/kitchen_motion_start.yaml#L7-L13

Leak Detection Sensors (x5)
https://github.com/brianhanifin/Home-Assistant-Config/blob/fac85d2b54984308ae6cca1ab1598e797165f33a/automations/areas/_house/watchdog_leak_sensors.yaml#L6-L16

@Snipercaine
Copy link
Author

Snipercaine commented Jun 6, 2019

@Snipercaine
Copy link
Author

Snipercaine commented Jun 6, 2019

@brianhanifin
Copy link

brianhanifin commented Jun 6, 2019

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

jasonblake46 commented Feb 22, 2021

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

marc-gist commented Dec 28, 2021

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

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