Helper Input number: Script for Opening, Closing and Positioning the store

Hi guy’s , im close to giving up on my issues.

It’s probably over 3 days (even more) I’m trying to fix it without success.

  1. I’m having a script called from my Dashboard to Open and Close the store
    Those 2 scripts are working nicely.
    The last one is the Set the position to xx which I just cannot make it to work based on the Position to set the store (roller)

The message below are the value passed when I press the button and received by the script. Evything seems to be OK, from my Point of view. The value is 89 in that case.

POSITIONNEMENT d'un store [ Paramètre ]
Action: Positionner Pièce: Salle à manger Position: 89 Entité: cover.fenetre Senseur: binary_sensor.ewe_fenetre_sam_opening
Il y a 17 minutes
 
Positionnement du store cover.fenetre à la position de 89 est soumis...

The errors are : 
23-08-28 18:48:51.120 ERROR (MainThread) [homeassistant.components.script.positionnement_dun_store_parametre] POSITIONNEMENT d'un store [ Paramètre ] : Error executing script. Invalid data for if at pos 2: expected int for dictionary value @ data['position']
2023-08-28 18:52:54.391 ERROR (MainThread) [homeassistant.components.script.positionnement_dun_store_parametre] POSITIONNEMENT d'un store [ Paramètre ] : POSITIONNEMENT d'un store: Error executing script. Invalid data for call_service at pos 2: expected int for dictionary value @ data['position']
2023-08-28 18:52:54.551 ERROR (MainThread) [homeassistant.components.script.positionnement_dun_store_parametre] POSITIONNEMENT d'un store [ Paramètre ] : Error executing script. Invalid data for if at pos 2: expected int for dictionary value @ data['position']
2023-08-28 18:59:05.643 ERROR (MainThread) [frontend.js.latest.202308021] https://ha-mlambert.duckdns.org:8123/frontend_latest/app-pdfsSFVCtsE.js:2:10695 Error: Failed to execute 'define' on 'CustomElementRegistry': the name "mushroom-select" has already been used with this registry
2023-08-28 18:59:05.662 ERROR (MainThread) [frontend.js.latest.202308021] https://ha-mlambert.duckdns.org:8123/hacsfiles/light-entity-row/light-entity-row.js?hacstag=151318225025:10:47 ReferenceError: Can't find variable: Polymer


I'm calling the script this way

**Opening -Closing**
**----------------------------**
type: custom:mushroom-template-card
secondary: Bureau
icon: >-
  {% set _Ent = 'cover.bureau' %}  {% set _Att = 'current_position' %}   {% if
  ((state_attr(_Ent, _Att) / 10) <= 1) %}
          phu:shutter-100
     {% elif ((state_attr(_Ent, _Att) / 10) <= 2) %}
               phu:shutter-90
     {% elif ((state_attr(_Ent, _Att) / 10) <= 3) %}
               phu:shutter-80
     {% elif ((state_attr(_Ent, _Att) / 10) <= 4) %}
               phu:shutter-70
     {% elif ((state_attr(_Ent, _Att) / 10) <= 5) %}
               phu:shutter-60
     {% elif ((state_attr(_Ent, _Att) / 10) <= 6) %}
               phu:shutter-50            
     {% elif ((state_attr(_Ent, _Att) / 10) <= 7) %}
               phu:shutter-40
     {% elif ((state_attr(_Ent, _Att) / 10) <= 8) %}
               phu:shutter-30
     {% elif ((state_attr(_Ent, _Att) / 10) <= 9) %}
               phu:shutter-20
     {% elif ((state_attr(_Ent, _Att) / 10) <= 9.9) %}
               phu:shutter-10        
     {% elif ((state_attr(_Ent, _Att) / 10) <= 10) %}
               phu:shutter-0   
  {% endif %}
layout: vertical
double_tap_action:
  action: call-service
  service: cover.stop_cover
  target:
    entity_id: cover.bureau
  data: {}
hold_action:
  action: call-service
  service: script.1693003922896
  data:
    _actionStore: Fermer
    _pieceStore: Bureau
    _storeEntity: cover.bureau
    _eweEntity: binary_sensor.ewe_fenetre_bureau_opening_2
tap_action:
  action: call-service
  service: script.1689978205320
  data:
    _actionStore: Ouvrir
    _pieceStore: Bureau
    _storeEntity: cover.bureau
    _eweEntity: binary_sensor.ewe_fenetre_bureau_opening_2
badge_icon: none
badge_color: transparent
icon_color: transparent
primary: ''
card_mod:
  style: |
    :host {
            --mush-icon-symbol-size: 1em;
          }
    mushroom-badge-icon:after {
        content: "{{ state_attr('cover.bureau','current_position') }}%";
        position: absolute;
        display: flex;
        justify-content: center;
        align-items: center;
        background: rgb(var(--rgb-green));
        color: var(--card-background-color);
        font-weight: bolder;
        border-radius: 75%;
        top: 0;
        width: 150%;
        height: 150%;
        font-size: 0.6em; 
    }



