Help with automation for shades

I had an automation in WebCore/Smartthings that I am trying to replicate to some degree in Home Assistant and I am unsure how to do it.

  1. close all the shades - This is done and easy but sometimes the shades do not all close

For this reason I need some kind of cleanup automation

  1. Check status of shades, if not all closed, close the ones that are still open - This is the part I can’t seem to get going. Can someone give some advice or point me in the direction I can best accomplish this?

Thanks.

Post the automation you currently have, that closes the shades, and we can help you modify it so that it closes any remaining open shades.

- id: '1627678559467'
  alias: Close Shades @ sunset
  description: ''
  trigger:
  - platform: sun
    event: sunset
  condition:
  - type: is_not_open
    condition: device
    device_id: 8bffaba45f27330bc6335c8bf285d9fe
    entity_id: binary_sensor.office_window_left_contact
    domain: binary_sensor
  - type: is_not_open
    condition: device
    device_id: 90f62bfab72219b88e528288245e0538
    entity_id: binary_sensor.office_window_right_contact
    domain: binary_sensor
  - type: is_not_open
    condition: device
    device_id: 60c0d0e8a87c26cb6eec13bd2394ecb5
    entity_id: binary_sensor.kitchen_window_left_contact
    domain: binary_sensor
  - type: is_not_open
    condition: device
    device_id: ded875100312bc392d7daabf3640b450
    entity_id: binary_sensor.kitchen_window_right_contact
    domain: binary_sensor
  - condition: device
    type: is_on
    device_id: a1aaa7dc048c9dc2e389d40290f07d52
    entity_id: switch.auto_shades
    domain: switch
  action:
  - type: turn_off
    device_id: f41453abe3c7c5c50a1d9f75d0af725e
    entity_id: switch.kitchen_north_2
    domain: switch
  - type: turn_off
    device_id: 983d0677e10acec4a427f1c7bab63dd0
    entity_id: switch.office_shades
    domain: switch
  - type: turn_off
    device_id: 09a49cff8de11bd3bce72886394ae0de
    entity_id: switch.kitchen_east_2
    domain: switch
  - device_id: 979e00ee2a88b9ae4c7decb3bc03fb03
    domain: cover
    entity_id: cover.dining_room_shade_3
    type: set_position
    position: 35
  - type: turn_off
    device_id: c6ca5ac0efa6b44caf026a45089eb6db
    entity_id: switch.living_room_left_2
    domain: switch
  - type: turn_off
    device_id: 0ffe4c7037118c1f9eb523bc41bcaa1e
    entity_id: switch.living_room_right_2
    domain: switch
  - type: turn_off
    device_id: 16763edfe2ee88abc00ad5bd9ea7a44c
    entity_id: switch.bedroom_south_2
    domain: switch
  - type: turn_off
    device_id: 6aefb8caef6c2630329fa101e7b53d40
    entity_id: switch.bedroom_l
    domain: switch
  - type: turn_off
    device_id: b65064ce3bd538fe3aef1416a2e55592
    entity_id: switch.bedroom_r
    domain: switch
  mode: single

I have two questions:

  1. You mentioned “shades” so I assumed you have more than one shade. However, the automation contains only one cover entity named cover.dining_room_shade_3. Are there other cover entities that are simply not shown in the automation or do any of the switches represent a shade? In other words, do all of the switches represent shades?

  2. Does cover.dining_room_shade_3 have an attribute that indicates the cover’s current position? Maybe it’s called position or current_position?

Question: what kind of shade communication is used that sometimes not all close? I have integrations that cannot handle firing too many commands at the same time, I can get that to always work by putting in a delay of a second. If it uses one way radio communication that sometimes fails without Home Assistant knowing, or if thay communicate back, the solution would also be different.

But in most cases if the problems occur frequently, are not specific to this one automation and are persistent, I would create template covers with the “fix” built in, and hide the original cover. Then you can from then on stop worrying about all automations that operate the blind.

