Template cover for garage door

well first, is it just an open/close sensor? If the answer is yes, ditch the sensor and make a binary sensor. Let translation handle open/close.

Then use value_template instead of position_template. I would expect your resulting cover template to look like this with a binary sensor.

cover:
  - platform: template
    covers:
      garage_door:
        device_class: garage
        friendly_name: "Garage Door"
        value_template: "{{ is_states('binary_sensor.garage_door', 'on') }}"
        open_cover:
          service: switch.turn_on
          entity_id: switch.garasjeport
        close_cover:
          service: switch.turn_on
          entity_id: switch.garasjeport
        stop_cover:
          service: switch.turn_on
          entity_id: switch.garasjeport

But, if the binary_sensor is just a template… don’t even bother with the binary sensor and put whatever the binary sensor’s template into the value_template

cover:
  - platform: template
    covers:
      garage_door:
        device_class: garage
        friendly_name: "Garage Door"
        value_template: >
          {{ whatever'd you'd use for binary_sensor value_template }}
        open_cover:
          service: switch.turn_on
          entity_id: switch.garasjeport
        close_cover:
          service: switch.turn_on
          entity_id: switch.garasjeport
        stop_cover:
          service: switch.turn_on
          entity_id: switch.garasjeport

Remember, translation is handled by home assistant. So if you select the appropriate language for your system, you should always try to let that handle the translations. Less work for you and it makes your code work everywhere because you’re using the untranslated values. Then when you have someone else visit and use the system, they can swap the language to what suits them without impacting your code. Or without it impacting their ability to read statuses.

Thank you. I tried the first code you gave me since I already had a binary_sensor.garage_door that reacts to my magnet door switch (switch.garasjeport_sensor_3) But now the whole cover is greyed out in the front end.

But If I were to use the second code I can use the switch in the template_value?

cover:
  - platform: template
    covers:
      garage_door:
        device_class: garage
        friendly_name: "Garage Door"
        value_template: >
          {{ switch.garasjeport_sensor_3 }}
        open_cover:
          service: switch.turn_on
          entity_id: switch.garasjeport
        close_cover:
          service: switch.turn_on
          entity_id: switch.garasjeport
        stop_cover:
          service: switch.turn_on
          entity_id: switch.garasjeport

Does the switch reflect the state of the garage being open and closed? If it does, it seems odd that close_cover has switch.turn_on service.

I have a relay switch connected to my garage door motor that open and close the door. That is switch.garasjeport. That works. But in order to see if the door is open or closed I have a magnetic switch (switch.garasjeport_sensor_3) that is off or on. When door is open the magnetic switch is “on”.

I made a sensor called sensor.garage_door that gives me the states “Åpen” or “Lukket” based on the state of the magnetic switch. This sensor works.


sensor:
  - platform: template
    sensors:
      garage_door:
        value_template: >- 
          {% if is_state('switch.garasjeport_sensor_3', 'on') %}
            Åpen
          {% else %}
            Lukket
          {% endif %}
        icon_template: >-
          {% if is_state('switch.garasjeport_sensor_3', 'on') %}
            mdi:garage-open
          {% else %}
            mdi:garage
          {% endif %}
        friendly_name: 'Garasjeport'

I also have a binary sensor based on the magnetic switch which has the states “on” and “off”

The garage door motor opens the door if it is closed, and closes it if it is open. It does not reflect the state. The relay switch just give the motor a signal like a remote or physical button hardwired to the motor.

So I put turn on service on all, since the relay switch turns on for a moment to move the door.

ok, then all you need is

cover:
  - platform: template
    covers:
      garage_door:
        device_class: garage
        friendly_name: "Garage Door"
        value_template: "{{ is_state('switch.garasjeport_sensor_3', 'on') }}"
        open_cover:
          service: switch.turn_on
          entity_id: switch.garasjeport
        close_cover:
          service: switch.turn_on
          entity_id: switch.garasjeport
        stop_cover:
          service: switch.turn_on
          entity_id: switch.garasjeport
1 Like

