Programming Garage "cover" template with Shelly Uni

Hi All-
I’ve hit a wall here. I use a shelly UNI device to install a reed switch (for open/closed status) and a relay to open/close the door. This all works manually. The UNI is setup to control the relay trigger (shut off relay 0.5 seconds after it gets turned on). I added to HA with the shelly integration. I did have to invert the input in the UNI settings in order to show the binary sensor inputs as open/closed correctly. So here’s the problem. Now I’m trying to create a cover template to bring this all together. I do need to invert open/closed in the template to get both the binary sensor input and cover status to match. Here’s my code:

cover:
  - platform: template   
    covers:
      big_garage_door:
        device_class: garage
        friendly_name: "House Big Garage Door"
        unique_id: "HouseBigGarageDoor"
        position_template: "{{ is_state('binary_sensor.small_garage_door_input', 'on')  }}"
        open_cover:
          - condition: state
            entity_id: binary_sensor.big_garage_door_input
            state: "off"
          - service: switch.turn_on
            target:
              entity_id: switch.big_garage_door
        close_cover:
          - condition: state
            entity_id: binary_sensor.big_garage_door_input
            state: "on"
          - service: switch.turn_on
            target:
              entity_id: switch.big_garage_door
        stop_cover:
          service: switch.turn_on
          target:
            entity_id: switch.big_garage_door
        icon_template: >-
          {% if states('binary_sensor.big_garage_door_input')|float < 100 %}
            mdi:garage-open
          {% else %}
            mdi:garage
          {% endif %}

Almost everything works as intended with the exception of the open/close cover buttons. Everything looks good when the garage is closed and the button works correctly to open it:

image

This problem starts after it’s opened. Now that it’s opened, I still have the options to both open and close the garage. I feel that I shouldn’t still have an open button when it’s already open.

image

I know I’m missing one stupid setting but I can’t find it.

From the template cover docs, I see this for position_template:

position_template template (optional)
Defines a template to get the position of the cover. Legal values are numbers between 0 (closed) and 100 (open).

You have

position_template: "{{ is_state('binary_sensor.small_garage_door_input', 'on') }}"

which will return true or false (a boolean). I suggest changing that to this:

position_template: "{{ iif(is_state('binary_sensor.small_garage_door_input', 'on'), 0, 100) }}"

(adjusted based on whether “on” means open or closed to you)

Or, just use value_template and not position_template, as I do:

value_template: "{{ iif (is_state('binary_sensor.garage_door', 'off'), 'open', 'closed') }}"

position_template is really intended for cases where you know and want to report that a cover is partially open, so it doesn’t really make sense for just open/closed.

Great. Thank you for pointing me in the right direction. This worked. I’ll add my code for anyone that searches this in the future.

cover:
  - platform: template   
    covers:
      big_garage_door:
        device_class: garage
        friendly_name: "House Big Garage Door"
        unique_id: "HouseBigGarageDoor"
        value_template: "{{ iif (is_state('binary_sensor.big_garage_door_input', 'off'), 'closed', 'open') }}"
        open_cover:
          - condition: state
            entity_id: binary_sensor.big_garage_door_input
            state: "off"
          - service: switch.turn_on
            target:
              entity_id: switch.big_garage_door
        close_cover:
          - condition: state
            entity_id: binary_sensor.big_garage_door_input
            state: "on"
          - service: switch.turn_on
            target:
              entity_id: switch.big_garage_door
        stop_cover:
          service: switch.turn_on
          target:
            entity_id: switch.big_garage_door
        icon_template: >-
          {% if states('binary_sensor.big_garage_door_input')|float < 100 %}
            mdi:garage-open
          {% else %}
            mdi:garage
          {% endif %}
4 Likes

Hi, I’m new to HA and Shelly Uni.
I’m trying to connect my gate with a cover to get the status oh my gate.
In order to do so, I connected the shelly uni to the gate electronic card.
I’m using the 2 relays to manage 2 means of opening (complete and partial for pedestrial).
I’ve connected the 2 binary sensors of the shelly to 2 limit switches (one when the gate is open, the other when it is closed).
The first issue I’m facing is that the shelly sensors don’t keep their state, it is like there is an impulsion and that’s it.
Help would be apreciated.
Thanks