Xiaomi Sherlock Smartlock

Hi Klagio,

Can you please submit a picture with a closeup of the wiring/soldering you did for the Bluetooth button and the ESP8266?

1 Like

I have them in enclosure and a bit hard to reach, butr there are clear photos in this thread

Here you go can’t be more clear then this

In the ESP in super simple.

Put the positive of the battery to the 3,3V, the negative to GND, and the other end of the resistor to D0 (D0 is GPIO16 in nodemcu) so also the blue LED will blink when you lock/unlock.

3 Likes

I am new to ESP8266 / ESP32.

Should I get the ESP32?

Any recommended online sellers? (Gearbest, Ali Express etc)

Both these below work. As for ESP32 you don’t need Bluetooth, actually could cause you interference (Wifi +2 Bluetooth all nearby, bad idea) avoid it. And you don’t need 36 GPIO, just 1 :smiley:

1 Like

Hello, your solution seems to be documented the best and I’m willing to give it a go and try on my lock. Can you please upload yaml file on your gut as well. I mean the part of configuration.yaml that you are using to control the lock.

Finally i found this video “The Hook up” explaining how can battery consumption can be lowered dramatically. https://youtu.be/2kLZ7DlP9KU would love to see this updated with lover power consumption in mind.

Thank you for your efforts.

1 Like

Hi,

Summary of my implementation and consolidating some of this thread for others:

  • Use a hacked fob, ESP32 and ESPhome add-on for Hassio lock/unlock control: Do the hacked fob onto a ESP32/ESP8266 like some others to get Hassio lock/unlock control.

    • Pop apart the fob. Mine came apart ok, but some others have struggled. The face definitely pries off. This post may help: Xiaomi Sherlock Smartlock - #83 by ahzazou
    • Wire it like Klagio and @ahzazou say in this post. Xiaomi Sherlock Smartlock - #233 by Klagio . I hate, and suck at soldering, but I struggled through it. Watch a few YouTube videos for soldering tips.
    • Use Esphome hassio add-on. Use @Klagio 's code (thanks). Here: Xiaomi Sherlock Smartlock - #230 by Klagio. Check online for your GPIO16 pin.
    • I was really unfamiliar with most of the above, but if I can do it, you can too!
    • A ESP8266 may be better than a ESP32. But I wanted to use the fancier ESP32 and maybe use it for BLE presence detection too.
  • Use a Reed switch positioned within the lock for state tracking:

    • Position a reed switch (xiaomi door sensor etc) within the lock to get a reliable state reading (locked/unlocked). I abandoned using a Xiaomi motion/vibration sensor after @burzka cracked a solid reed switch solution. Here: Xiaomi Sherlock Smartlock - #216 by burzka
    • The positioning of mine is a bit unique to my lock type/set-up, but burzka’s solution should work for all?
    • Then for state tracking, (and I’m not sure if this is the same for everyone’s locks, so you may need to tinker), the main logic here is that it takes longer for the lock to do it’s ’unlock’ sequence, than a “lock” sequence. See code.

Some unique features of mine:

  • I can still manually turn/unlock/unlock the lock from inside (like andreyxc, but not as cool), I grasp and turn the stainless steel part.

My challenges:

  • Only a thumb-turn on the inside for me, like in andreyxc 's video. Vertical is locked. Rotate 90 degrees clockwise to unlock (horizontal). Thumb turn width quite wide which meant I couldn’t just reverse the thing-me-bob. I had to build a custom coupling thingo. So quite a lot of modding for it to work on my door. I went through a few iterations, but I got there. See vid.

  • This was my first time using an ESP32 or similar. Total novice to that. ESPhome was pretty easy to get set up, instructions are pretty good. A few hiccups, but some restarts/power cycles seemed to have sorted it.

  • I cut my finger while whittling the custom coupler thingo from wood and walked bleeding down the street to get 4 stiches. Stuuupid😊.

  • The fob only work like 75% of the time? This is even using a spare one manually, the light flashes, but door lock doesn’t respond. The work around is in the script to check if the action was actually effective and try again if not. This actually happened in my vid, so you can see that in action.

Thanks to all those mentioned in the thread.

Video of it working: https://www.youtube.com/watch?v=6M4HUpGbGYk&feature=youtu.be

A quick vid more focused on the mod I made : https://www.youtube.com/watch?v=IV49bL67ZRQ&feature=youtu.be

Main materials for custom coupler:

For state tracking:
In your automation file:

- id: '1755'
  alias: Door was just unlocked
  trigger:
    platform: state
    entity_id: binary_sensor.door_window_sensor_158d0001bf8643
    from: 'off'
    to: 'on'
    for:
      seconds: 1
  action:
- id: '1756'
  alias: Door was just locked
  trigger:
    platform: state
    entity_id: binary_sensor.door_window_sensor_158d0001bf8643
    from: 'off'
    to: 'on'
  action:

For switch which gets it’s state from the automations (I preferred to use a switch template in the end, but you could use the template lock if you like)

switch:
  - platform: template
    switches:
      smartlock:
        friendly_name: "Smart Lock"
        value_template: "{{states.automation.door_was_just_locked.attributes.last_triggered > states.automation.door_was_just_unlocked.attributes.last_triggered }} "
        turn_on:
          service: script.lock_door
        turn_off:
          service: script.unlock_door
        icon_template: >-
          {% if is_state('switch.smartlock', 'on') %}
            mdi:lock
          {% else %}
            mdi:lock-open
          {% endif %}

or for the template lock

  - platform: template
    name: smart lock
    value_template: "{{states.automation.door_was_just_locked.attributes.last_triggered > states.automation.door_was_just_unlocked.attributes.last_triggered }} "
    lock:
      service: script.lock_door
    unlock:
      service: script.unlock_door

And the scripts to fire the ESPhome switches as per Klagios code, which re-fire a few times if they fail.

lock_door:
  sequence:
  - service: switch.turn_on
    entity_id: switch.close_12_home_door
  - delay: '00:00:03'
  - condition: template
    value_template: "{{states.automation.door_was_just_locked.attributes.last_triggered < states.automation.door_was_just_unlocked.attributes.last_triggered}}"
  - service: switch.turn_on
    entity_id: switch.close_12_home_door
  - delay: '00:00:03'
  - condition: template
    value_template: "{{states.automation.door_was_just_locked.attributes.last_triggered < states.automation.door_was_just_unlocked.attributes.last_triggered}}"
  - service: switch.turn_on
    entity_id: switch.close_12_home_door
  - delay: '00:00:03'
  - condition: template
    value_template: "{{states.automation.door_was_just_locked.attributes.last_triggered < states.automation.door_was_just_unlocked.attributes.last_triggered}}"
  - service: switch.turn_on
    entity_id: switch.close_12_home_door

    
unlock_door:
  sequence:
  - service: switch.turn_on
    entity_id: switch.open_12_home_door
  - delay: '00:00:8'
  - condition: template
    value_template: "{{states.automation.door_was_just_locked.attributes.last_triggered > states.automation.door_was_just_unlocked.attributes.last_triggered}}"
  - service: switch.turn_on
    entity_id: switch.open_12_home_door
  - delay: '00:00:8'
  - condition: template
    value_template: "{{states.automation.door_was_just_locked.attributes.last_triggered > states.automation.door_was_just_unlocked.attributes.last_triggered}}"
  - service: switch.turn_on
    entity_id: switch.open_12_home_door
  - delay: '00:00:8'
  - condition: template
    value_template: "{{states.automation.door_was_just_locked.attributes.last_triggered > states.automation.door_was_just_unlocked.attributes.last_triggered}}"
  - service: switch.turn_on
    entity_id: switch.open_12_home_door

Added: 2019-04-27

  1. Made steampunk ESP32 case out of $3 solar light bulb from local crap-store and hung it near the door. I drilled a hole in the bottom for ventilation. Someone tell me if this is a bad idea. I like it! You can keep an eye on the flashing fob led and see the next feature.

  2. Added visual LED indicator for locked/unlocked. From what I can see so far I can only do blue led on/off with what’s onboard my ESP32. Append this to Klagio’s early code under switch:

switch:
  - platform: gpio
    pin:
      number: GPIO2
      inverted: yes
    id: led
  - platform: template
    name: "esp32 led off"
    icon: "mdi:lightbulb"
    turn_on_action:
    - switch.turn_on: led
  - platform: template
    name: "esp32 led on"
    icon: "mdi:lightbulb"
    turn_on_action:
    - switch.turn_off: led
  1. Added a Xiaomi button near my apartment intercom/and where my “grab the things before you go out the door” are so that can I toggle the lock (guests are coming up etc, long press), or I’m leaving (unlock the door). That’s pretty straight forward, but here you are anyway:
#Toggle lock on xiaomi button long press
- id: '17566'
  alias: Toggle Door Lock
  trigger:
    platform: event
    event_type: xiaomi_aqara.click
    event_data:
      entity_id: binary_sensor.switch_158d0001e145a5
      click_type: long_click_press
  action:
    - service: switch.toggle
      entity_id: switch.smartlock
  1. Added auto-lock after door closes. This uses another (different) reed switch/door sensor mounted in the traditional way. The door locks 15 seconds aftert the door closes. Again, pretty straight forward, but there you go:
#Auto lock front door after the DOOR actually closes
- id: '17567'
  alias: Auto Lock Door 15s
  trigger:
    platform: state
    entity_id: binary_sensor.door_window_sensor_158d00031b360f
    from: 'on'
    to: 'off'
    for:
      seconds: 15
  action:
    - service: script.lock_door

Next up:

  • See if I can use the same or my spare ESP32 to also do some BLE presence detection looking for my Mi band 3 and/or phone. (step out of elevator, approach door, door unlocks), like @michel72 seems to be doing here: Xiaomi Sherlock Smartlock - #199 by michel72 (could you share success/details please?).

[Updated 2019-08-01]: I got this working using ESPHome and the same ESP32 that the fob is attached to, but the detection lag was too long to detect me as I apprach door. I went down a ‘Monitor’ path (find that thread).

  • It would be nice if the esp32 can be a somewhat dedicate device with a short scan interval so my Pi doesn’t get stressed out?

  • Update: I am super excited that the esp32 BLE scanner can see my Mi Band 3. Detecting these has been in demand and a big hassle for quite few people, so I’ll share how that goes in a few other threads if it is fruitful.

  • Monitor for reliability.
    [Updated 2019-08-01]: It has been very solid! happy!

[Updated 2020-05-14]: Battery light just started flashing red. meaning I got an amazing 12 months from a single charge!

8 Likes

For the ones who have the vertical key and do not want to modify the lock. I used this mod, just cutting the key and solder it at 90 degrees.

2 Likes

Hi Guys,

did anybody else had the problem that the lock only could be paired to one fob ?

Thanks

I had a few different issues. Try resetting the fobs that won’t add. Hold down the the button until it flashes alternative colors, immediately release the button, and then push the button again. Then re-add. That helped with mine…

Thanks alot for the hint, but it didn’t helped . I think my problem comes from the Android app. After the first fob it gets stuck when I want to add another one . It never goes into the mode where it searches for a new key :frowning:

there is a beta version of the app, you may try that one

Thanks alot for the suggestion. Do you know how I can request access to the beta application ?

Write an email tro them and ask for it

[email protected]

Yes, email them for support with your specific issue. They are pretty responsive and seem to know the fixes. Write really simply as I think it all goes through a translator.

I’m dumping my exchanges here in case it helps someone.


Thank you for quick response.

This fixed it :blush:.

From: cxj <[email protected]>
Sent: Tuesday, 23 April 2019 8:18 PM
To:######### 连骆鑫 <[email protected]>; [email protected]; [email protected]
Subject: Re:RE: Re:Issue setting up Sherlock S2

Intelligent key recovery factory settings: long press button until the traffic lights flashing alternately immediately release the button and then press the button to release.

Hello, please check your operation method is correct.


陈晓军

客服专员

陨石科技/售后部

厦门

------------------ Original ------------------

From: ########

Date: 2019年4月23日(星期二) 下午5:49

To: "连骆鑫"; "[email protected]"; "[email protected]";

Subject: RE: Re:Issue setting up Sherlock S2

Hello,

Now I have another issue.

I bought 4 Smart keys with my Sherlock S2.

2 were added, but then stopped working. The LED still functions as expected, but the door doesn’t respond. I tried to reset them by holding down the button, then I removed them from the app. But now I can’t add them back again. Maybe there is something you can reset on your side for the 2 faulty smart keys so I can use them again?

I was able to add a 3rd one that I hadn’t unboxed yet.

Can you help?

From: ############
Sent: Sunday, 17 March 2019 4:01 PM
To: 连骆鑫 <[email protected]>; [email protected]; [email protected]
Subject: Re: Re:Issue setting up Sherlock S2

Ok. Yes the device has disappeared from app which is good. I will reset and try to set up again.

From: 连骆鑫 <[email protected]>
Sent: Sunday, March 17, 2019 3:59:28 PM
To: ######## [email protected]; [email protected]
Subject: Re: Re:Issue setting up Sherlock S2

hello,

I have already helped you untie the success. You can restore the device to factory settings. Press and hold the function key 6S until the indicator light flashes red and green alternately


连骆鑫

客服专员

陨石科技/售后部

厦门

------------------ Original ------------------

From: ########

Date: Sun, Mar 17, 2019 12:43 PM

To: "连骆鑫"<[email protected]>; "[email protected]"<[email protected]>; "[email protected]"<[email protected]>;

Subject: Re: Re:Issue setting up Sherlock S2

Thankyou.

I am using the most recent app but I’ll check again.

From: 连骆鑫 <[email protected]>
Sent: Sunday, March 17, 2019 3:40:19 PM
To: ########## [email protected]; [email protected]
Subject: Re:Issue setting up Sherlock S2

hello,

I can help you untie the device. You take a photo of the QR code in the battery compartment.

APP question you can see if the app store has an update。


连骆鑫

客服专员

陨石科技/售后部

厦门

------------------ Original ------------------

From:

Date: Sun, Mar 17, 2019 12:34 PM

To: "[email protected]"<[email protected]>; "[email protected]"<[email protected]>;

Subject: Issue setting up Sherlock S2

When I tried to set up my Sherlock S2 the set up process failed.

I have tried reinstalling the app and resetting the device.

My lock shows as testing not complete but when I try to test it says it has been reset and needs to be reinstalled.

But it is not possible to remove the untested lock or reinstall the lock.

I think I have tried all options in the interface and nothing works.

This is very frustrating.

Maybe if you reset my account?

Video:
##Removed##…

1 Like

Agreed, try to be as simple as possible

For those interested, I’m looking into, but struggling with fast arrival presence detection to open the lock.

Hi, anyone has tested a way to open/close/read battery level or state with an esp32 and openmqttgateway acting as BLE?

I think you’ll need to do the fob hack…

But I would like to know battery state and status… Everything available in the app in order to feed mqtt

I don’t think anyone has cracked how to get battery status or true state. Some of us are getting state by using a door sensor within the lock.