artem-sedykh / mini-climate-card

Minimalistic climate card for Home Assistant Lovelace UI
MIT License
281 stars 19 forks source link

Calling a script from toggle_action #92

Open argoon38 opened 2 years ago

argoon38 commented 2 years ago

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 commented 2 years ago

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...