Lock Template with input_boolean

Help :slight_smile: I am struggling a lot.

I want to have “lock” entity that controls an input_boolean. I have a gate with a momentory switch to open and close. Pulse to open and pulse to close. A seperate door sensor is attached to see the state. I am trying to build that as a lock… I was almost there, see here:

But then I stopped using a “vswitch” since it seems not supported and I suspect that being the source of my problems and I decided to go for the “helper” and created an input_boolean.
but that seems to give me the same headache.

I have

  1. a helper:
    image

  2. a node red flow controlling the physical switch by sending a “pulse” of 2 secs and then wait for 20secs to see if the door sensor is open/closed. This works really well and I would like to keep that:

  3. I had/have a template lock
    Why? In that “lock” I can also take the door sensor as a sensor for the template and see the correct state.

BUT I cannot get that working… (again, I had it working with a vswitch but that was not reliable. Probably it’s very simple (like everything is when you know it :-).

I struggle with the template lock and the combination with a boolean…

This does not work:

lock:
  - platform: template
    name: Tuin Voor Poort
    value_template: "{{ is_state('binary_sensor.tuin_v_poort_sensor_956', 'off') }}"
    lock:
      service: switch.turn_on
      data:
        entity_id: input_boolean.tuin_voor_poort
    unlock:
      service: switch.turn_off
      data:
        entity_id: input_boolean.tuin_voor_poort

This also does not work:

lock:
  - platform: template
    name: Tuin Voor Poort
    value_template: "{{ is_state('binary_sensor.tuin_v_poort_sensor_956', 'off') }}"
    lock:
      service: input_boolean.turn_on
      data:
        entity_id: input_boolean.tuin_voor_poort
    unlock:
      service: input_boolean.turn_off
      data:
        entity_id: input_boolean.tuin_voor_poort

This also does not work:

lock:
  - platform: template
    name: Tuin Voor Poort Lock
    value_template: "{{ is_state('binary_sensor.tuin_v_poort_sensor_956', 'off') }}"
    lock:
      service: turn_on
      data:
        entity_id: input_boolean.tuin_voor_poort
    unlock:
      service: turn_off
      data:
        entity_id: input_boolean.tuin_voor_poort

What am I missing?

Additionally (this is driving me crazy!) I can set the state manually to “off”:


and the gate closes! (and vice versa when on it opens)

And the color and state of the lock changes in lovelace!?!?:
image

But nothing happens when I press lock/unlock in lovelace!?

WTH!?

Sorry this was wrong. this was about the boolean.

I can set locked/unlocked via this and nothing happesn.

But when I THEN click on “unlock” in lovelace it locks !!?!?

I just canot controll the “lock” via lovelace. WTH?!

Is this a bug?

Changing the state in the dev tools does NOT send the corresponding commands. All it does is change the state. If you pick a light entity and swap the state, the light will remain in the original state but report the one you put (until the next update happens from the switch).

What it CAN do is trigger automations. It will send a state changed event for that entity, even though nothing happened.

But when I THEN click on “unlock” in lovelace it locks !!?!?

When you click ‘unlock’, it will call the ‘set_unlock’ command.

    unlock:
      service: input_boolean.turn_off
      data:
        entity_id: input_boolean.tuin_voor_poort

How did you map this to your virtual switch? Do you have an automation that listens to the input_boolean and calls the virtual switch turn on/off? To me, it sounds like your virtual switch is more like a button where, it has no state…and when you push it, it just runs. Looking at your flow, both open and close to the exact same thing, so this would make sense.

I’m not sure why the close flow will delay for 20 seconds, then check if the sensor is open, then do it again. What if the gate closes within that 20 seconds? The poort sensor would be off. I don’t know how to read node-red, but ist hat a conditional block? I dunno, it might be right, but having 2 identical things for both open and close seems wrong to me. Might as well have one.

Ok, I stopped this road… changed to:

cover:
  - platform: template
    covers:
      tuin_voor_poort_cover:
        device_class: gate
        friendly_name: "Tuin Poort"
        value_template: "{{ is_state('binary_sensor.tuin_v_poort_sensor_956', 'on') }}"
        open_cover:
          service: script.open_gate
        close_cover:
          service: script.close_gate

This works instantly and ok (till now :-))

I am 100% sure there is a bug in combination between “lock template” and “input_boolean”.

Thank you @jocnnor for your support! greatly appreciated.

There might be something that assumes it doesn’t take 20 seconds for a lock to work.

But I could find nothing in the code to support that.

It worked “partially” (mostly did than not) with the “virtual” switch…

1 Like

Ok… bummer… same behaviour…

I am thus absolutely sure the sensor works correctly (I can see it stating on/off when the gat eis opening closing (IMMEDIATELY).

I am really lost here now…

the config is SO SIMPLE:

the cover:
cover:
  - platform: template
    covers:
      tuin_voor_poort_cover:
        device_class: gate
        friendly_name: "Tuin Poort"
        value_template: "{{ is_state('binary_sensor.tuin_v_poort_sensor_956', 'on') }}"
        open_cover:
          service: script.open_gate
        close_cover:
          service: script.close_gate

the scripts:

open_gate:
  alias: open_gate
  sequence:
  - service: input_boolean.turn_on
    data: {}
    entity_id: input_boolean.tuin_voor_poort
  mode: single
  icon: mdi:gate
close_gate:
  alias: close_gate
  sequence:
  - service: input_boolean.turn_off
    data: {}
    entity_id: input_boolean.tuin_voor_poort
  mode: single
  icon: mdi:gate

The helper (add helper --> toggle)

And node red takes care of the physical closure/opening… (sending a pulse of 2 secs to close and/or vice versa)…

WHY DID IT WORK a few hours back and now stopped?! Totally LOST

The Cover entity just does not respond in lovelace.
the boolean immeditely controls node red and opens/closes the gate

Its the combination again between the boolean and the template…

Ok, think I am there… (3rd time :-):

Made:

cover:
  - platform: template
    covers:
      tuin_voor_poort_cover:
        device_class: gate
        friendly_name: "Tuin Poort"
        value_template: "{{ is_state('binary_sensor.tuin_v_poort_sensor_956', 'on') }}"
        open_cover:
          service: script.pulse_gate
        close_cover:
          service: script.pulse_gate
pulse_gate:
  alias: pulse_gate
  sequence:
  - service: switch.turn_on
    data: {}
    entity_id: switch.poort_switch
  - delay: '1'
  - service: switch.turn_off
    data: {}
    entity_id: switch.poort_switch
  mode: single
  icon: mdi:gate

Deleted Node-red flow… will monitor again…