Transform a switch in a lock

Hi, I do have two (momentary) switch

switch.open_gate

and

switch.close_gate

Is it possible to transform it in lock. so unlock would trigger switch.open_gate, and lock switch.close_gate?

lock.gate
1 Like

See template lock:

1 Like

Thanks excellent. One big problem for me is that I have no reliable sensor for value_template, and its required.

I could use as value_template which of the two switch was called the latest (if switch.open or switch.closed), but don’t know if this is possible, or how to do it

lock:
  - platform: template
    name: Garage Door
    value_template: "{{ is_state('sensor.skylight.state', 'on') }}"
    lock:
      service: switch.turn_on
      data:
        entity_id: switch.skylight_open
    unlock:
      service: switch.turn_on
      data:
        entity_id: switch.skylight_close

I would imagine that optimistic: true does what you want. I suppose you could try something like {{none}} for the value template.

I haven’t tested this.

Hi, I am having problems to understand. It might be due to the fact I am half ways understanding…

I have a gate. I have a sensor on the gate. I want the gate to be presented as a lock.

Gate binary sensor:
binary_sensor.gate_sensor_956

I have in configuration.yaml:

lock:
  - platform: template
    name: Gate
    value_template: "{{ is_state('binary_sensor.gate_sensor_956', 'off') }}"
    lock:
      service: switch.turn_off
      data:
        entity_id: switch.virtual_vswitch_6
    unlock:
      service: switch.turn_on
      data:
        entity_id: switch.virtual_vswitch_6

The virtual switch:

switch:
  - platform: virtual
    name: vSwitch_6

I created the virtual switch to give an on and off state.
on=closed
off=open

I use it in node red:


(2× flows right to the delay of 20s is to ensure the hate closes if the first one fails)

But a lot of time the lock/unlock does not work…

the gate is controlled via a momentary switch which I “call” in node-red on-off for 2 secs opens or closes it.

Where am I thinking wrongly?

Edit:
Sometimes it just “hangs” and lock/unlock just doesn’t work until I restart homeassistant.
When I use the “vswitch 6” I can correctly control the gate (open / close).

Too hard question :-)?