Skript - Template: cover position

Hello, community,

New day, new question. I’m hoping someone can help me.

In a script I try to set the position, depending on the input field “position”, either by this value or if the field is empty, by a value from an “input_number” field.

As I said, I am interested in the template in the “position:” section - everything else works fine.

Does it not work at all, or am I making an error?

#scripts.yaml

script_rollo_test:
  alias: Setzt definierte Rollos Test
  icon: "mdi:script-text-outline"
  description: 'Setzt definierte Rollos Test'

  fields:
    title:
      description: 'The title of the notification'
      example: 'State change'
    message:
      description: 'The message content'
      example: 'The light is on!'
    position:
      description: 'New position of cover'
      example: 30
    orientation:
      description: 'geographic direction'
      example: 'all'

  # Öffne die Rollos, welche für die Automatisierung ausgewählt wurden
  sequence:
    - service_template: >
          {% if is_state('input_boolean.automatisierung_gaestezimmer', 'on') and
            (states.cover.rollo_gaestezimmer.attributes.current_position|int != position) and
            (position == 0) and
            (orientation == 'all' or orientation == 'east' or orientation == 'gast') %}
              cover.close_cover
          {% elif is_state('input_boolean.automatisierung_gaestezimmer', 'on') and
            (states.cover.rollo_gaestezimmer.attributes.current_position|int != position) and
            (position == 100) and
            (orientation == 'all' or orientation == 'east' or orientation == 'gast') %}
              cover.open_cover
          {% elif is_state('input_boolean.automatisierung_gaestezimmer', 'on') and
            (states.cover.rollo_gaestezimmer.attributes.current_position|int != position) and
            (position == '') and
            (orientation == 'all' or orientation == 'east' or orientation == 'gast') %}
              cover.set_cover_position
          {% else %}
            script.script_continue
          {% endif %}
      data_template:
        entity_id: >
          {% if is_state('input_boolean.automatisierung_gaestezimmer', 'on') and
            (states.cover.rollo_gaestezimmer.attributes.current_position|int != position) and
            (orientation == 'all' or orientation == 'east' or orientation == 'gast') %}
              cover.rollo_gaestezimmer
          {% else %}
            script.script_continue
          {% endif %}
        position: >
          {% if position == '' %}
            states.input_number.schliessposition_gaestezimmer.state | int
          {% else %}
            position | int
          {% endif %}

Best regards Markus

Hello community,

perhaps my question is not entirely understandable.

I have a problem with the template at the “Position” part. If a value is passed in the field: “position”, the rollon should be set to this position. If no value is passed, the position should be set to the value of an “input_number” field.

        position: >
          {% if position == '' %}
            states.input_number.schliessposition_gaestezimmer.state | int
          {% else %}
            position | int
          {% endif %}

Regards Markus

You just need to use the output terminations.

          {% if position == '' %}
            {{ states.input_number.schliessposition_gaestezimmer.state | int }}
          {% else %}
            {{ position | int }}
          {% endif %}

{% %} means: execute this line of code, don’t output anything
{{ }} means: Execute this line of code and return it’s contents as a string.

1 Like

Many Thx Petro,

It works.
Small error with great effect

Regards Markus

1 Like

Dear community,

One more little postscript. I wrote that this part works.

    - service_template: >
          {% if is_state('input_boolean.automatisierung_gaestezimmer', 'on') and
            (states.cover.rollo_gaestezimmer.attributes.current_position|int != position) and
            (position == 0) and
            (orientation == 'all' or orientation == 'east' or orientation == 'gast') %}
              cover.close_cover
          {% elif is_state('input_boolean.automatisierung_gaestezimmer', 'on') and
            (states.cover.rollo_gaestezimmer.attributes.current_position|int != position) and
            (position == 100) and
            (orientation == 'all' or orientation == 'east' or orientation == 'gast') %}
              cover.open_cover
....

I’m afraid that’s not true.
If I run into the branch with the service: “cover_close” or “cover_open”, the script doesn’t work.

        position: >
          {% if position == '' %}
            {{ states.input_number.schliessposition_bad.state | int }}
          {% else %}
            {{ position | int }}
          {% endif %}

Because the code apparently crashes due to the service data attribute: “position”, which doesn’t exist in this case.
If someone has a solution for this problem, I would be grateful.
If not, I will only control it via the service: “set_cover_position”.

Thanks a lot for your support.

Best regards

Markus

create 2 scripts that accept all variables. One for open 1 for closed. Just don’t use the variables for the close portion.

1 Like

Thanks Petro,

I wanted a code that would map all the functions. I did it like you suggested, or closes the blind yes, if I enter the position “0”, or opens it, if I enter the position “100”.

Regards Markus