Yes that is correct
In HA, all entities have states. The state is what represents the current state of the entity. For a cover, the possible states would be open
, closed
, opening
, closing
, unavailable
, and unknown
. It is not possible for a cover entity to have any state besides those. However, entities can also have attributes. Attributes hold additional information and can really be anything. For a cover that supports being partially open, it could have an attribute called position
which holds the current position of the cover. So the state might be open
while the position attribute is 50
. I recommend you go to developer tools > states and search for the entities that represent your blinds, and see what the state is and see what attributes they have. You will need to understand this to create a working script or automation.
To create a template you will have to type it in using your keyboard. You can do this in the script editor UI but the UI will just give you a place to type it. You also need to know where templates are allowed and where they are not allowed. The docs (usually) specify this.
â
To start, we can make a simple script that uses the âset_positionâ command. We can make it more complex later by adding the âwhileâ loop but weâll hold off for now. In HA, commands are known as a services
and the supported services for covers are listed here. And we know what can be templates in service calls from this documentation. (The quick answer is that pretty much everything in a service call can be templated.)
And you may wonder why these services look different from what you shared from your script earlier, which lists devices. You should avoid devices as described here.
So in the script editor, create a new script, enter a name for it, and add an action. The action is âcall a serviceâ. The service to select is âcover: set positionâ. Since we are going to reference a variable, we need to use templates, and so this is about as far as we can get before we have to start typing things out. So click the 3 dots to the right of the text âcall a service: âCover set positionâ onâ. In that menu you can choose âedit in YAMLâ
Now you have some text that should look like this:
service: cover.set_cover_position
data: {}
In the cover documentation linked above, where it discusses the cover.set_position service call, there is an example you can just copy from. Paste the relevant text into your script, replacing the text that was there. So you now have:
service: cover.set_cover_position
target:
entity_id: cover.demo
data:
position: 50
Instead of copying this over, you could have chosen a cover entity and entered a position in the UI before switching over to YAML. Either way you do it, you want to get the data structure and spacing correct before we start adding templates.
So now we donât want to issue the service call to cover.demo
. Instead, we want it issued to whatever variable we pass into this script. So now we replace it with a template that references a variable. We can do the same thing with the position as well:
service: cover.set_cover_position
target:
entity_id: "{{ my_cover_entity }}"
data:
position: "{{ desired_position }}"
You can now save the script and exit the editor. Your script is set up to accept variables. Specifically two variables; one called my_cover_entity
that should contain the entity_id of a cover, and the other called desired_position
that should contain an integer between 0 and 100.