Update switch state enitity based on a binary_sensor state entity

Hi,

The last 2 days I’m pulling out my hairs to fix the state of my Garagedoor. The toggle does not represent the real state of the door. In other words if i’m opening the door, the toggle goes active for a few seconds and goes back to off while the door is open.

I’m using a Shelly 2PM with a switch. The functionality of opening/closing doors is working just fine.

There is only 1 entity which shows me the actual state of the door:

  • Door closed: binary_sensor.switch_garage1_1_switch_0_input = On
  • Door open: binary_sensor.switch_garage1_1_switch_0_input = Off

I already tried to so many things (also from the forum) but it feels likes i’m going deeper and deeper in the swamp :slight_smile:

My initial guess was, I want to update the state of switch.switch_garage1_1_switch_0 (as you would do in the debug tools) when binary_sensor.switch_garage1_1_switch_0_input to Off . This is what I started with (Automation):

alias: Update Garage switch state
description: ""
triggers:
  - trigger: state
    entity_id:
      - binary_sensor.switch_garage1_1_switch_0_input
    from: null
    to: "off"
conditions: []

But after this things getting complicated for me.

Any ideas how to fix this properly?

  • Gerwin

Create a template cover:

Your value template will be:

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

Both your open and close actions will be to turn on the switch:

        open_cover:
          action: switch.turn_on
          target:
            entity_id: switch.garage1_whatever
        close_cover:
          action: switch.turn_on
          target:
            entity_id: switch.garage1_whatever

Hi @tom_l ,

Wowww an answer within 15 minutes :innocent: . Thanks for the solution, It works with a minor tweak. For whoever is interested, this is the in the full template code (in configuration.yaml) :

cover:
  - platform: template
    covers:
      garage_door:
        device_class: garage
        friendly_name: "Garage Door"
        value_template: "{{ is_state('binary_sensor.switch_garage1_1_switch_0_input', 'off') }}"
        open_cover:
          action: switch.turn_on
          target:
            entity_id: switch.switch_garage1_1_switch_0
        close_cover:
          action: switch.turn_on
          target:
            entity_id: switch.switch_garage1_1_switch_0
1 Like