Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update ELECTRONICS_ASSEMBLY.md #35

Open
wants to merge 21 commits into
base: master
Choose a base branch
from

Conversation

TonyBrobston
Copy link
Collaborator

In an effort to support battery power, I have been doing some work to update the wiring, which pins are used to open up RST/D0 for Deep Sleep functionality https://esphome.io/components/deep_sleep.html. I also had to change the PWM wire for the servo from D3 to D5. There was some sort of interference on wake that was causing the servo to move when it should not have. I also had to switch which pins the limit switch used, because I needed D0 for Deep Sleep.

This is the rough config I have been testing with. Unfortunately the battery life has only been about a week with very little interaction and the way that manual interaction with ESPHome is, this whole setup is pretty unusable. When the vent goes to sleep, you cannot interact with it. When it wakes up, you can; but that means you have to wait until it wakes up. This is a horrible user experience, but that is just how ESPHome works. It is possible to code a solution for this. I see two options: 1. Add some functionality to ESPHome or Home Assistant to sort of "queue" commands, which are executed on next wake, 2. Write this https://github.com/BrobstonCreations/mqtt-hvac-vent-control as a Home Assistant Integration and write logic to handle this issue. Ideally both would be done, but given the situation with this project I will probably only do the second option; if either. If I could dedicate a few weeks to this work, I imagine I could learn more of the inter-workings of Home Assistant, but I unfortunately have not had the time or enthusiasm to dig in.

substitutions:
  ninety_degree_servo_distance: '0.77'
  servo_transition_length: 7s
  invert_value: '1'

globals:
  - id: servo_distance_to_move
    type: float
    initial_value: '0.01'
  - id: position_to_move_servo_to
    type: float
    initial_value: '0'
  - id: closed_position
    type: float
    restore_value: true
  - id: closed_potentiometer_position
    type: float
    restore_value: true
  - id: opened_position
    type: float
    restore_value: true
  - id: opened_potentiometer_position
    type: float
    restore_value: true

esp8266:
  board: d1_mini
  restore_from_flash: true

esphome:
  name: vent
  on_boot:
    priority: -100
    then:
    - if:
        condition:
          lambda: 'return ESP.getResetReason() != "Deep-Sleep Wake";'
        then:
          - servo.write:
              id: vent_servo
              level: 0
          - delay: 225ms
          - while:
              condition:
                lambda: 'return !id(closed_limit_switch).state;'
              then:
                  - globals.set:
                      id: position_to_move_servo_to
                      value: !lambda 'return id(position_to_move_servo_to) - id(servo_distance_to_move) * ${invert_value};'
                  - servo.write:
                      id: vent_servo
                      level: !lambda 'return id(position_to_move_servo_to);'
                  - delay: 75ms
          - globals.set:
              id: closed_position
              value: !lambda 'return id(position_to_move_servo_to);'
          - globals.set:
              id: closed_potentiometer_position
              value: !lambda 'return id(vent_servo_potentiometer).sample();'
          - delay: 225ms
          - servo.write:
              id: vent_servo
              level: !lambda 'return id(position_to_move_servo_to) + ${ninety_degree_servo_distance} * ${invert_value};'
          - delay: 3s
          - globals.set:
              id: opened_position
              value: !lambda 'return id(position_to_move_servo_to) + ${ninety_degree_servo_distance} * ${invert_value};'
          - globals.set:
              id: opened_potentiometer_position
              value: !lambda 'return id(vent_servo_potentiometer).sample();'

cover:
  - platform: template
    device_class: damper
    id: vent
    name: Vent
    open_action:
      - deep_sleep.prevent: vent_deep_sleep
      - servo.write:
          id: vent_servo
          level: !lambda 'return id(opened_position);'
      - wait_until:
          condition:
            lambda: 'return id(vent_servo).has_reached_target();'
      - deep_sleep.allow: vent_deep_sleep
    close_action:
      - deep_sleep.prevent: vent_deep_sleep
      - servo.write:
          id: vent_servo
          level: !lambda 'return id(closed_position);'
      - wait_until:
          condition:
            lambda: 'return id(vent_servo).has_reached_target();'
      - deep_sleep.allow: vent_deep_sleep
    stop_action:
      - deep_sleep.prevent: vent_deep_sleep
      - servo.write:
          id: vent_servo
          level: !lambda 'return remap(id(vent_servo_potentiometer).state, id(opened_potentiometer_position), id(closed_potentiometer_position), id(opened_position), id(closed_position));'
      - wait_until:
          condition:
            lambda: 'return id(vent_servo).has_reached_target();'
      - deep_sleep.allow: vent_deep_sleep
    tilt_action:
      - deep_sleep.prevent: vent_deep_sleep
      - servo.write:
          id: vent_servo
          level: !lambda 'return remap(tilt, float(1), float(0), id(opened_position), id(closed_position));'
      - wait_until:
          condition:
            lambda: 'return id(vent_servo).has_reached_target();'
      - deep_sleep.allow: vent_deep_sleep
    tilt_lambda: !lambda 'return remap(id(vent_servo_potentiometer).state, id(opened_potentiometer_position), id(closed_potentiometer_position), float(1), float(0));'
    lambda: 'return id(closed_limit_switch).state ? COVER_CLOSED : COVER_OPEN;'

binary_sensor:
  - platform: gpio
    pin:
      number: D7
      mode:
        input: true
        pullup: true
      inverted: true
    id: closed_limit_switch

sensor:
  - platform: adc
    id: vent_servo_potentiometer
    pin: A0
    update_interval: 500ms

servo:
  - id: vent_servo
    output: vent_servo_output
    transition_length: ${servo_transition_length}
    auto_detach_time: 200ms
    restore: true

output:
  - platform: esp8266_pwm
    id: vent_servo_output
    pin: D5
    frequency: 50 Hz

deep_sleep:
  id: vent_deep_sleep
  run_duration: 25s
  sleep_duration: 180s

web_server:

logger:

# Enable Home Assistant API
api:

ota:

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

captive_portal:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant