Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calling a script from toggle_action #92

Open
argoon38 opened this issue Jul 14, 2022 · 1 comment
Open

Calling a script from toggle_action #92

argoon38 opened this issue Jul 14, 2022 · 1 comment

Comments

@argoon38
Copy link

argoon38 commented Jul 14, 2022

Hi,

I can't get my code working. Any help would be appreciated.
I'm trying to call a script and pass variables to it fro a button toggle_action. I don't really understand how to use the call_service option.

buttons:
  gauche:
    icon: mdi:arrow-left
    toggle_action: >
      (entity) => this.call_service('script/turn_on',
      entity_id='script.1657740924559', { variables: { entity: entity.entity_id,
      direction: 'left' }})

and the script to call is:

alias: ChangeAirDirection
description: 
fields:
  entity:
    description: entity
    required: true
  direction:
    description: sens de deplacement
    example: up / down / left / right
    required: true
sequence:
  - service: |
      {% if direction == "up" or direction == "down" %}
          melcloud.set_vane_vertical
      {% else %}
          melcloud.set_vane_horizontal
      {% endif %} 
    data:
        entity_id: '{{ entity }}'
    position: |
        {% if direction == 'left' %}
          {%set val= state_attr('climate.pac_salon', 'vane_horizontal') | first | int -1 %}
          {{ val if val>1 else '1_left' }}
        {% endif %}

It works when I test it separately, but I can't getting it work from the card.

@regevbr
Copy link
Collaborator

regevbr commented Jul 16, 2022

if you look at the docs, you can see that the first argument is the state, and the second argument is the entity... so you got the args list wrong...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants