Hi all. Very recently I started with Home Assistant with the intention of getting into home automation and doing some automation at home.
At the moment I have installed a Shelly 2.5 relay to control the blind as well as an Aqara contact sensor in the same window. Both devices work perfectly.
The sensor entity is binary_sensor.room2_window_contactand the Shelly is cover.room2_blind.
Since the blind cannot be lowered while the window is open, I have read in the forum that the best solution would be to use a āTemplate Coverā. The problem is that I canāt get it to work with the following code:
A template always returns a string, as of now (will change in 0.115 as far as I read) you canāt template a dictionary. In addition Iām not sure if you can even use a template in the close_cover section.
You could make a script that checks if the window is open and only closes when the window is not open. Then call this script in the close_cover section.
Given my limited knowledge, I have decided to tackle the problem starting from scratch.
The first step is to create a template that exactly copies the operation of the cover entity.
The following code works perfectly except that the bar to manage the blind in percentage does not work.
The attribute is current_position and Itās 100 when fully open and 0 when fully closed.
I have checked this attribute in various positions in both, cover.persiana_guillem and cover.copia_persiana_guillem and the value is alway the same.
Is there any other way to ācloneā an entity without using a template?
Finally, after reading Template Cover documentation again, I have realized that I had not taken into account set_position service.
Finally, it works as I wanted to:
Thanks for the code! It looks promising in the Template Editor, although I had to change "{{position}}" to "{{ state_attr('cover.original_cover_sensor', 'current_position')}}". Even though what I wrote is true to the extend that it gets rid of an error in the Template editor, it disables the function to set a target position of the blind. So @ntds code was perfectly fine, sorry!
But right now Iām still stuck, because I cant find out where to implement this templateā¦could anyone give a hint?
I looked at the Home-Assistant Documentation relating to States, Templates and so on, but nothing there worked. I added the code from @ntds to my configuration.yaml (with a cover: in the line above it), but nothing happens. No errors either but nothing us showing up anywhere and the coverās behaviour doesnāt change whether the window is open or not.
If it matters: Iām running Home-Assistant CORE on a Raspberry Pi.
EDIT:
Ok, I figured it out. My problem was the indentation I thinkā¦
I did the following steps:
copy the code below to your configuration.yaml
replace <original_cover> with your blind cover ID and <window_sensor> with your blinds sensor ID (both can be found under Developer Tools > STATES and search for either cover or window sensor keywords within the first column)
under Developer Tools > YAML do a reload of āALL YAML CONFIGURATIONā and then use the red āRESTARTā button in the āCheck and Restartā section above.
now you should be able to find the entity under Developer Tools > STATES by searching for āsecuredā (while youāre at it copy the whole device ID, it should be āoriginal_cover_sensor_securedā)
to make use of the entity create a new card in a dashboard using the new device ID