I posted a feature request a while ago to be able to invert the standard switch-as-a-lock. This seems easy but didn’t get any traction.
Nobody (besides yourself) voted for it. Cross-posting also won’t help.
I’ve responded there, but invert the logic in a template switch. It’s as simple as that.
I saw the solution - it was what I already had implemented. It just seemed in the spirit of WTH to raise this again since there’s half a solution (at least for me) in place already and another (small?) bit of work would mean I can remove some more customisation and use the UI configuration.
This would be a really useful addition. In the electronic security space, it is common to be able to do this so you can deal with different types of locks.
Magnetic locks needs power to lock. Door strikes can be set up to be either power to lock, or power to unlock.
A simple tick box against the helper to invert the behaviour would save having to create template locks and change the ui for a large bunch of doors.
My solution of an inverted template lock added to configuration.yaml.
I need it to show state of the car charger, which is counter logical.
lock:
- platform: template
name: Inversed_Lock
value_template: “{% if is_state(‘lock.original_lock’, ‘unlocked’) %}
locked
{% else %}
unlocked
{% endif %}”
lock:
service: lock.unlock
target:
entity_id: lock.original_lock
unlock:
service: lock.lock
target:
entity_id: lock.original_lock
The title suggests it cannot be done. It can, you just don’t like the way how.
The Spook integration adds an inverted entity. With it you can use the UI to invert the switch, if that is your biggest problem. Then you can use the switch as X to convert it to lock. If you don’t want to use another integration, use a template.
Having inverted logic for each and every domain is creating a lot of complexity in the code, increasing development time and risk of bugs. So I don’t mind having to combine a few things on my end. With the fact that it is already possible, I’d rather have the devs put their time in things we cannot do right now, then making something pretty easy even easier.