Thank you very much. :slight_smile:

Hi there, I am excited that I found this thread but I still don’t know enough about HA to use it. I have a garage door that has a zwave wireless door sensor on it. I also have a Remotec ZFM-80 zwave relay on the switch. (I had this working on SmartThings for a couple years before I bailed).

On HA, my components are called:
switch.garage_main_door_relay
binary_sensor.garage_main_door_closed

I see the code above, but I don’t know where to put it. This relay needs to be turned off a couple seconds after it is turned on so I’ll have to add that as well with a delay - shouldn’t be a problem.

I don’t quite understand what a cover is. Can anyone point me in the right direction on using this code so I can have a garage door icon on my dashboard? Thank you!

UPDATE:
I wanted to report back that I pretty much used the code above and just put in my own switch and relay names. Since the relay needs to be shut off, I just made an automation in the UI that turns it off if it has been on for 3 seconds. Worked great the first time. Thanks again! :slight_smile:

Hi all!

I try now since a few hours to get this working.

My Garagedoor stays open no matter what I do. I use a switch as “opener” (switch.garage) and have a binary sensor as well…state sensor (binary_sensor.garagentor). This is my current code

cover:
  - platform: template
    covers:
      garage_door:
        device_class: garage
        friendly_name: "Garage Door"
        position_template: "{{ is_states('binary_sensor.garagentor') }}"
        open_cover:
          service: switch.turn_on
          entity_id: switch.garage
        close_cover:
          service: switch.turn_on
          entity_id: switch.garage
        stop_cover:
          service: switch.turn_on
          entity_id: switch.garage

I tried to replace position_template with value_template but this had the effect that the entitiy was not available. I also tried to put an “on” or “off” behind binarysensor line.

Currently the door is closed. Means the sensor shows off.

Hope someone can release me from my misery :slight_smile:

This works for me too for a single door.
How do i add a second switch/sensor combination for a second garage door?

Does anyone know how to put a confirmation dialog on this type of control?

Thats handled through the ui

1 Like

Yes, I understand, but can’t get it to work. Do you happen to have a working example for entities card?

what have you tried?

1 Like

I’ve tried this:

You can’t do it with that ui item. You’ll have to use something that accepts tap_actions

1 Like

Thank you!:slight_smile:

Hi! I had the same issue. Have simple door sensors on my garage and gate, and open/close it via simple RF433 command from Sonoff RF Bridge (so i have 2 scripts - for gate, and for garage).
Try similar to this:

- platform: template
  covers:
      garage_door:
        device_class: garage
        friendly_name: "Garage"
        value_template: "{{ is_state('binary_sensor.garage_contact', 'on') }}"
        open_cover:
          service: script.1621708691102
        close_cover:
          service: script.1621708691102
        stop_cover:
          service: script.1621708691102
      front_gate:
        device_class: gate
        friendly_name: "Gate"
        value_template: "{{ is_state('binary_sensor.gate_contact', 'on') }}"
        open_cover:
          service: script.1621683565039
        close_cover:
          service: script.1621683565039
        stop_cover:
          service: script.1621683565039     
1 Like

My config for garage door with 1 magnetic sensor, work great:

cover:
  - platform: template
    covers:
    # секцию ниже не трогать. Рабочий прототип гаражных ворот
      garage_door:
        device_class: garage
        friendly_name: "гараж"
        unique_id: garagedoor
        value_template: >
          {% if is_state('binary_sensor.vorota_zakryty_contact', 'off') %}
            false
          {% else %}
            true
          {% endif %}
        open_cover:
          - condition: state
            entity_id: binary_sensor.vorota_zakryty_contact
            state: "off"
          - service: switch.turn_on
            target:
              entity_id: switch.gate_remote
        close_cover:
          - condition: state
            entity_id: binary_sensor.vorota_zakryty_contact
            state: "on"
          - service: switch.turn_on
            target:
              entity_id: switch.gate_remote
        stop_cover:
          - service: switch.turn_on
            target:
                entity_id: switch.gate_remote