Zwave - this is a klugy implementation from Somfy. They dont even offer these anymore.

Are they included with S0 security? I’ve had communication problems with that before, that disappeared when I included them without security (less scary than it sounds).

How do I check this on HA? I knew how to do it on Smartthings. Which, to clarify, these shades did the same thing on ST. That’s why I chalk it up to a problem with the shades.

Yes

I just set the position of one specifically.

Also, I can poll the position on them, yes.

What Am looking for is general guidance. I can check position so can I, either in a single automation or two, check the position, issue a command to set position or open or close or whatever and then loop it till it reaches the position I want? How would I set that up?

Here’s what I have in mind:

The automation creates a list of the shades (switches) that are open and then proceeds to close each one in sequence. It closes a shade and then waits for the shade’s state to indicate it has closed. However, it will only wait up to 5 seconds (or whatever duration you think is reasonable) and then it will repeat the closing/waiting process. It will try a total of three times before it gives up and then moves on to closing the next open shade.

The cover is handled the same way but separately because it uses a different service call to set its position.

Here’s an example:

- id: 'close_shades_at_sunset'
  alias: Close Shades at Sunset

  variables:
    windows:
    - binary_sensor.office_window_left_contact
    - binary_sensor.office_window_right_contact
    - binary_sensor.kitchen_window_left_contact
    - binary_sensor.kitchen_window_right_contact
    shade_switches:
    - switch.kitchen_north_2
    - switch.office_shades
    - switch.kitchen_east_2
    - switch.living_room_left_2
    - switch.living_room_right_2
    - switch.bedroom_south_2
    - switch.bedroom_l
    - switch.bedroom_r
    open_shade_switches: >
      {{ expand(shades_switches) | selectattr('state', 'eq', 'on')
          | map(attribute='entity_id') | list  }}
    shade_cover: cover.dining_room_shade_3
    shade_cover_position: 35

  trigger:
  - platform: sun
    event: sunset

  condition:
  - "{{ expand(windows) | selectattr('state', 'eq', 'on') | list | count == 0 }}"
  - "{{ is_state('switch.auto_shades', 'on') }}"

  action:
  - repeat:
      for_each: '{{ open_shade_switches }}'
      sequence:
      - repeat:
          sequence:
          - service: switch.turn_off
            target:
              entity_id: '{{ repeat.item }}'
          - wait_template: "{{ is_state(repeat.item, 'off') }}"
            timeout:
              seconds: 5
          until: "{{ is_state(repeat.item, 'off') or repeat.index >= 3 }}"

  - repeat:
      sequence:
      - service: cover.set_cover_position
        target:
          entity_id: '{{ shade_cover }}'
        data:
          position: '{{ shade_cover_position }}'
      - wait_template: "{{ is_state_attr(shade_cover, 'current_position', shade_cover_position) }}"
        timeout:
          seconds: 5
      until: "{{ is_state_attr(shade_cover, 'current_position', shade_cover_position) or repeat.index >= 3 }}"
  mode: single

NOTE

The condition does the same thing as in your automation. It confirms no windows are open and switch.auto_shades is on.

The automation has passed the configuration check but is untested because I don’t have an appropriate testing environment for it.

The automation can be enhanced (if needed) so that the closing of open shades occurs in parallel as opposed to in sequence.

1 Like

Depends on the integration you use. In the zwave2mqtt addon configuration it is shown in the list.

I am just using Zwavejs. Never could get zwave2mqtt to work.

Did you have a chance to test the automation I posted above?

Yeah, it doesn’t seem to work. I am still trying to figure out how to make this happen. Previously I would

issue a command to close all the shades
set a bool to yes
wait 5 min
check bool, if yes
Check the shades to make sure they are at the correct place if not fix it
check bool, still yes
check shades again, if all is well
set bool to no and that ends the automation

Check the automation’s trace. Let me know at which point it fails to work as expected.