Cover template to control a rolling shutter

Hi, I’m trying to configure a cover template to control a rolling shutter connected to a sonoff dual r2.
With my existing wall buttons i simply push the up button one time to open totally the rolling shutter, and if i want to stop it i have to push again one time the same button. If i push the down button while the rolling shutter is opening then it starts to close. And so on…
I would like to replicate the wall buttons behavior using the cover template.

My actual testing configuration is this:

cover:
  - platform: template
    covers:
      tapparella_studio:
        friendly_name: "Tapparella Studio"
        value_template: "{{is_state('cover.tapparelle_studio', 'open')}}"
        open_cover:
          - service: mqtt.publish
            data:
              topic: 'cmnd/tapparellaStudio/power1'
              payload: 'TOGGLE'
        close_cover:
          - service: mqtt.publish
            data:
              topic: 'cmnd/tapparellaStudio/power2'
              payload: 'TOGGLE'
        stop_cover:
          - service: mqtt.publish
            data_template:
              topic: >
                {% if is_state('cover.tapparelle_studio', 'open') %}
                  'cmnd/tapparelleStudio/power1'
                {% else %}
                  'cmnd/tapparelleStudio/power2'
                {% endif %}
            data:
              payload: 'TOGGLE'
        set_cover_position:
          - service: mqtt.publish
            data_template:
              position: "{{position}}"
              topic: 'cmnd/tapparellaStudio/backlog'
              payload: >
                {% if states.cover.tapparella_studio.attributes.current_position | int > 50 %}
                  'Power2 ON;Delay {{position}}" }};Power2 OFF'
                {% else %}
                  'Power1 ON;Delay {{position}};Power1 OFF'
                {% endif %}

open_cover works but stop_cover doesn’t. When I push the up arrow on the HA interface I need that it remains active since the shutter is open 100%.
The set position slider doesn’t work.

Anyone can help me? Or can explain me how to use the cover template?

So, when the cover is in the process of opening, is the state “open” or “closed”?

always closed

This will always return ‘cmnd/tapparelleStudio/power2’ then. Does that stop the cover?

No, it does nothing.

How value_template should be used? How can i use the position_template instead?

So, which topic do you use to send commands? Also, i just noticed, this syntax is wrong… might be the root cause:

    stop_cover:
      - service: mqtt.publish
        data_template:
          topic: >
            {% if is_state('cover.tapparelle_studio', 'open') %}
              'cmnd/tapparelleStudio/power1'
            {% else %}
              'cmnd/tapparelleStudio/power2'
            {% endif %}
        data:
          payload: 'TOGGLE'

change to:

    stop_cover:
      - service: mqtt.publish
        data_template:
          topic: >
            {% if is_state('cover.tapparelle_studio', 'open') %}
              'cmnd/tapparelleStudio/power1'
            {% else %}
              'cmnd/tapparelleStudio/power2'
            {% endif %}
          payload: 'TOGGLE'

data_template replaces data. If you intend to use regular data with a data template, put all the attributes under the data_template. Having both of them may ignore one or the other.

If the shutter is opening i stop it pushing the open button so the topic is cmnd/tapparelleStudio/power1
if it’s closing cmnd/tapparelleStudio/power2 that is close button

i already tried using only data_template but it’s the same

If that’s the case, then the syntax alone isn’t correct if the state is “closed” when you are opening it. It’s sending it to the wrong topic. But aside from that, it doesn’t sound like the topic is actually be honored. When you press a button, does it move?

yes, the wall buttons connected to the sonoff work, and the switches configured in HA work too

Sounds like you need to create a sensor that has 4 states, open, opening, close, closing. Then post to the correct topic based on those 4 states. If you don’t have that ability, the device can never work the way you want in Home Assistant. You could make that sensor based on the position of shudder.

mmh i don’t know how to do that… how can i get the shutter position?

depends on your device, can your device report position? It appears you can set a position. I would assume there is a way to get it.

No, i have to calculate the position percentage based on the time needed by the shutter to fully open.
The set_cover_position in my cover configuration in the first post is only for testing it.

For example:
if the shutter needs 24 second to fully open i have to send to the sonoff this command:
Backlog Power1 TOGGLE;Delay 120;Power1 TOGGLE
that simulate the first button press and the second after 12 sec to stop the shutter at 50% of opening

Bleh, i don’t think there is a sound way to do this because you can only “toggle” and you have to report to 2 topics.

why?
for set_cover_position the topic should be always this cmnd/tapparellaStudio/backlog
and the payload cannot be a string like “Power1 TOGGLE;Delay 120;Power1 TOGGLE”?

if this worked, then the problem would be get the value 50% from the HA interface…
How can i read that value from the input slider of the cover?

Many reasons off the top of my head:

  1. You need to know your starting position. From close → to open, from open → to close. Without feedback, this is painful.

  2. What happens when you actually use the stop? Is the cover now open? If that’s the case, your cover.tapparelle_studio state won’t know that, because you stopped. Now you gotta handle that.

  3. So clicked open, waited 18 seconds, now you clicked close. Gotta handle that.

Hi all

I know this is an old topic, I’m trying to do something similar to this and I have another thread open.

I’ve tried also to use the cover template in first post modified a little bit, but strangely I don’t see the entity then.

This is my modification

cover:
  - platform: template
    covers:
      tapparella_sala:
        friendly_name: "Tapparella Sala"
        value_template: "{{is_state('cover.tapparella_sala', 'open')}}"
        open_cover:
          - service: mqtt.publish
            data:
              topic: 'shellies/shellyswitch-xxxxxx/roller/0/command'
              payload: 'open'
        close_cover:
          - service: mqtt.publish
            data:
              topic: 'shellies/shellyswitch-xxxxxx/roller/0/command'
              payload: 'close'
        stop_cover:
          - service: mqtt.publish
            data:
              topic: 'shellies/shellyswitch-xxxxxx/roller/0/command'
              payload: 'stop'
        set_cover_position:
          - service: mqtt.publish
            data:
              topic: 'shellies/shellyswitch-xxxxxx/roller/0/command/pos'
              payload: "{{position}}"

Any help?

Thanks

1 Like