Setting multiple covers (or dimmed lights) to different opening states (or dimmings)

HI,
I am succesfully running ESPSomfy and found a way to individually open the shades to different opening states manually by sliding:

type: entities
state_color: true
title: Rolläden
show_header_toggle: true
entities:
  - entity: cover.rolladen
    name: links
    type: custom:slider-entity-row
    step: 1
    full_row: true
    toggle: false
    hide_state: false
    hide_when_off: false
    show_icon: false
    colorize: true
  - entity: cover.l1
    name: L1
    type: custom:slider-entity-row
    step: 1
    toggle: true
  - entity: cover.l2
    name: L2
    type: custom:slider-entity-row
    step: 1
    toggle: true
  - entity: cover.l3
    name: L3
    type: custom:slider-entity-row
    step: 1
    toggle: true
  - entity: cover.l4
    name: L4
    type: custom:slider-entity-row
    step: 1
    toggle: true
  - entity: cover.r1
    name: R1
    type: custom:slider-entity-row
    step: 1
    toggle: true
  - entity: cover.r2
    name: R2
    type: custom:slider-entity-row
    step: 1
    toggle: true
  - entity: cover.r3
    name: R3
    type: custom:slider-entity-row
    step: 1
    toggle: true
  - entity: cover.r4
    name: R4
    type: custom:slider-entity-row
    step: 1
    toggle: true

This is “80%” of what I want :slight_smile: Now I an trying to find a way to have ONE “action/Pushbutton/whatever” to set all covers to a different state at once.
Say cover.l1 to 37, cover.l2 to 54, cover.l3 to 64, … cover.r4 to 60
Reason: In the morning, we open all covers, to get the cool air in. In the Summer we than put them down to a degree, so that we can “see” something in the living room, but do not let the sun shine in too much. In the winter, we have 2 closed and all other open, …

So I personally would have inplemented an array with all shades, and their opening positions and add “Summer”; “Winter” autumn to it, and than run thru it and set the covers to “Summer”, if I decide we have summer :slight_smile:

I have a goot idea how to do such things in perl, e.g. I might find a way in C, but I am totally off here in YAML and HomeAssistant.

I don’t think that one group would help me, as I do want to have each cover set individually, and I absolutely have no idea how to start this. I can cet ONE cover individually, so I could to 8 Buttons and change them manually in Winter/Summer/Autumn, but I have the feeling that this can be done better :slight_smile:

Here the one button solution:


show_name: true
show_icon: true
type: button
hold_action:
  action: none
entity: cover.l1
tap_action:
  action: call-service
  service: espsomfy_rts.set_shade_position
  target:
    entity_id:
      - cover.l1
  data:
    position: 37
name: L1 Rolladen 37%
icon_height: 50px
icon: mdi:window-shutter-settings

any help apprechiated. A 90% start for me would be to have ONE Button which sets all covers to their state (leaving out the summer/autumn/winter idea.)

Future idea would be to automate this according to time in the year and “sun shining”, so it might be an idea to have this as a “somthing” in the background, that is actioned by a helper switch manually so I can than enhance my automation.

thank you
Juergen

Hi Jurgen,
actually i m in the situation, did you end up or finally got the button/switch?
Appreciate in case you got it to share over here.
Thanks

Hi @DaniBCN76 ,
I ended up with two scripts, one for winter, one for summer, which I trigger by either automation or a button. It is not my favourite, but it works.

Juergen

So… I just went through something similar as I have some motors for some curtains that don’t close in the center and so need them to open to different percentages if we want them to be symmetrical in the room. This is a similar issue to what you’re experiencing I think in that you want to be able to open different irl covers to different positions discreetly from a single virtual entity.

Obviously a group will set them all to the same position - and this was the same issue I was facing. But I got thinking, if I can model the state that each curtain should be at for any given overall percentage (which I could - it’s not a complicated equation) then I could create a template cover and discreetly set the position in the “set position”/“close”/“open” action for each irl cover. I think this would work for you too.

The beginning is relatively easy: just create a helper and select template>cover and then start populating your values. When you create the “open”, “close”, and “set_position” actions, just call the service to set each cover discreetly. You can even set some variables at the beginning of the action blocks to do different things based on a template/sensor/etc… - which for you would just be something to test the time of year I imagine.

Let me know if you want more info or are having a hard time with the yaml syntax for some of the tests/sensors. It’s not crazy complicated, but working with arrays and the like in yaml can be funky sometimes. Of course you can always just do a bunch of IF,ELIFs too and that should work just fine! :slight_smile:

Hi @jackson.moormeier,
could you please post the YAML here. I think I could manage to run from there. Although my solution “works”, it does not “feel” right.

thank you
Juergen

So I configured this from the UI cause I wanted to add the entity to a device and (to my knowledge) there isn’t a way to do that yet for templates created via yaml and my situation is different enough that the logic probably isn’t quite the same.

But a pure yaml config for your situation should (not 100% - might be some typos - I haven’t actually set this example up in my env) look something like the following:

template:
  - cover:
      - name: Rolläden
        device_class: shade
        position: >-
          {$ set positions = 
            [
            state_attr('cover.l1','current_position'),
            state_attr('cover.l2','current_position'),
            state_attr('cover.l3','current_position'),
            ...,
            state_attr('cover.ln','current_position')
            ]
          %}

          {{average(positions)}}
        state: >-
          {$ set states = 
            [
            states('cover.l1'),
            states('cover.l2'),
            states('cover.l3'),
            ...,
            states('cover.ln')
            ]
          %}
          {% if 'opening' in state %}
          opening
          {% elif 'closing' in state %}
          closing
          {% endif }
        open_cover:
          variables:
            l1: "{% if states('sensor.season') == 'winter' %} 0 {% else %} 37 {% endif %}" #this is your seasonal logic - make sure you add the "seasons" integration to make this work
            l2: 54
            l3: 64
            ...
            ln: "{% if states('sensor.season') == 'winter' %} 0 {% else %} 60 {% endif %}"
          parallel:
            - action: cover.set_cover_position
              metadata: {}
              data:
                position: "{{l1}}"
              target:
                entity_id: cover.l1
            - action: cover.set_cover_position
              metadata: {}
              data:
                position: "{{l2}}"
              target:
                entity_id: cover.l2
            - action: cover.set_cover_position
              metadata: {}
              data:
                position: "{{l3}}"
              target:
                entity_id: cover.l3
            ...
            - action: cover.set_cover_position
              metadata: {}
              data:
                position: "{{ln}}"
              target:
                entity_id: cover.ln
        close_cover:
          action: cover.close_cover
          metadata: {}
          data: {}
          target: 
            entity_id:
              - cover.l1
              - cover.l2
              - cover.l3
              - ...
              - cover.ln
        stop_cover:
          action: cover.stop_cover
          metadata: {}
          data: {}
          target: 
            entity_id:
              - cover.l1
              - cover.l2
              - cover.l3
              ...
              - cover.ln
        set_cover_position: #This one depends on if you want the absolute maximum of each individual cover (i.e. they're all open 100%) or if you want them to be opened relative to the "maximum" state that y'all like them to be at (i.e. the variables we defined in the "open_cover" action) - I'll do the second option here, cause the first is just a single service call to all of the covers just like the "close" and "stop" actions.
          variables:
            l1: "{% if states('sensor.season') == 'winter' %} 0 {% else %} 37 {% endif %}"
            l2: 54
            l3: 64
            ...
            ln: "{% if states('sensor.season') == 'winter' %} 0 {% else %} 60 {% endif %}"
          parallel:
            - action: cover.set_cover_position
              metadata: {}
              data:
                position: "{{l1*(position/100)}}"
              target:
                entity_id: cover.l1
            - action: cover.set_cover_position
              metadata: {}
              data:
                position: "{{l2*(position/100)}}"
              target:
                entity_id: cover.l2
            - action: cover.set_cover_position
              metadata: {}
              data:
                position: "{{l3*(position/100)}}"
              target:
                entity_id: cover.l3
            ...
            - action: cover.set_cover_position
              metadata: {}
              data:
                position: "{{ln*(position/100)}}"
              target:
                entity_id: cover.ln