Αssociate a binary sensor state with a switchbot for a cover template

To minimize confusion I’m going to call the actual normal garage door operator pushbutton the “GDO” and the HA controlled button the “switchbot”

Looking at the switchbots I think they only act as kind of a “virtual finger” pressing the GDO button just like you would when you operate the GDO.

So (and correct me if I’m wrong…) when you normally push the GDO you only momentarily push it then immediately release it. If you turn on the switchbot then turn it back off right away doesn’t it just “unpress” the GDO just like you pulling your finger away from the GDO?

Or does your GDO need to be held in position until the door goes all the way closed or open?

I know the way my GDO works is if I push the button momentarily the door operates (open or closed). But if it’s opening and is half way open and I push the GDO again it stops opening and stays in that position. And if it’s going closed and I push the GDO again it stops and goes back open.

I think you guys are looking at this the wrong way. This is a cover, not a switch. Template cover may be what you want.

I agree that is eventually the goal but I’m just trying to work out how the switching works before the template can even be figured out.

It suits to my case!
The problem I have now is that the valid values for value_template are: open / true or closed / false and the binary sensor returns on/off, should I give a try with these values or there is a way to transform them to open/closed ?
One of the examples has the following, should I try it?
value_template: "{{ states('sensor.garage_door')|float > 0 }}"

You can do what ever you want pretty much. That’s why you use a template.

But you can use the ‘on’ value. Here is mine:

value_template: "{{ is_state('binary_sensor.garage_door_north_position_sensor', 'on') }}"

I’m not sure how this fixes your original problem. Won’t your switchbot still be in the wrong state if someone operates the door with the GDO?

I will get the state from the binary sensor, not from the switchbot :wink:

Oh, I thought you wanted the switchbot to take on the state of the door since you already had the state of the door from a door position sensor.

I guess I’m still confused. :crazy_face:

But I’m glad you got it worked out.

So, the default template works perfectly!

  - platform: template
    covers:
      outside_door:
        friendly_name: "Outside Door"
        value_template: "{{ states('binary_sensor.door_window_sensor_158d00026edec3')|regex_replace('on','open')|regex_replace('off','closed') }}"
        open_cover:
          service: switch.turn_on
          data:
            entity_id: switch.switchbot
        close_cover:
          service: switch.turn_off
          data:
            entity_id: switch.switchbot
        stop_cover:
          service: switch.turn_on
          data:
            entity_id: switch.switchbot
        icon_template: >-
          {% if is_state("binary_sensor.door_window_sensor_158d00026edec3", "on") %}
            mdi:garage-open
          {% else %}
            mdi:garage
          {% endif %}```
2 Likes

Can this be used to ask google the state of a sensor?

So, if the sensor is closed or off the switch will also be OFF and google home can tell me that.
If the sensor is open google home mini will tell the switchbot is ON

@cflev May I know how did you add the Switchbot Contact Sensor integration to HA? Thanks.

Shouldn’t the contact-sensor be set-up as a binary-sensor?

Which switchbot device are you referring to? I see a number of products listed on their web page. Which one has the contact-sensor you refer to?

This one:

They do not appear to be supported. I am not 100% sure though. Perhaps open a thread about that specific device, as this thread is about a different switchbot device.

Oh I thought the “binary door sensor” metioned by OP is Switchbot that one. Sorry for that.

I just added switchbot motion and contact sensor to my esp32 implementation

https://community.home-assistant.io/t/switchbot-bot-curtain-meter-contact-motion-mqtt-esp32-bridge-local-control

note: normally a contact sensor would be a binary open/closed, but switchbot returns “open”, "closed’, and “timeout”. so it is just a sensor with 3 possible values

I am running HA on RPi4. May you please tell me what hardware do I need in order to use your library? Thanks.

An esp32, just like it says.