Hello, the script below throws the error “Error: extra keys not allowed @ data[‘position’]” when I attempt to run it. I am guessing it has to do with data provided for the position. I have the input set to be a number. It takes and Integer but that is not an option. What could be causing this error? All comments are appreciated! Thank you!
alias: Set Cover Position
sequence:
- target:
entity_id: "{{ target_cover_entity }}"
data:
position: "{{ desired_position }}"
action: script.turn_on
mode: parallel
icon: mdi:curtains
fields:
target_cover_entity:
selector:
entity: {}
description: The actual cover entity
name: target_cover_entity
required: true
desired_position:
selector:
number:
min: 0
max: 100
name: desired_position
description: The position to set the shutter to
required: true```
When you call the script indirectly using script.turn_on you have to put the variables under a variables key.
- target:
entity_id: #This should be the script you are targeting, not a cover entity
data:
variables:
entity_id: "{{ target_cover_entity }}"
position: "{{ desired_position }}"
action: script.turn_on
When I click run I am presented with a dialog box to select the target_cover_entity and the desired_position. I provided values for both and clicked run on the bottom. The shutter did not change it’s position.
I’m kind of confused (ok really confused…) about what you are trying to accomplish with the script.
the first and only action of the script runs another script (script.turn_on) but it doesn’t look like you are passing a script entity to the script but instead you are passing a cover entity with a parameter for the cover position.
normally a script action call (formerly a service call) requires that you tell the script.turn_on action which script to run and then if pass the variables that you want that script to use if the script needs them.
and a script doesn’t run independently. you need to call the script (with something like script.turn_on) from something else like an automation or a frontend button.
why are you calling a script from within another script?
data:
Hello @finity, thank you for your reply. I am new to HA and struggling to learn, everything is ‘documented’ but there is a lack of work flow information. Like trying to learn English but you only have a dictionary.
As a first step in a larger goal, I am trying to write and test a script that will accept a cover entity and a position and then set that cover to that position. The script was generated by the UI but threw the error in the title.
So how can I create a script that I can test in dev tools that will prompt me for a cover entity and a position and then set the actual cover to that position?
Thank you!
Is this not a legitimate way to run a script?
I honestly don’t think that HA can “prompt” you for any data in the traditional sense.
you have to provide that data programatically either by hard-coding the data or by using a jinja template if the action call accepts a template.
as in the example I gave above you would typically call the script that uses variables by creating an automation that passes those variable to the scrip as I outlined above.
like:
automation:
alias: your automation name
trigger:
- platform: some trigger
action:
- action: script_turn_on
entity_id: script.your_script_entity_id
data:
variables:
target_cover_entity: cover.blind
desired_position: some_postion_integer_value
Hmm. I don’t use anything from the UI so I’ve never seen that screen before so I guess at this point I’m not sure I can add anything more of value to that specific thing.
Yeah I was admonished earlier by some body that I should use the UI but it never seems to work except for the simplest of tasks. I guess I have to learn YAML and all the HA extensions. This is a very slow process.
So far, it looks like all you have shared is the caller script, “Set Cover Position”. Can you post the script that is being called by “Set Cover Position”?
Well I’m sure I’m more confused than both of you put together! I don’t have another script or automation to call the script that I shared. I am trying to write this script and then test it. Writing an automation that calls the script just seems to compound the opportunities for things that are wrong because I wouldn’t know if the automation was broken or the script was broken if it didn’t work. I am attempting to utilize this run feature to run the script without additional code that needs to be debugged or has the opportunity to have its own defects. The script was generated with the UI except for the modification that was required to get rid of the error that I had posted. So I will repeat. I am trying to write and test script that will accept a cover entity and a position to set the cover too. I do appreciate your attention and efforts greatly. Thank you
Ok, that’s where the disconnect was… your action needs to be cover.set_cover_position, not script.turn_on. Since you have said that action isn’t reliable, you could include a repeat:
alias: Set Cover Position
sequence:
- repeat:
sequence:
- action: cover.set_cover_position
target:
entity_id: "{{ target_cover_entity }}"
data:
position: "{{ desired_position }}"
- delay: 5 #Change this to suit how long it takes your slowest cover to fully open from closed
until:
- condition: template
value_template: |
{{ is_state_attr(target_cover_entity, 'current_position', desired_position )
or repeat.index > 5 }}
mode: parallel
icon: mdi:curtains
fields:
target_cover_entity:
selector:
entity:
filter:
- domain: cover
description: The actual cover entity
name: Target Cover Entity
required: true
desired_position:
selector:
number:
min: 0
max: 100
name: Desired Position
description: The position to set the shutter to
required: true
EDIT: Fixed attribute ID and added repeat index requirement to until condition.