Convert sonoff switch to lock

Hi, I would like to turn my switch into lock so as to see it on HomeKit as a door, I tried to follow the guide on the ha page but it gives me this error:


Invalid config for [lock.template]: not a valid value for dictionary value @ data['lock'][0]['target']['entity_id']. Got None

not a valid value for dictionary value @ data['unlock'][0]['target']['entity_id']. Got None. (See ?, line ?)

What can I do? Thank u

Maybe show your template ?

lock:
  - platform: template
    name: Portoncino
    value_template: "{{ is_state('sensor.door', 'on') }}"
    lock:
      service: switch.turn_off
      target:
        entity_id: switch.sonoff_ 100103ca88
    unlock:
      service: switch.turn_on
      target:
        entity_id: switch.sonoff_ 100103ca8

I just copied the code from the ha page and entered the sonoff id

Do you actually have an entity called sensor.door ?

You probably want to change this:

value_template: "{{ is_state('sensor.door', 'on') }}"

to:

value_template: "{{ is_state('switch.sonoff_ 100103ca88', 'on') }}"

It gives me the same error when I check the configuration :sleepy:

This is not correct:

switch.sonoff_ 100103ca88
              ^

There are no spaces in entity ids.

lock:
  - platform: template
    name: Portoncino
    value_template: "{{ is_state('switch.sonoff_100103ca88', 'on') }}"
    lock:
      service: switch.turn_on
      data:
        entity_id: switch.sonoff_100103ca88
    unlock:
      service: switch.turn_off
      data:
        entity_id: switch.sonoff_100103ca88

yes, I saw it later, thanks, now it works :pray:

Thanks for the clarification..

My configuration now is this

lock:
  - platform: template
    name: Portoncino
    value_template: "{{ is_state('switch.sonoff_1001010928', 'off') }}"
    lock:
      service: switch.turn_off
      target:
        entity_id: switch.sonoff_1001010928
    unlock:
      service: switch.turn_on
      target:
        entity_id: switch.sonoff_10010310928

I changed the switch and also the initial state. The problem is that if I go to activate or deactivate the switch directly, the lock changes state but if I go to activate or deactivate the lock, the switch does nothing

The example that I gave is how I setup my locks (years ago) and works great
I noticed that you’re using target: while my template uses data: I realize
that the HA template rules are ever-changing but it works without warnings.

Have you tried my example?

yes, i changed target with data but nothing has changed :roll_eyes: