Help with new garage template

Hi all, can someone please see why my new config is not working. I’m trying to move to the new template for my garage and gate. I use Sonoff SV for both, and monitor the state with a basic window/door sensor. Nothing too fancy, just a momentary on/off switch.

Old config:

cover:
  - platform: template
    covers:
      garage_door:
        friendly_name: "Garage"
        value_template: "{{ states('binary_sensor.garage_door_window_door_is_open')|regex_replace('on','open')|regex_replace('off','closed') }}"
        open_cover:
          service_template: >
            {% if is_state('binary_sensor.garage_door_window_door_is_open', 'off') %} 
              switch.turn_on
            {% endif %}
          entity_id: switch.sonoff_10008d36fa
        close_cover:
          service_template: >
            {% if is_state('binary_sensor.garage_door_window_door_is_open', 'on') %} 
              switch.turn_on
            {% endif %}
          entity_id: switch.sonoff_10008d36fa
        icon_template: >
          {% if is_state('binary_sensor.garage_door_window_door_is_open', 'on') %}
            mdi:garage-open
          {% else %}
            mdi:garage
          {% endif %}
      gate:
        friendly_name: "Gate"
        value_template: "{{ states('binary_sensor.gate_sensor_window_door_is_open')|regex_replace('on','open')|regex_replace('off','closed') }}"
        open_cover:
          service_template: >
            {% if is_state('binary_sensor.gate_sensor_window_door_is_open', 'off') %} 
              switch.turn_on
            {% endif %}
          entity_id: switch.sonoff_10008d36e9
        close_cover:
          service_template: >
            {% if is_state('binary_sensor.gate_sensor_window_door_is_open', 'on') %} 
              switch.turn_on
            {% endif %}
          entity_id: switch.sonoff_10008d36e9
        icon_template: >
          {% if is_state('binary_sensor.gate_sensor_window_door_is_open', 'on') %}
            mdi:gate
          {% else %}
            mdi:gate
          {% endif %}

New config:

template:
  - cover:
      - name: Garage
        open_cover:
          service: >-
            {% if is_state('binary_sensor.garage_door_window_door_is_open', 'off') %}
              switch.turn_on
            {% endif %}
          entity_id: switch.sonoff_10008d36fa
        close_cover:
          service: >-
            {% if is_state('binary_sensor.garage_door_window_door_is_open', 'on') %}
              switch.turn_on
            {% endif %}
          entity_id: switch.sonoff_10008d36fa
        default_entity_id: cover.garage_door
        icon: >-
          {% if is_state('binary_sensor.garage_door_window_door_is_open', 'on') %}
            mdi:garage-open
          {% else %}
            mdi:garage
          {% endif %}
        state: >-
          {{ states('binary_sensor.garage_door_window_door_is_open') | regex_replace('on','open') | regex_replace('off','closed') }}

      - name: Gate
        open_cover:
          service: >-
            {% if is_state('binary_sensor.gate_sensor_window_door_is_open', 'off') %}
              switch.turn_on
            {% endif %}
          entity_id: switch.sonoff_10008d36e9
        close_cover:
          service: >-
            {% if is_state('binary_sensor.gate_sensor_window_door_is_open', 'on') %}
              switch.turn_on
            {% endif %}
          entity_id: switch.sonoff_10008d36e9
        default_entity_id: cover.gate
        icon: >-
          {% if is_state('binary_sensor.gate_sensor_window_door_is_open', 'on') %}
            mdi:gate
          {% else %}
            mdi:gate
          {% endif %}
        state: >-
          {{ states('binary_sensor.gate_sensor_window_door_is_open') | regex_replace('on','open') | regex_replace('off','closed') }}

Alot of that is outdated and can be optimized.

This goes in your configuration.yaml file.

template:
  - cover:
      - name: Garage
        open_cover:
          action: switch.turn_on
          entity_id: switch.sonoff_10008d36fa
        close_cover:
          action: switch.turn_on
          entity_id: switch.sonoff_10008d36fa
        default_entity_id: cover.garage_door
        device_class: garage
        state: "{{ states('binary_sensor.garage_door_window_door_is_open') }}"

      - name: Gate
        open_cover:
          action: switch.turn_on
          entity_id: switch.sonoff_10008d36e9
        close_cover:
          action: switch.turn_on
          entity_id: switch.sonoff_10008d36e9
        default_entity_id: cover.gate
        device_class: gate
        state: "{{ states('binary_sensor.gate_sensor_window_door_is_open') }}"
1 Like

Thank you. That works. The gate is still showing as unknown and not functional, but I think that’s because the sensor is not working. It used to function without the sensor, but didn’t show the state of the gate (open or close) I’ll put a new sensor on the gate, it’s a bit far, so a zigbee or zwave sensor link is usually weak.