#Make a script more universal?

14 messages · Page 1 of 1 (latest)

weary kraken
#

Hey there, I've wrote a little script to toggle my covers. If they are open, they should close and the other way around. And the use it at the dashboard in a button.
Using just the entity_id works nicely.
But: I've got eight covers - so I would like to make the script more dynamic and not write one for each. Simply replacing "rollo_kuchenfenster" with {{ device }} don't work :/
Are there any suggestions how to do it?
Thanks a lot

quaint dagger
#

You want to have one script with parameter to pit cover ID there? Or you want script to toggle all of them at once?

#

If former - use script field.

weary kraken
quaint dagger
#

Yes, something like.
If you post the YAML, I will fix it for you.

weary kraken
# quaint dagger Yes, something like. If you post the YAML, I will fix it for you.
fields:
  coverid:
    description: "entity_id des Rollos"
    example: "rollo_kuchenfenster"
    required: true
sequence:
  - choose:
      - conditions:
          - condition: numeric_state
            entity_id: cover.{{ coverid }}
            attribute: current_position
            below: 100
        sequence:
          - target:
              entity_id: cover.{{ coverid }}
            action: cover.open_cover
      - conditions:
          - condition: state
            entity_id: cover.{{ coverid }}
            state: open
        sequence:
          - target:
              entity_id: button.{{ coverid }}_my_position
            action: button.press

thank you

quaint dagger
#

Hint: use three ticks (on cap with "~") to have it formatted

quaint dagger
#
alias: cover - toggle test
fields:
  cover_id:
    selector:
      entity:
        domain: cover
        multiple: false
    name: Cover
    required: true
sequence:
  - choose:
      - conditions:
          - condition: template
            value_template: "{{ state_attr(cover_id, \"current_position\")|int < 100 }}"
        sequence:
          - target:
              entity_id: "{{ cover_id }}"
            action: cover.open_cover
      - conditions:
          - condition: template
            value_template: "{{ is_state(cover_id, \"on\") }}"
        sequence:
          - target:
              entity_id: "{{ cover_id }}"
            action: cover.close_cover

I replaced last action with close cover - IDK what's that button.

weary kraken
quaint dagger
#

No problem! 🙂

#

Oh wait

#

I edited it. Added filter for entity to accept only covers

weary kraken
#

@quaint dagger The button was for a fixed closing level (I don't like them completly closed) ... I changed your script a bit - and it's wonderfull!

alias: cover - toggle test
fields:
  cover_id:
    selector:
      entity:
        domain: cover
        multiple: false
    name: Cover
    required: true
sequence:
  - choose:
      - conditions:
          - condition: template
            value_template: "{{ state_attr(cover_id, \"current_position\")|int < 100 }}"
        sequence:
          - target:
              entity_id: "{{ cover_id }}"
            action: cover.open_cover
      - conditions:
          - condition: template
            value_template: "{{ state_attr(cover_id, \"current_position\")|int == 100 }}"
        sequence:
          - target:
              entity_id: "{{ cover_id }}"
            action: cover.set_cover_position
            data:
              position: "{{ state_attr(cover_id, \"supported_features\") }}"

One last question if you don't mind: Is there a way to pass the entity_id from the tile card into the script? Just because they will be the same all the time - just out of curiosity

dim quest
#

you'd have to do it in yaml. CLick on "show visual editor" in that widow