Combine switch and binary-sensor for garage door

Hello,
i made my garage door a bit smarter and useing the Fibaro FGBS-222 and a Aqara Door/Window Sensor.
Now i try to combine them into a cover for my garage door to control it via homekit.
Here in the forum were some examples and i tried some of them, but did not get the right result. At the moment i use following template:

---
- platform: template
  covers:
    garage_door:
      friendly_name: "Garagentor Cover"
      value_template: "{{ states('binary_sensor.garagedoor_status'), 'off' }}"
      open_cover:
        service: switch.toggle
        data:
          entity_id: switch.garagentor
      close_cover:
        service: switch.toggle
        data:
          entity_id: switch.garagentor
      icon_template: >-
        {% if states('binary_sensor.garagedoor_status') == "on" %}
          mdi:garage-open
        {% else %}
          mdi:garage
        {% endif %}

The binary sensors outputs on/off state for open/close. The Template itself shows the correct icon, but the state is still opend. Is there no possibilites to change the default state to closed?

1 Like

because you have it open when the binary sensor is off and your syntax is wrong.

      value_template: "{{ is_state('binary_sensor.garagedoor_status', 'on') }}"
1 Like

With ‘off’ was some kind of experiment. If its ‘on’ there is no other status. The same result in Frontend and Homekit.

That makes no sense. If that was the case your icon wouldn’t work, but you stated that it does.

Yes, see at the screenshots.

and you’re using this code and you restarted:

- platform: template
  covers:
    garage_door:
      friendly_name: "Garagentor Cover"
      value_template: "{{ is_state('binary_sensor.garagedoor_status', 'on') }}"
      open_cover:
        service: switch.toggle
        data:
          entity_id: switch.garagentor
      close_cover:
        service: switch.toggle
        data:
          entity_id: switch.garagentor
      icon_template: >-
        {% if states('binary_sensor.garagedoor_status') == "on" %}
          mdi:garage-open
        {% else %}
          mdi:garage
        {% endif %}
1 Like

Okay, very confusing. I copy and paste your config and now it worked! I feel stuipd now. :frowning:

Thanks for your help!

value_template represents the state you see in the UI. Then based on what that state is, the open/close cover will enable/disable. E.g. if the state is open, only close will be enabled.

1 Like

Hi, I’m new to HA and don’t quite get it yet.

Is the binary_sensor "garagedoor_status " separately defined elsewhere?

And the switch “garagentor”, too?

Welcome, yes those entities are defined elsewhere. These items usually come from other integrations. For example, if you have a zwave switch (switch.garage_door) that opens and closes the garage door and a zwave sensor (binary_sensor.door_status) that tells you if the state of the garage door. You’d use those entities in the value template and the turn_on/turn_off service fields.