Skip to content

Instantly share code, notes, and snippets.

@Snipercaine
Created April 5, 2019 19:03
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Snipercaine/7ef43369de1accfa861b765bb1b3319c to your computer and use it in GitHub Desktop.
Save Snipercaine/7ef43369de1accfa861b765bb1b3319c to your computer and use it in GitHub Desktop.
## this part goes in configuration.yaml
input_number:
office_blinds_tilt:
name: Office Blinds Tilt
initial: 0
min: -100
max: 100
step: 1
mode: slider
## this part goes in automations.yaml
- alias: office blinds tilt servo input
id: officeblindstiltservoinput45765934785
trigger:
platform: state
entity_id: input_number.office_blinds_tilt
action:
- service: esphome.office_blinds_control_servo
data_template:
level: '{{ trigger.to_state.state | int }}'
## this part goes in your ESPhome servo_device.yaml
esphome:
name: office_blinds
platform: ESP8266
board: d1_mini
wifi:
ssid: !secret wifi
password: !secret wifi_pw
debug:
# Enable logging
logger:
level: debug
# Enable Home Assistant API & new Service for Servo Control
api:
services:
- service: control_servo
variables:
level: float
then:
- servo.write:
id: ob_tilt
level: !lambda 'return level / 100.0;'
ota:
output:
- platform: gpio
id: 'ob_1'
pin: D1
- platform: gpio
id: 'ob_2'
pin: D2
- platform: esp8266_pwm ## this is for the servo
id: 'ob_t'
pin: D0
frequency: 50 Hz
switch:
- platform: output
name: "ob1"
output: 'ob_1'
id: ob1
- platform: output
name: "ob2"
output: 'ob_2'
id: ob2
servo:
- output: 'ob_t'
id: ob_tilt
binary_sensor:
- platform: gpio
pin: D5
name: "Office Blinds End Stop"
filters:
invert:
on_press:
then:
- switch.turn_off: ob1
- switch.turn_off: ob2
id: ob_end_stop
- platform: gpio
pin: D3
name: "OB Button"
filters:
invert:
on_press:
then:
- lambda: |
if (id(ob_open).state == cover::COVER_OPEN) {
if (id(ob1).state){
// shade is opening
id(ob_open).stop();
} else {
// shade is open and not moving
id(ob_open).close();
}
} else {
if (id(ob2).state){
// shade is closing
id(ob_open).stop();
} else {
// shade is closed and not moving
id(ob_open).open();
}
}
cover:
- platform: template
name: "Office Blinds Full"
id: ob_open
optimistic: true
open_action:
- switch.turn_off: ob2
- switch.turn_on: ob1
## customize this time delay based on how long it takes your blinds to fully lift
- delay: 155s
- switch.turn_off: ob1
close_action:
- switch.turn_off: ob1
- switch.turn_on: ob2
## customize this time delay based on how long it takes your blinds to fully descend
- delay: 122s
- switch.turn_off: ob2
stop_action:
- switch.turn_off: ob1
- switch.turn_off: ob2
- platform: template
name: "Office Blinds Control"
id: ob_open_control
assumed_state: true
open_action:
- switch.turn_off: ob2
- switch.turn_on: ob1
close_action:
- switch.turn_off: ob1
- switch.turn_on: ob2
stop_action:
- switch.turn_off: ob1
- switch.turn_off: ob2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment