Conditional cover

I got a high skylight window (Velux) and installed a linear actuator to open and close it remotely. Open en closing works fine but when the window is locked it’s still possible to activate the cover. I mounted a simple doorsensor on the lock handle.
How do I code that the cover can’t be used if the handle is locked?
My code:

esphome:
  name: keukenraam

esp8266:
  board: esp01_1m

# Enable logging
logger:

# Enable Home Assistant API
api:

ota:
  password: "**************************"

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  manual_ip:
    # Set this to the IP of the ESP
    static_ip: 192.168.0.116
    # Set this to the IP address of the router. Often ends with .1
    gateway: 192.168.0.1
    # The subnet of the network. 255.255.255.0 works for most home networks.
    subnet: 255.255.255.0
  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Keukenraam Fallback Hotspot"
    password: "*************"

captive_portal:
    
output:
  - platform: esp8266_pwm
    pin: 2
    frequency: 1000 Hz
    id: sh_speed_pin
  - platform: gpio
    pin: 4
    id: sh_direction_pin1
    inverted: true
  - platform: gpio
    pin: 5
    id: sh_direction_pin2
    inverted: true

cover:
  - platform: template
    device_class: window
    name: "Velux"
    id: velux
    open_action:
      
      - output.turn_on: sh_direction_pin2
      - output.turn_on: sh_speed_pin
      - delay: 15s
      - output.turn_off: sh_direction_pin2
      - output.turn_off: sh_speed_pin
    close_action:
      - output.turn_on: sh_direction_pin1
      - output.turn_on: sh_speed_pin
      - delay: 15s
      - output.turn_off: sh_direction_pin1
      - output.turn_off: sh_speed_pin
      
     
    stop_action:
      - output.turn_off: sh_direction_pin1
      - output.turn_off: sh_direction_pin2
      - output.turn_off: sh_speed_pin
    optimistic: true  
    
binary_sensor:
  - platform: gpio
    pin:
      number: 0
      mode: INPUT_PULLUP
    name: "sensor velux"
    device_class: window

Use a template cover. Template Cover - Home Assistant

So I have to make the gpio pins in ESPhome switches and create a cover in HA config yalm?

You should be able to do it in ESPHome with a condition (I think), e.g.

    open_action:
      - if:
          condition:
            binary_sensor.is_off: velux # or on 
          then:
            - output.turn_on: sh_direction_pin2
            - output.turn_on: sh_speed_pin
            - delay: 15s
            - output.turn_off: sh_direction_pin2
            - output.turn_off: sh_speed_pin

Add the id to the binary sensor:

binary_sensor:
  - platform: gpio
    pin:
      number: 0
      mode: INPUT_PULLUP
    name: "sensor velux"
    id: velux
    device_class: window

I assume that is your lock sensor (or is it your window open / closed sensor)?

If not the lock sensor and this sensor is only in home assistant (I couldn’t see it in your esphome config) then you will have to bring it into esphome with this:

And use that sensor in the condition instead.

1 Like

It is a lock sensor. I will give it a try and let you know if it works. Thanks!

I just did a quick test and it works just I liked it to do. Thanks a lot.

1 Like

Is it also possible to have the actuator stop when motor current exceeds a load threshold?

I put an ACS712 on the motor wire to detect if the actuator load is too high by measuring current.

I’d like the door to stop and maybe stop and try to open for 1s to unload the actuator.