Control Lock with a Switch entity

Hi guys,

in my home assistant I have a Nuki device that I can control easily with the app and via dashboards. The lock is places at floor 0 so I would like to control it from floor 1 where bedrooms are. At floor 1 I have a switch (that features also on/off light) that is already exposed in home assistant and that now is not used.

My idea is to open/close the lock using also that switch. I setup an automation to open/close the lock when on/off status is triggered via switch.

What frustrates me and what I am struggling with is that almost every time the state of the lock does not correspond to the state of the switch. Ideally I would like that:

  • when the door is open → the switch is on (so led on)
  • when the door is closed → the switch is off (so led off)

This happens because when controlling the door from other ‘positions’ (e.g. app, dashboard or the door itself) the two states are not paired.

Is there any way to force the state of the switch based on the state of the port?