How to store cover position in variable

Hi, I tried to set up an automation.

When I open my window, the current position of my cover should be stored into a variable (input_number.int_savedcoverposition)
After that my covers will open.

When I later close the window again the i want to use the cover.set_cover_position service to restore the original state.

So far so good, but I have no Idea how to set the value for the variable.

I tried something like this:

service: input_number.set_value
data:
  entity_id: input_number.int_savedcoverposition
  value: '{{ states(''cover.wohnzimmer_jalousie_rechts.current_position'') | int }}'

Any Ideas whats wrong?

I don’t use covers here, but I would hazard a guess that it would be…

service: input_number.set_value
data:
  entity_id: input_number.int_savedcoverposition
  value: "{{ state_attr('cover.wohnzimmer_jalousie_rechts', 'current_position')|int }}"

(you probably don’t need the |int either as the attribute is probably already one, but I left it in there just in case)

Hmmm still doesn’t work. I always geth the following error message

expected float for dictionary value @ data['value']

Change it to |float

still the same thing.

Why is it so difficult to get a state value in home assistant and assign it to a variable and vice versa?

It’s not usually.

Can you post the contents of the attributes column from the states list for your cover please?

entity_id: cover.schlafzimmer_jalousie_rechts
state: open
current_position: 100
id: QEQ1406279
interface: rf
rssi_peer: -197
level: 1
working: 'No'
friendly_name: Schlafzimmer Jalousie rechts
supported_features: 15

There’s your problem, you’re using the wrong entity_id in the template.

Hi, I’m curious since I’m trying to accomplish the same.

@Septem
Did You get it working? How are You passing input_number.int_savedcoverposition back to the cover such that it sets the position?

Also, I assume You have more than one cover. Were You / anybody else able to define the logic once and re-use it? (In my case 13*2 automations = 13 covers * (1 automation for opening + 1 automation for closing)…)