Controlling roller shutters. Newcomer needs help! :-)

Hi all,

I’m new to HA and was so far using ioBroker with Blockly Scripts. Now I’d like to migrate slowly to HA and try to understand how it works.
I need some help on how to migrate my current roller shutter control to HA.
Here is my current state:

  • all shutters are remote controlled via broadlink RF signals.
  • every shutter has its own signals for open and close.
  • I learned 2 signals open and close for one shutter. (for HA test case)
  • I created 2 scripts to trigger open or close RF signal. → works
  • I created 2 helpers. 1: shutter.current.positon, 2: shutter.target.position. (0-100)

→ Now I wanted to somehow replicate, what I did in ioBroker. There I was checking, if target position is bigger/smaller than current position. If not, then I fire respective signal to open or close and I was adding/substracting +=1 to the current.position until the target position is reached. (I divided the 100% into the time it takes to open a shutter. Here let’s say 20s, so each step 200ms). To stop the motion of the shutter, I’m sending the same signal like before.
With that, I was able to set 50%, the shutter moved to the position and stopped there. In case of target.position =0 or =100, I did not stop the motion exactly at 0/100, but with a delay of 5 seconds. (Just to be sure it is really closed).

Now I’m somehow lost how a pro-user would do that in HA? I wasn’t successful in building an automation and I could not manipulate the helper values.
Can somebody help me getting traction?

Thomas

hi… what part do you need help with? if it’s the writing the automation, that’s not hard… can help you with that. if it is an integration issue… ie how to send the right broadlink rf signals and also how to read the current position, im personally not familiar with your hardware…

please clarify … happy to help if I can

Hi,

it’s about the automation. Broadlink works already and is integrated.

something like this? read the comments in the code for explanation.

mode: single
trigger:
#trigger when the target level changes
  - platform: state
    entity_id:
      - input_number.target
condition: []
action:
# repeat the following commands
  - repeat:
# try to set the shades to what the target is
      sequence:
        - service: cover.set_cover_position
          target:
            entity_id: cover.my_shades
          data:
            position: " {{ states('input_number.target') - 1}}"
       - delay:
            seconds: 1
        - service: cover.set_cover_position
          target:
            entity_id: cover.my_shades
          data:
            position: " {{ states('input_number.target') }}"
# wait a few seconds to give it a chance
        - delay:
            seconds: 10
#keep trying until the target is the same as the shade's actual value
      until:
        - condition: template
          value_template: >-
            {{ states('input_number.target') ==
            states('cover.my_shades') }}

hmmmm… For me it is hard to judge.
What do I need to do with this code to enable it on my side?
And how could I adapt it to all the shades?
What helper do I need to create first?
I don’t see the commands to control the shutter up or down. Remember, this is RF controlled. There is no interface to directly control the % of a shutter. There is only up or down. The % must be calculated “virtually” to reflect the current state…
Sorry for all the questions :slight_smile:

have you played around with creating automations and creating dashboard cards? as well, what’s your experience writing scripts and code?

I experimented a bit with automations but rather the GUI rather than coding straight. I wanted to see what is coming out of the visual tool and wanted to potentially adapt the code afterwards. I’m more a “blockly” guy, not hand-coder, but I understand the code.
So in a nutshell: I’m able to understand scripts, but (currently) not able to write any for HA.

so something like this then?

i think it’s smart to mostly work in the gui… and just drop into yaml for the small bits that can’t be done in the gui. so pop this in the gui and almost all except the template should be fine… of course you have to replace my random entity names with your real ones, and my script with your real script or command that raises/lowers the shades. i put a 1 second time for it to run. before stopping… change as needed.

to wire this up, go to the dashboard and add a card that points to the helper target entity. (whatever you replace my input_number.target with).

as you can see, you don’t need to know much hand coding to get this done. play with this in the gui …

description: ""
mode: single
trigger:
  - platform: state
    entity_id:
      - input_number.target
condition: []
action:
  - repeat:
      sequence:
        - if:
            - condition: numeric_state
              entity_id: input_number.target
              above: cover.my_shades
          then:
            - service: script.raise_shades
              target:
                entity_id: cover.my_shades
          else:
            - service: script.lower_shades
              target:
                entity_id: cover.my_shades
        - delay:
            seconds: 1                
        - service: script.stop_shades
          target:
            entity_id: cover.my_shades

      until:
        - condition: template
          value_template: >-
            {{ (states('input_number.target') - states('cover.my_shades') | abs)
            < 10}}

Looks better and I will try it tomorrow.
Some adjustments need to be made though:
1: The signal to stop ist the same signal that was pressed before. So if shades need to be lowered, the stopping signal is also “script.lower_shades”.
2: Would it be possible to add a const = number that reflects the total opening time (like 20s), so that the algorithm will automatically divide that number into 100 pieces and the according time for each step? With that I could have a helper outside the script to adjust that number for multiple windows.

yup, you will definitely need to adjust for your case. i’m totally unfamiliar with your hardware and your setup… so i’m guessing a lot. intent here is to get you the framework that gets you going.

personally i would put the time delay on a helper, and i’d also put the threshold (see the 10 in the last line) in a helper. that 10 is there for a “what’s close enough between actual shades and target” because it may be too hard to hit the number exactly.

Hi!

I played around a bit and I’m stuck now.
Here is my current code:

alias: Rolladen_Büro_l_öffnen
description: ""
trigger:
  - platform: numeric_state
    entity_id:
      - input_number.rolladen_buro_l_target_position
    above: input_number.rolladen_buro_current_position
condition: []
action:
  - parallel:
      - service: script.rolladen_buro_links_offnen
        metadata: {}
        data: {}
  - delay: >-
      00:00:{{ states(('input_number.rolladen_buro_l_target_position') -
      ('input_number.rolladen_buro_current_position')) * 
      0.01 *
      ('input_number.rolladen_120')}}
  - service: script.rolladen_buro_links_offnen
    metadata: {}
    data: {}
mode: single

Everything works except this part:

00:00:{{ states(('input_number.rolladen_buro_l_target_position') -
      ('input_number.rolladen_buro_current_position')) * 
      0.01 *
      ('input_number.rolladen_120')}}

I tried to test 00:00:05 and this works. But when I’d like to calculate the value it doesn’t.
Example:
Helper values are:
rolladen_buro_l_target_position = 50
rolladen_buro_current_position = 0
rolladen_120 = 10
→ In my calculation, it would be: (50-0)* 0.01 * 10=5
Is it even allowed to calculate within the delay function? How could I do it better? The preferred way would be to calculate the seconds separately. But how?

I helped myself and corrected the calculations. I’m now able to run myself. Thanks for your help. :slight_smile:

awesome. glad it’s working for you! :slight_smile:

Can you show the solution with the complete code?

I’m trying to do by myself but I’m stucked. I’m using a broadlink and a roller shuters with RF.

Also, how do you show the roller shuters in the frontend?

I have solved my second problem, adding:

homeassistant:
 customize_glob:
    cover.*:
     assumed_state: true

So one of my problems was that the buttons showed grey although my roller shutter weren’t at 0% or 100%. With this option, you can avoid the false state of open or close in this kind of roller shutter (RF + broadlink without position)

But I need to solve my first problem, I mean, to virtually calculate the position of the shutter

Thanks in advance