Positionning

tap_action:
  action: call-service
  service: script.positionnement_dun_store_parametre
  data:
    _actionStore: Positionner
    _pieceStore: Salle à manger
    _storePos: '{{ states(''input_number.store_ouverture_bureau'') | int }}'
    _storeEntity: cover.fenetre
    _eweEntity: binary_sensor.ewe_fenetre_sam_opening
entity: input_number.store_ouverture_bureau

1.1 SCRIPT: Opening

alias: OUVERTURE d'un store [ Paramètre ]
sequence:
  - service: notify.persistent_notification
    data:
      message: >-
        l'action a poser est {{ _actionStore }} - La piece ou est le store est: 
        {{ _eweStore }} - Le nom du store est:  {{_storeEntity }} 
  - if:
      - condition: template
        value_template: "{{ _actionStore == 'Ouvrir'  }}"
        alias: "[ _ationStore ] = Ouvrir"
        enabled: true
      - condition: template
        value_template: "{{ is_state(_eweEntity,'off') }}"
        alias: Vérifier si la fenêtre est fermé
        enabled: true
    then:
      - service: notify.persistent_notification
        data:
          message: Ouverture
      - service: cover.open_cover
        data: {}
        target:
          entity_id: "{{_storeEntity}}"
        enabled: true
    alias: OUVERTURE d'un store
    else:
      - service: notify.persistent_notification
        data:
          message: fermeture
mode: single
icon: mdi:roller-shade

   **1.2 SCRIPT: Closing**
   
alias: FERMETURE d'un store  [ Paramètre ]
sequence:
  - service: notify.persistent_notification
    data:
      message: >-
        l'action a poser est {{ _actionStore }} - La piece ou est le store est: 
        {{ _eweStore }} - Le nom du store est:  {{_storeEntity }} 
  - if:
      - condition: template
        value_template: "{{ _actionStore == 'Fermer'  }}"
        alias: "[ _ationStore ] = Fermer"
        enabled: true
      - condition: template
        value_template: "{{ is_state(_eweEntity,'off') }}"
        alias: Vérifier si la fenêtre est fermé
        enabled: true
    then:
      - service: notify.persistent_notification
        data:
          message: Fermeture
      - service: cover.close_cover
        data: {}
        target:
          entity_id: "{{_storeEntity}}"
        enabled: true
    alias: FERMETURE d'un store
    else:
      - service: notify.persistent_notification
        data:
          message: fermeture
mode: single
icon: mdi:roller-shade

   **1.3 POSITIONING SCRIPT:**
alias: "POSITIONNEMENT d'un store [ Paramètre ] "
sequence:
  - service: notify.persistent_notification
    data:
      message: >-
        POSITIONNEMENT d'un store [ Paramètre ]

        Action:    {{_actionStore}} Pièce:     {{_pieceStore}} Position: 
        {{_storePos}} Entité:    {{_storeEntity}} Senseur:   {{_eweEntity}}
  - if:
      - condition: template
        value_template: "{{ _actionStore == 'Positionner'  }}"
        alias: "[ _ationStore ] = Positionner"
        enabled: true
      - condition: template
        value_template: "{{ is_state(_eweEntity,'off') }}"
        alias: Vérifier si la fenêtre est fermé
        enabled: true
    then:
      - service: notify.persistent_notification
        data:
          message: >-
            Positionnement du store {{_storeEntity}} à la position de
            {{_storePos}} est soumis...
      - service: cover.set_cover_position
        data:
          position: "{{_storePos}}"
        target:
          entity_id: "{{_storeEntity}}"
        enabled: true
    alias: POSITIONNEMENT d'un store
    else:
      - service: notify.persistent_notification
        data:
          message: La fenêtre est possiblement ouverte {{_eweStore}}
mode: single
icon: mdi:roller-shade

Your help will be more than appreciate

I am not sure it will solve your problem, but something to try:
In the _storePos: template of the Positioning code you have several repeated single quotes like ‘’.
Try to replace these with double quotes “.
So like this:

tap_action:
  action: call-service
  service: script.positionnement_dun_store_parametre
  data:
    _actionStore: Positionner
    _pieceStore: Salle à manger
    _storePos: '{{ states("input_number.store_ouverture_bureau") | int }}'
    _storeEntity: cover.fenetre
    _eweEntity: binary_sensor.ewe_fenetre_sam_opening
entity: input_number.store_ouverture_bureau

Or, looking at you other code, even more consistent would be to interchange the quote types in that template:

tap_action:
  action: call-service
  service: script.positionnement_dun_store_parametre
  data:
    _actionStore: Positionner
    _pieceStore: Salle à manger
    _storePos: "{{ states('input_number.store_ouverture_bureau') | int }}"
    _storeEntity: cover.fenetre
    _eweEntity: binary_sensor.ewe_fenetre_sam_opening
