Hi. Newbie here, (my second post). I have been configuring HA (Hassio on Ubuntu) for about a month and so far it has been great. I’ve now run into a problem I can’t seem to figure out.
I’d like to refactor a few scripts that I reuse down to one by passing an entity_id.
I set up a test so that I can get the syntax right before I make changes to my prod environment however I can’t pass an entity_id to a script from an automation.
I am getting the following error “Error executing script. Invalid data for call_service at pos 1: extra keys not allowed @ data[‘entity’]”. I’ve looked through the forum, the question has been asked before:
I’ve tried several options but nothing has worked; at my wits end now so any suggestions are welcomed (sorry for the long post). My code is:
Automation -
- id: '7'
alias: New Automation
description: ''
trigger:
- entity_id: switch.lamp_tv
platform: state
to: 'on'
condition: []
action:
- service: script.test_arguments
data:
entity: "{{ switch.lamp_tv }}"
Thanks for the suggestion Pippyn. I tried your code and unfortunately got the same error message. I also tried curly braces and quotes around the entity data variable in the automation and same result. It seems to me that I am missing some really simple rule or syntax, I’ll keep reading and trying.
cheers
Nick
Thanks very much for the advice. I’ve read the page on scripts. I am using the “calling the script as a service directly” method. I had a service call in the script but in a different sequence to your post. I’ve modified my code accordingly. However, I got the same error message on execution:
Logger: homeassistant.components.automation Source: helpers/script.py:693 Integration: Automation (documentation, issues) First occurred: 3:36:52 PM (16 occurrences) Last logged: 8:53:39 PM
New Automation: Error executing script. Invalid data for call_service at pos 1: extra keys not allowed @ data[‘entity’]
Reading the docs, your code should work so I thought that there is something else going on. I loaded my code into the VS Code editor to see if I received any errors. I also rewrote the code to ensure that there were no hidden chars. Still the same result. So I then rebooted Ubuntu/Hassio and tried again, and it worked!!! My code is below for reference.
Thanks for the advice once again.
Nick
Automation
- id: '7'
alias: New Automation
description: ''
trigger:
- entity_id: switch.lamp_tv
platform: state
to: 'on'
action:
- service: script.test_arguments
data:
entity: switch.lamp_tv
well, after changing your automation and script did you reload them by going to Configuration → Server controls and clicking on “Reload automations” and “Reload scripts”?
you should do that so HA pick up the changes.
you only need to restart HA (just HA) if you change something with your sensors and other non-reloadable stuff (as HA devs keep adding .reload services to integrations).
please mark the solution post in this topic so others can easily find it later.