I made a simple lock sensor with Xiaomi Door Sensor, some battery holders and a soldering iron

Probably done many times before but it’s the first time I’ve done something like this.

I’ve got a bunch of Xiaomi door sensors. I saw a youtube video where someone had soldered two points of the sensor to a water sensor matt. I thought why not do it to some battery springs and stick it in my door…and…IT WORKED!

All the bits:

This is the inside of the Xiaomi sensor, you can see the two points I soldered some cables onto:

I then took apart some spare battery holders I had laying around and connected them up:

Cut some little holes for the cables to be routed.

I now have a lock / bolt sensor in my door. Open state is “unlocked” closed state is “locked” just messed around with customize.yaml and all done.

   friendly_name: "Front Door Lock"
   device_class: lock

edit: The spring part is put in the frame and then when the bolt is thrown it completes the circuit and puts the sensor in “locked” mode.


Interesting! So basically you turned it into a contact switch where the bolt connected the two springs? Cool! Will have to try this with a sensor I still have around.

Yeah that’s basically it, good luck (quite easy tbh).

That’s exactly what I’m after!
I’m a little confused though as to how the springs work in thus case
So you have both springs soldiered to the sensor then the bolt goes in and presses them in which closes the circuit?
Could you perhaps upload more photos of the installation please? :grin:

That’s exactly it.

I used springs as I wanted something with some “give”, as the bolt will push against it. Technically no reason you couldn’t measure the depth of the hole and use any other conductive material (even bare wire if you measure it right / use correct placement).

It’s quite a simple process:

  • Open up your Xiaomi door sensor.
  • Solder 2 wires to the sensor (as per the middle photo)
  • Connect those wires to springs (or whichever method you want)
  • Make sure the bolt hits whatever you use to complete the circuit.
  • Whenever the circuit is complete your sensor will report “off”.
  • Use your customize.yaml to change it to a lock (so it reports locked instead of on)
   friendly_name: "Front Door Lock"
   device_class: lock
1 Like

genius, I’m building one today.
The hardest task… Picking which of my boy’s toys I should destroy for the battery holder


Here are a few more ideas in a thread that I started a little while ago:

1 Like

Thanks for the great idea in this post.
I copied your idea, and it works great!

I have a UPVC door, and the black plastic thing is an insert that the lock enters.
The hacked xiaomi door sensor fits easily behind it.
All in all ~1 hour to build this.
Family VERY happy that they can check the lock status remotely!

1 Like

@hijinx Nice implementation man.

A few months later and I found that constant locking/unlocking cycles has started to damage the micro switch.
I now have some spring battery terminals and will alter the sensor to that approach.

Last week my cleaning lady forgot to lock my front door and I thought that I need to find a way to sense if the door is locked or not without changing the lock with a smart one(I kind of don’t trust them) and I came up with almost the same idea but instead of battery springs I will use this kind of micro switch:

It has a roll at the end of the lever which will make the detection of the locking bolts even smoother. I will test it next weekend and share the results with you.

@Knottyboy if you come across my reply… Are you still using this a couple of years later and how’s it holding up? Been looking for this exact use case as I don’t want to destroy the door frame but also don’t want a smart lock.

Anyone also know what gauge wire I’d need for this? I’d like the thinnest possible but obviously needs to also work. I would use jumper cables but I want to run the wires up to the top of the door so will need something a bit longer.

Did this ever work for you?

I finally got around to trying the original post suggestion but sadly it didn’t work well for me. The whole metal section of the door acts as sort of a relay which confuses the sensor when you touch parts of the door. Basically not reliable for me sadly, I think I need an approach that ends up pressing something rather than relying on the signal conducting…