entity: input_number.store_ouverture_bureau

Does that work for you?

Good morning Ed,

Thank you, I made the test of your recommendation and nothing change. Here the result of both tests:

just to add just info, when you are seeing the
' ''
the second one has been added by Home assistant when I was making different tests. I was also thinking it was weird :slight_smile:

2023-09-02 08:15:02.437 ERROR (MainThread) [homeassistant.components.script.positionnement_dun_store_parametre] POSITIONNEMENT d'un store [ Paramètre ] : POSITIONNEMENT d'un store: Error executing script. Invalid data for call_service at pos 2: expected int for dictionary value @ data['position']
2023-09-02 08:15:05.330 ERROR (MainThread) [homeassistant.components.script.positionnement_dun_store_parametre] POSITIONNEMENT d'un store [ Paramètre ] : Error executing script. Invalid data for if at pos 2: expected int for dictionary value @ data['position']


2023-09-02 08:21:47.952 ERROR (MainThread) [homeassistant.components.script.positionnement_dun_store_parametre] POSITIONNEMENT d'un store [ Paramètre ] : POSITIONNEMENT d'un store: Error executing script. Invalid data for call_service at pos 2: expected int for dictionary value @ data['position']
2023-09-02 08:21:50.058 ERROR (MainThread) [homeassistant.components.script.positionnement_dun_store_parametre] POSITIONNEMENT d'un store [ Paramètre ] : Error executing script. Invalid data for if at pos 2: expected int for dictionary value @ data['position']```

I am still not sure whether it is of any help, but there appears to be a typo on two locations in your code:

    alias: "[ _ationStore ] = Fermer"

This should probably be:

    alias: "[ _actionStore ] = Fermer"

And another observation: this error message:
Invalid data for if at pos 2: expected int for dictionary value @ data['position']
might be caused by the variable _storePos being zero at runtime ( so not an integer as it is expected by the code).
However, it is not clear to me where this variable _storePos is being declared in your code.

_storePos is the only option you have in the tap_acrion that uses a template.

According to the documentation for the Mushroom Template card, several of its options support templates, like icon, icon_color, etc but it doesn’t indicate that tap_action supports templates.

Wowww

I never realized there was something missing but even by doing it , it didn’t.
But I found one way to fix it:

I decided to update an input_number where an automation is watching if the value is changing and I’m calling the script (cut/paste)

And it works very smoothly :slight_smile:

Yes, I can hear you…. “you could optimize it….” I guess LOL


type: entities
entities:
  - entity: input_number.store_ouverture
    secondary_info: none
    name: Ajustement de la position
    icon: mdi:roller-shade-closed
state_color: true
show_header_toggle: false
title: 'Position des 4 stores '


alias: positionner le store à
description: ""
trigger:
  - platform: state
    entity_id:
      - input_number.store_ouverture
    from: null
    to: null
condition: []
action:
  - service: script.positionnement_dun_store_parametre
    data:
      _actionStore: Positionner
      _pieceStore: Salle à manger
      r_storePos: states('input_number.store_ouverture')
      _storePos: "{{states('input_number.store_ouverture')}}"
      _storeEntity: cover.fenetre
      _eweEntity: binary_sensor.ewe_fenetre_sam_opening
    alias: >-
      Ouverture de store de la salle à mangerOuverture de store de la FENETRE de
      la salle à manger
  - service: script.positionnement_dun_store_parametre
    data:
      _actionStore: Positionner
      _pieceStore: Salle à manger
      r_storePos: states('input_number.store_ouverture')
      _storePos: "{{states('input_number.store_ouverture')}}"
      _storeEntity: cover.porte
      _eweEntity: binary_sensor.ewe_porte_sam_opening
    alias: >-
      Ouverture de store de la salle à mangerOuverture de store de la PORTE de
      la salle à manger
  - service: script.positionnement_dun_store_parametre
    data:
      _actionStore: Positionner
      _pieceStore: Salon
      r_storePos: states('input_number.store_ouverture')
      _storePos: "{{states('input_number.store_ouverture')}}"
      _storeEntity: cover.fenetre_du_salon
      _eweEntity: binary_sensor.ewe_fenetre_salon_opening
    alias: >-
      Ouverture de store de la salle à mangerOuverture de store de la FENETRE du
      SALON
  - service: script.positionnement_dun_store_parametre
    data:
      _actionStore: Positionner
      _pieceStore: Bureau
      r_storePos: states('input_number.store_ouverture')
      _storePos: "{{states('input_number.store_ouverture')}}"
      _storeEntity: cover.bureau
      _eweEntity: binary_sensor.ewe_fenetre_bureau_opening
    alias: Ouverture de store du store de la FENETRE du bureau
    enabled: true
mode: single