But i have more complicated configuration. I am using 2 magnetic sensors for garage door. Sensor1 for “closed” state (off if gate is closed) and sensor2 for “open” state (off if gate is opened)
Based on real sensors i create templates:

template:
  - sensor:
      - name: vorota_opening
        state: "on"
      - name: vorota_closing
        state: "on"
      - name: vorota_open
        state: "off"
      - name: vorota_closed
        state: "on"

And appdaemon script:

import appdaemon.plugins.hass.hassapi as hass 

##############################################
### ПОМЕНЯТЬ ПЕРЕМЕННЫЕ ТУТ
##############################################
# имя датчика открытых ворот OpenSensor
open_sensor = "binary_sensor.0x00124b0022fef19f_contact" 
# имя датчика закрытых ворот Clopen_sensoredSensor
closed_sensor = "binary_sensor.vorota_zakryty_contact"

class garage_door_status(hass.Hass):
    def initialize(self):
        handle = None
        # слушем изменение датчиков открытых и закрытых ворот и если оно есть, запускаем функцию garage_door_status
        self.listen_state(self.garage_door_status, open_sensor, attribute="all")
        self.listen_state(self.garage_door_status, closed_sensor, attribute="all")
        # debug only
        self.listen_state(self.garage_door_status, 'cover.test_garage_door', attribute="all")

    def garage_door_status(self, entity, attribute, old, new, kwargs):
        # пишем в лог для траблшутинга, позже можно убрать
        self.log(f'===.input entity={entity}, new state is {new["state"]}. old state is {old["state"]}')
        # делаем проверку, изменился ли статус датчика
        if new["state"] != old["state"]:
            if entity == closed_sensor:
                if old["state"] == "off" and new["state"] == "on":
                    self.log("info 01. set gate to OPENING state")
                    self.set_state('sensor.vorota_closed', state="on")
                    self.set_state('sensor.vorota_closing', state="on")
                    self.set_state('sensor.vorota_open', state="on")
                    self.set_state('sensor.vorota_opening', state="off")
                elif old["state"] == "on" and new["state"] == "off":
                    self.log("info 02. set gate to CLOSED state")
                    self.set_state('sensor.vorota_open', state="on")
                    self.set_state('sensor.vorota_closing', state="on")
                    self.set_state('sensor.vorota_opening', state="on")
                    self.set_state('sensor.vorota_closed', state="off")
            elif entity == open_sensor:
                if old["state"] == "off" and new["state"] == "on":
                    self.log("info 03. set gate to CLOSING state")
                    self.set_state('sensor.vorota_open', state="on")
                    self.set_state('sensor.vorota_opening', state="on")
                    self.set_state('sensor.vorota_closed', state="on")
                    self.set_state('sensor.vorota_closing', state="off")
                elif old["state"] == "on" and new["state"] == "off":
                    self.log("info 04. set gate to OPEN state")
                    self.set_state('sensor.vorota_opening', state="on")
                    self.set_state('sensor.vorota_closed', state="on")
                    self.set_state('sensor.vorota_closing', state="on")
                    self.set_state('sensor.vorota_open', state="off")

So My logic is:

  1. when sensor1 old state is “off” and new state is “on” - then i assume that gate is “opening” (sensor.vorota_opening’, ‘off’)
  2. when sensor2 old state is “off” and new state is “on” - then gate is “open” (sensor.vorota_open’, ‘off’)
  3. when sensor2 old state is “on” and new state is “off” - then gate is “closing” (sensor.vorota_closing’, ‘off’)
  4. when sensor1 old state is “off” and new state is “on” - then gate is “closed” (sensor.vorota_closed’, ‘off’)

On paper it should work fine, but i have strange behaivor in log:
Screenshot_20210919_115019
When sensor.vorota_closed change it state from “off” (means gate is closed) to “on” means (gate is opening) - gate state is changed to “open” and in moment later “opening”

Is some one can explain to me what is my mistake?

Something might be missing where is the code that actually converts the template code into the 4 sensor states?