Script error "not a valid value for dictionary value @ data['entity_id']"

well, we didn’t see your modified config…

anyway, I made a simple test by replacing cover.set_cover_position with persistent_notification.create and it works as expected.
that means there something not quite right with that service call rather than script variables in general.

here’s my script

test:
  sequence:
    - service: persistent_notification.create
      data_template:
        message: "{{device}}"

and here’s the automation (didn’t want a button)

- alias: test
  trigger:
    platform: time
    at: "00:00:00"
  action:
    - service: script.test
      data:
        device: 'cover.dining_room'

I think you are missing variables: after data in the lovelace tap action. Try like this:

  - type: button
    name: "Close cover"
    icon: mdi:arrow-down
    tap_action:
      action: call-service
      service: script.set_cover_position
      data:
        variables:
          device: 'cover.dining_room'
          modus: 'close'

That’s how it is in the docs.

I’ve seen conflicting information about the use of ‘variables’. But if it’s in the docs :man_shrugging:

I don’t see anything here. Do you mean this?

I don’t think he needs variables if it’s not script.turn_on service.

My bet is TS did not reload script after changing device to something else.

Ah, calling scrip.turn_on requires variables. Calling the script directly as a service does not.

There are two ways to achieve this. One way is using the generic script.turn_on service. To pass variables to the script with this service, call it with the desired variables

The other way is calling the script as a service directly. In this case, all service data will be made available as variables.

Ah I see, you’re totally right, my bad. Only read the first part :rofl:

1 Like

One more test that works for me

test:
  sequence:
    - service: input_boolean.toggle
      data_template:
        entity_id: "{{device}}"

- service: script.test
  data:
    device: 'input_boolean.debug_central_heating'

so it looks like it’s ok to use device as a variable name and the problem lays in that cover.set_cover_position service call

will play with it later.

1 Like

Thanks for all your input.

The strange thing is that it works if I type in the entity_id directly in the script but not as variable.

set_cover_position:
  sequence:
    - service: cover.set_cover_position
      data_template:
        entity_id: 'cover.dining_room'
        position: >-
          {% if modus == close %}
            0
          {% else %}
            100
          {% endif %}

you’re using the wrong fields for the button card. data is not a valid field.

  - type: button
    name: "Close cover"
    icon: mdi:arrow-down
    tap_action:
      action: call-service
      service: script.set_cover_position
      service_data:
        device: 'cover.dining_room'
        modus: 'close'

Your script needs updating too. Gotta wrap close in quotes.

set_cover_position:
  sequence:
    - service: cover.set_cover_position
      data_template:
        entity_id: "{{device}}"
        position: >-
          {% if modus == 'close' %}
            0
          {% else %}
            100
          {% endif %}

EDIT: Just to clarify, the root cause of your issue is that entity_id and modus were blank because you were using data instead of service_data in your button card.

1 Like

Thanks @petro.

service_data: did the trick. :+1:

It would be much better to have data/data_template wherever we can use service: xxx.

Edited for clarity. service requires data and it has nothing to do with templates. It’s just a question of consistency as I see it. Lack of that creates post like this.

Templating is not a thing in lovelace :wink:

Not natively . . .

Yes of course custom cards can do this, but native cards do not. I was just rebutting ahmadk who is perpetually upset about things in home assistant.

1 Like

tap_actions call-service actions across all of lovelace consistently use service and service_data though.

I assume he mean’t that it should be consistent across Home Assistant. E.g. in automations it’s data and in the tap action of lovelace it’s service_data

1 Like

spot on :+1:
I think I understand and appreciate why there is no consistency in HA but for me personally it does not mean that any thought about imperfection of things is heresy.
I also appreciate that people might be absolutely happy with the state of things and won’t try to disturb them in their nirvana as I’m here solely to learn and share my knowledge with those who want it.

I for 1, never want it. How do I sign up for that?

1 Like

Game, Set and Match

I have a similar problem, I would like to make a stripe button-card to start the timers I use in my kitchen, but I don’t want an extra press to restart the timer, because a press should only work if the timer is idle
button-card code

type: custom:button-card
aspect_ratio: 1.2
color: red
color_type: card
entity: timer.kitchen_002_aeg_hardkogte
name: Hård kogte æg
haptic: success
tap_action:
  action: call-service
  service: script.timertest
  service_data:
    thetimer: timer.kitchen_002_aeg_hardkogte
hold_action:
  action: call-service
  service: timer.cancel
  service_data:
    entity_id: timer.kitchen_002_aeg_hardkogte
show_last_changed: true
show_state: true

and here hassio script:

alias: timertest
sequence:
  - condition: state
    entity_id: timer.kitchen_002_aeg_hardkogte
    state: idle
  - service: timer.start
    data: {}
    target:
      entity_id: "{{ thetimer}}"
mode: single

I would like to replace:

  - condition: state
    entity_id: timer.kitchen_002_aeg_hardkogte
    state: idle

with:

  - condition: state
    entity_id: "{{ thetimer}}"
    state: idle