Combine Switch and Door-Sensor together

Hi,

I have an old electrical driven Garage Door. I added now an Fibaro Door Sensor and a Qubino Relay to the Garage Door and now I can control it via home assistant.

It looks now the following:

image

image

The Status of the Door Sensor is “Offen” and “Geschlossen”

Now I tried to setup a cover and added the following to the configuration.yaml

cover:
  - platform: template
    covers:
      garage_door:
        friendly_name: "Garagentor Cover"
        position_template: "{{ states('sensor.garage_door') }}"
        open_cover:
          service: switch.toggle
          data:
            entity_id: switch.qubino_zmnhnd1_flush_1d_relay_switch
        close_cover:
          service: switch.toggle
          data:
            entity_id: switch.qubino_zmnhnd1_flush_1d_relay_switch
        icon_template: >-
          {% if states('sensor.garage_torstatus') == "Offen"}
            mdi:garage-open
          {% else %}
            mdi:garage
          {% endif %}

I am getting the following error:

2019-02-26 08:15:57 ERROR (MainThread) [homeassistant.config] Invalid config for [cover.template]: invalid template (TemplateSyntaxError: unexpected '}') for dictionary value @ data['covers']['garage_door']['icon_template']. Got '{% if states(\'sensor.garage_torstatus\') == "Offen"}\n mdi:garage-open\n{% else %}\n mdi:garage\n{% endif %}'. (See /config/configuration.yaml, line 683). Please check the docs at https://home-assistant.io/components/cover.template/

Br,
Johannes

This line should end with %}.

Many thanks,

Now I am getting the following error:

could not convert string to float: 'unknown'

And another stupid question. How do I then add this cover-template to the UI?

Br,
Johannes

I assume that this error is related to your position_template. Do you actually have a sensor called sensor.garage_door or is that a copy&paste issue? If you do have that sensor then it will have to return a number between 0 and 100, according to the documentation.

Where does your sensor.garage_torstatus get its value from? Normally, if you have something like a reed sensor that just knows if the door is closed or not, you should have this available as a binary_sensor instead. This in turn could then directly feed into the cover template’s value_template.

Once the cover is defined correctly you should be able to add it into an entities card. The cover will have its own entity id, cover.....

Ok, could be my issue.

You are right, I have an binary sensor for that as well:

would this be then correct?

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

Replace position_template with value_template.

You should be able to simplify this to:
{% if states('binary_sensor.fibaro_system_fgdw002_door_opening_sensor_2_sensor') }

Hi @exxamalte,

I have to revert back my last messages. The mentioned binary_sensor is not true.

Originally it is the follwoing sensor:

It shows “23” when closed and “22” whewn opened.

then I added the following sensor template:

  garage_torstatus:
    value_template: '{% if states.sensor.garagentor_kontakt_access_control %}
     {% if states.sensor.garagentor_kontakt_access_control.state == "23" %}
       Geschlossen
     {% else %}
       Offen
     {% endif %}
     {% else %}
       n/a
     {% endif %}'
    friendly_name: 'Garagentor'
    entity_id: sensor.garagentor_kontakt_access_control  

Br,
Johannes

Meaning that it does not exist? Or it doesn’t correctly switch between on == door open, and off == door closed?

So, if your sensor sensor.garagentor_kontakt_access_control can have two different numeric values indicating whether the garage door is open or closed, I would turn this into a binary_sensor, something like:

binary_sensor:
  - platform: template
    sensors:
      garage_torstatus:
        value_template: "{{ if states.sensor.garagentor_kontakt_access_control.state == "22" }}"
        friendly_name: "Garagentor"
        device_class: garage_door

I don’t exactly know how this behaves if your sensor is unavailable, i.e. the case you were trying to cover with your surrounding if-statement.

The resulting binary_sensor’s entity id can then be used in the cover’s value_template.

@exxamalte

One Step ahead, but still not working.

I have now the following config:

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

binary_sensor:
  - platform: template
    sensors:
      garage_torstatus_binary:
        value_template: >-
          {{ states.sensor.garagentor_kontakt_access_control.state|float == 22 }}
        friendly_name: "Garagentor"
        device_class: garage_door

This delivers me the following binary sensor:

It is “off” when the garage door is closed and “on”, when opened.

On the log I am getting the following error message:

2019-02-27 08:13:18 ERROR (MainThread) [homeassistant.components.cover.template] Received invalid cover is_on state: off. Expected: open, closed, true, false

Br,
Johannes

Good to see that the binary sensor works as expected. If you add this to an entities card in the UI you should now also get a nice garage door icon and “Geschlossen”/“Offen” as state.

Oh, I thought that the binary sensor can be used as-is, but according to the documentation and this error message, that is not the case.
Try this: value_template: "{{ is_state('binary_sensor.garage_torstatus_binary', 'on') }}"

Many thanks!

1 Like

Ok, last question:

How do I get the garage icon “yellow” when opened?

Br,
JOhannes

I don’t think that this is possible; the icon changes, but the colour doesn’t.
This is how my entities look like when the garage door is open - the top entry is the cover, the bottom one is just the garage door’s reed sensor.