Set cover tilt on window open/close

Opening a window to let air in does not work well if your covers are shut, therefore I wrote a small blueprint to automatically set the tilt after opening/closing a window.

Open your Home Assistant instance and show the blueprint import dialog with a specific blueprint pre-filled.

blueprint:
  name: Window Cover Tilt Control
  domain: automation
  input:
    window_sensor:
      name: Window Sensor
      selector:
        entity:
          domain: binary_sensor
    cover_entity:
      name: Cover
      selector:
        entity:
          domain: cover
    open_tilt:
      name: Open Tilt Position
      default: 100
      selector:
        number:
          min: 0
          max: 100
          unit_of_measurement: "%"
    close_tilt:
      name: Close Tilt Position
      default: 0
      selector:
        number:
          min: 0
          max: 100
          unit_of_measurement: "%"
    position_threshold:
      name: Cover Position Threshold
      description: Only adjust tilt if cover at least that percentage open
      default: 80
      selector:
        number:
          min: 0
          max: 100
          unit_of_measurement: "%"
    open_delay:
      name: Open Delay
      default: 5
      selector:
        number:
          min: 0
          max: 600
          unit_of_measurement: seconds
    close_delay:
      name: Close Delay
      default: 5
      selector:
        number:
          min: 0
          max: 600
          unit_of_measurement: seconds

mode: restart
trigger:
  - platform: state
    entity_id: !input window_sensor
    to: "on"
    for: !input open_delay
    id: opened
  - platform: state
    entity_id: !input window_sensor
    to: "off"
    for: !input close_delay
    id: closed
condition:
  - condition: template
    value_template: "{{ state_attr(cover_entity, 'current_position') | int(0) >= position_threshold | int }}"
variables:
  cover_entity: !input cover_entity
  position_threshold: !input position_threshold
action:
  - choose:
      - conditions:
          - condition: trigger
            id: opened
        sequence:
          - service: cover.set_cover_tilt_position
            target:
              entity_id: !input cover_entity
            data:
              tilt_position: !input open_tilt
      - conditions:
          - condition: trigger
            id: closed
        sequence:
          - service: cover.set_cover_tilt_position
            target:
              entity_id: !input cover_entity
            data:
              tilt_position: !input close_tilt

Had a silly bug in it with the threshold, here’s the fix

blueprint:
  name: Window Cover Tilt Control
  domain: automation
  input:
    window_sensor:
      name: Window Sensor
      selector:
        entity:
          domain: binary_sensor
    cover_entity:
      name: Cover
      selector:
        entity:
          domain: cover
    open_tilt:
      name: Open Tilt Position
      default: 100
      selector:
        number:
          min: 0
          max: 100
          unit_of_measurement: "%"
    close_tilt:
      name: Close Tilt Position
      default: 0
      selector:
        number:
          min: 0
          max: 100
          unit_of_measurement: "%"
    position_threshold:
      name: Cover Position Threshold
      description: Only adjust tilt if cover at least that percentage open
      default: 80
      selector:
        number:
          min: 0
          max: 100
          unit_of_measurement: "%"
    open_delay:
      name: Open Delay
      default: 5
      selector:
        number:
          min: 0
          max: 600
          unit_of_measurement: seconds
    close_delay:
      name: Close Delay
      default: 5
      selector:
        number:
          min: 0
          max: 600
          unit_of_measurement: seconds

mode: restart
trigger:
  - platform: state
    entity_id: !input window_sensor
    to: "on"
    for: !input open_delay
    id: opened
  - platform: state
    entity_id: !input window_sensor
    to: "off"
    for: !input close_delay
    id: closed
condition:
  - condition: template
    value_template: "{{ state_attr(cover_entity, 'current_position') | int(0) <= position_threshold | int }}"
variables:
  cover_entity: !input cover_entity
  position_threshold: !input position_threshold
action:
  - choose:
      - conditions:
          - condition: trigger
            id: opened
        sequence:
          - service: cover.set_cover_tilt_position
            target:
              entity_id: !input cover_entity
            data:
              tilt_position: !input open_tilt
      - conditions:
          - condition: trigger
            id: closed
        sequence:
          - service: cover.set_cover_tilt_position
            target:
              entity_id: !input cover_entity
            data:
              tilt_position: !input close_tilt