Service homeassistant.toggle does not support lock (Nuki)

Hi,

I have a Nuki lock which is integrated into Home Assistant thank to alexdelprete’s solution.

I would like to control it through my Garmin device and hassIQ widget. For that I included my entity nuki_lock_action into a group configured into the widget. I can see on my Garmin device the current status of the lock but if I want toggle it, I get this error into HA log :

The service homeassistant.toggle does not support entities lock.nuki_lock_action

I find that strange since I can control this entity using toggle action in the UI.

Am I doing something wrong ?

Service homeassistant.toggle doesn’t work with a lock.

Use the services lock.lock or lock.unlock and choose the entity lock.nuki_lock_action.

Let me know if it works. :slight_smile:

I can’t choice the service, HassIQ widget uses only toggle against the entity configured.

So you need to modify the lock into a switch, like it was originally. But if it’s a switch, when you see the lock in the gui you won’t see the actions ready like you see for a lock.

Or…you could create a virtual switch, when off it calls unlock, when on it calls lock.

A template switch is a perfect workaround.
Thanks.

Here you go, it’s a “shadow switch”. Put it in switches.yaml, I chose shadow_nuki_lock for the name, but modify it as you prefer.

It reflects the status from the real lock, it sets the icon based on the state of the real lock and it has the availability config to avoid errors at startup when the sensors are not ready yet.

Obviously, since it’s a shadow, it’s fast like the real one based on the callback. :slight_smile:

- platform: template
  switches:
    shadow_nuki_lock:
      value_template: "{{ is_state('lock.nuki_lock_action', 'locked') }}"
      availability_template: "{{ states('lock.nuki_lock_action') != 'unknown' }}"
      icon_template: >
        {% if states('lock.nuki_lock_action') != 'unknown' %}
          {% if is_state('lock.nuki_lock_action', 'locked') %}
            mdi:lock-outline
          {% elif is_state('lock.nuki_lock_action', 'unlocked') %}
            mdi:lock-open-outline
          {% endif %}
        {% endif %}
      turn_on:
        service: lock.lock
        target:
          entity_id: lock.nuki_lock_action
      turn_off:
        service: lock.unlock
        target:
          entity_id: lock.nuki_lock_action

Thanks. I don’t need the template part since HassIQ doesn’t show the state of the entity, it juste toggle it. I will try with another widget (HassControl) later, may be it could show the state.

PS. I use data: no target: to parameter the service (but both runs fine). What is the difference ?

Leaving the templates is appropriate, because in HA you will see it correctly and you won’t find errors in the logs when you restart HA. The HassIQ will simply not use it. If you have a widget that uses it, you’ll see it.

The official documentation reports this kind of syntax for actions, the fact that it works in both ways doesn’t mean it will still work in the future. I always follow official docs, where possible.

- alias: "Bedroom lights on"
  service: light.turn_on
  target:
    entity_id: group.bedroom
  data:
    brightness: 100

Finally I tried with HassControl widget instead of HassIQ widget. It supports lock entity type (with the corresponding icons) so I doesn’t need anymore a virtual switch. Anyway, thank you for the help :+1: