Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- esphome:
- name: motor-persienner-2
- esp32:
- board: esp32dev
- framework:
- type: arduino
- # Enable logging
- logger:
- ota:
- password: "aa6d2ef6d6bb0a1f1364b035a68d8686"
- wifi:
- ssid: !secret wifi_ssid
- password: !secret wifi_password
- # Enable fallback hotspot (captive portal) in case wifi connection fails
- ap:
- ssid: "Motor-Persienner-2"
- password: "GB2nclOIrGeg"
- captive_portal:
- # Enable Home Assistant API
- api:
- encryption:
- key: "GAgvGvd1vA2swDSvspxIzSJcObRqh1+JrWTobR8lmzY="
- services:
- - service: set_stepper_target
- variables:
- target: int
- then:
- - stepper.set_target:
- id: blind_stepper
- target: !lambda 'return target;'
- - script.execute: record_stepper_position
- - service: set_stepper_speed
- variables:
- speed: int
- then:
- - stepper.set_speed:
- id: blind_stepper
- speed: !lambda 'return speed;'
- - service: set_stepper_position
- variables:
- stepper_position: int
- then:
- - stepper.report_position:
- id: blind_stepper
- position: !lambda "return stepper_position;"
- - stepper.set_target:
- id: blind_stepper
- target: !lambda "return stepper_position;"
- globals:
- - id: open_position
- type: int
- initial_value: '8000'
- - id: closed_position
- type: int
- initial_value: '1000'
- - id: saved_position
- type: int
- initial_value: '1000'
- restore_value: true
- stepper:
- - platform: uln2003
- id: blind_stepper
- pin_a: GPIO16
- pin_b: GPIO17
- pin_c: GPIO18
- pin_d: GPIO19
- max_speed: 50 steps/s
- acceleration: 200
- deceleration: 200
- sleep_when_done: true
- cover:
- - platform: template
- id: "blind_cover"
- device_class: blind
- name: "Blinds"
- has_position: true
- optimistic: false
- open_action:
- - logger.log: "Opening"
- - cover.template.publish:
- id: blind_cover
- current_operation: OPENING
- - stepper.set_target:
- id: blind_stepper
- target: !lambda "return id(open_position);"
- - while:
- condition:
- lambda: 'return id(blind_stepper).current_position < id(open_position);'
- then:
- - script.execute: update_cover_position
- - delay: 1000 ms
- - script.execute: update_cover_position
- - script.execute: record_stepper_position
- - cover.template.publish:
- id: blind_cover
- current_operation: IDLE
- close_action:
- - logger.log: "Closing"
- - cover.template.publish:
- id: blind_cover
- current_operation: CLOSING
- - stepper.set_target:
- id: blind_stepper
- target: !lambda "return id(closed_position);"
- - while:
- condition:
- lambda: 'return id(blind_stepper).current_position > id(closed_position);'
- then:
- - script.execute: update_cover_position
- - delay: 1000 ms
- - script.execute: update_cover_position
- - script.execute: record_stepper_position
- - cover.template.publish:
- id: blind_cover
- current_operation: IDLE
- position_action:
- - logger.log: "Setting position"
- - stepper.set_target:
- id: blind_stepper
- target: !lambda 'return (float(pos) * float( float(id(open_position)) - float(id(closed_position)) )) + float(id(closed_position));'
- - while:
- condition:
- lambda: 'return id(blind_stepper).current_position != ((float(pos) * float( float(id(open_position)) - float(id(closed_position)) )) + float(id(closed_position)));'
- then:
- - script.execute: update_cover_position
- - delay: 1000 ms
- - script.execute: update_cover_position
- - script.execute: record_stepper_position
- - cover.template.publish:
- id: blind_cover
- current_operation: IDLE
- stop_action:
- - logger.log: "Stopping"
- - cover.template.publish:
- id: blind_cover
- current_operation: IDLE
- - stepper.set_target:
- id: blind_stepper
- target: !lambda 'return id(blind_stepper).current_position;'
- - script.execute: update_cover_position
- - script.execute: record_stepper_position
- sensor:
- - platform: template
- name: "Current stepper position"
- lambda: return id(blind_stepper).current_position;
- update_interval: 5s
- script:
- - id: update_cover_position
- then:
- - cover.template.publish:
- id: blind_cover
- position: !lambda 'return float( float(id(blind_stepper).current_position) - float(id(closed_position))) / float( float(id(open_position)) - float(id(closed_position)) );'
- - id: record_stepper_position
- then:
- - globals.set:
- id: saved_position
- value: !lambda 'return id(blind_stepper).current_position;'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement