Hello, I have the following problem with two scripts that control roller blinds.
One of the scripts was created through the Home Assistant graphical interface, and the other was written by me. Supposedly, both should work the same way, but the one I wrote does not behave as expected. First, let me explain what it’s about:
I need a script where I can set the percentage opening of venetian blinds. If the venetian blinds are open more than 8%, they have already started to retract, and if I set them to open at 3%-which means the slats are horizontally open-the script should first close the blinds to 0% and then open them to 3%.
Here is the script made via the GUI with a set percentage:
test:
sequence:
- sequence:
- if:
- type: is_value
condition: device
device_id: 1e3fdafbc6ae20993bf4fecd407b1b9f
entity_id: 84fea2029de4cbac02650d32100cd273
domain: sensor
above: 8
then:
- device_id: 1e3fdafbc6ae20993bf4fecd407b1b9f
domain: cover
entity_id: da29209ef0c3f7dd82899a1e9ccae121
type: set_position
position: 0
- repeat:
sequence:
- delay:
hours: 0
minutes: 0
seconds: 0
milliseconds: 500
until:
- type: is_value
condition: device
device_id: 1e3fdafbc6ae20993bf4fecd407b1b9f
entity_id: 84fea2029de4cbac02650d32100cd273
domain: sensor
below: 1
- device_id: 1e3fdafbc6ae20993bf4fecd407b1b9f
domain: cover
entity_id: da29209ef0c3f7dd82899a1e9ccae121
type: set_position
position: 3
alias: Test
description: ""
Here is the script I wrote, in which I pass the percentage when calling it:
raf_0_1_parameter1:
alias: Raf 0.1 - parameter % (1)
description: Set shutter position dynamically based on parameter
fields:
position:
selector:
text:
default: "0"
required: true
name: position
sequence:
- variables:
pos_int: "{{ position | int }}"
real_position: >
{% if pos_int == -1 %}4
{% elif pos_int == -2 %}5
{% elif pos_int == -3 %}6
{% else %}{{ pos_int }}
{% endif %}
- if:
- condition: numeric_state
entity_id: sensor.hmipw_drbl4_001660c9b13bf9_position_ch1
above: 8
then:
- service: cover.set_cover_position
target:
entity_id: cover.hmipw_drbl4_001660c9b13bf9_ch2
data:
position: 0
- repeat:
until:
- condition: numeric_state
entity_id: sensor.hmipw_drbl4_001660c9b13bf9_position_ch1
below: 1
sequence:
- delay: "00:00:00.5"
- delay: "00:00:01"
- service: cover.set_cover_position
target:
entity_id: cover.hmipw_drbl4_001660c9b13bf9_ch2
data:
position: "{{ real_position }}"
mode: restart
The problem with my script is as follows: after I set them to close to 0%, the loop that checks whether 0% has been reached does not wait, but immediately sets the new percentage, which leaves the blinds in some undefined position. Where am I making a mistake, and why is this happening? Can someone help me?