Zwave Lock Manager

I just updated my fork, so it should be good. Try again, maybe you did it as I was deleting/updating my fork.

Are you running in a docker container? If you’re running in a python venv these instructions should work. I updated the commands for .14

Yes it’s a docker container…do I need to do make before?

That I cannot help with. I’ll let @kevinduong help you out. At least it got me to update my repo. :slight_smile:
It does look like it is having problems installing other dependices

Fail to install minimal dependencies Cython

Not sure if that will help you or not.

Yes, I see that now too…

bash-4.4# pip install homeassistant-pyozw==0.1.4 --no-cache-dir --no-deps --install-option="--flavor=dev"
/usr/local/lib/python3.7/site-packages/pip/_internal/commands/install.py:244: UserWarning: Disabling all use of wheels due to the use of --build-options / --global-options / --install-options.
  cmdoptions.check_install_build_global(options)
Collecting homeassistant-pyozw==0.1.4
  Downloading https://files.pythonhosted.org/packages/2e/48/ffc8e03c7249a68bdf35bc5e9fa2af2222acab16eb4f0022d7626c34e83a/homeassistant_pyozw-0.1.4.zip (147kB)
     |████████████████████████████████| 153kB 3.1MB/s 
Skipping bdist_wheel for homeassistant-pyozw, due to binaries being disabled for it.
Installing collected packages: homeassistant-pyozw
  Running setup.py install for homeassistant-pyozw ... error
    ERROR: Complete output from command /usr/local/bin/python -u -c 'import setuptools, tokenize;__file__='"'"'/tmp/pip-install-fz0y9yvw/homeassistant-pyozw/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-fml2lefy/install-record.txt --single-version-externally-managed --compile --flavor=dev:
    ERROR: sysargv ['-c', 'install', '--record', '/tmp/pip-record-fml2lefy/install-record.txt', '--single-version-externally-managed', '--compile']
    Found SETUP_DIR : /tmp/pip-install-fz0y9yvw/homeassistant-pyozw
    <pyozw_setup.DevTemplate object at 0x7fb50c74cf28>
    Fail to install minimal dependencies Cython
    {'name': 'libopenzwave', 'sources': ['src-lib/libopenzwave/libopenzwave.pyx'], 'include_dirs': ['/config/ptdalen/open-zwave//cpp/src', '/config/ptdalen/open-zwave//cpp/src/value_classes', '/config/ptdalen/open-zwave//cpp/src/platform', '/config/ptdalen/open-zwave//cpp/build/linux'], 'define_macros': [('PY_LIB_VERSION', '0.1.4'), ('PY_SSIZE_T_CLEAN', 1), ('PY_LIB_FLAVOR', 'dev'), ('PY_LIB_BACKEND', 'cython')], 'libraries': ['udev', 'stdc++', 'resolv'], 'extra_objects': ['/config/ptdalen/open-zwave//libopenzwave.a'], 'extra_compile_args': [], 'extra_link_args': [], 'language': 'c++'}
    ['six', 'PyDispatcher>=2.0.5', 'Cython']
    Fail to install minimal dependencies Cython
    running install
    flavor --flavor=dev
    running build_openzwave
    Found g++ : None
    Found gcc : None
    Found make : None
    Found gmake : None
    Found cython : /usr/local/bin/cython
    Found pkg-config : None
    Clean openzwave in /config/ptdalen/open-zwave/ ... be patient ...
    error: [Errno 2] No such file or directory: 'make': 'make'
    ----------------------------------------
ERROR: Command "/usr/local/bin/python -u -c 'import setuptools, tokenize;__file__='"'"'/tmp/pip-install-fz0y9yvw/homeassistant-pyozw/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-fml2lefy/install-record.txt --single-version-externally-managed --compile --flavor=dev" failed with error code 1 in /tmp/pip-install-fz0y9yvw/homeassistant-pyozw/

You’re missing the OS build tools.

Understood but how do I get those tools inside the hassio docker container?

If it was a deb based system you’d use apt-get install make g++ gcc gmake

The host is…not sure what the hassio container is built on…definitely no apt on it

Ok, hassio docker is built on Alpine Linux and to get these packages you need to run apk add alpine-sdk
That will get all the build tools.
Now my error is:
g++: error: /config/ptdalen/open-zwave//libopenzwave.a: No such file or directory
error: command ‘g++’ failed with exit status 1

Ok… So also needed are apk add linux-headers, apk add eudev-dev And apk add openzwave-libs. After that I ran make and make install and finally was able to run pip install. All working now. (not sure if openzwave-libs as well as make and make install are necessary but those are all the steps I took)

So, one of the things I missed from the SmartThings app I was using to manage locks was configurable alerts for each door code. I spent a few hours yesterday adding that to this project. Here’s what I came up with:

What it looks like in LoveLace:

Create the input_boolean for each code slot:

input_boolean:
...
  door_keypad_18_basement_switch:
    name: Basement Door
  code_1_notify:
    name: Notifications
  code_2_notify:
    name: Notifications
  code_3_notify:
    name: Notifications

Add the input_boolean to each code’s Group:

door_keypad_1:
control: hidden
name: Entry Code 1
entities:
  - input_text.door_keypad_1_name
  - input_text.door_keypad_1_code
  - input_boolean.code_1_notify
  - input_select.door_keypad_1_access_schedule
  - input_datetime.door_keypad_1_date_start
  - input_datetime.door_keypad_1_date_end
  - input_boolean.door_keypad_1_front_switch
  - input_boolean.door_keypad_1_basement_switch
  - script.door_keypad_1_delete

And finally - the Automation:

- id: 'notify_on_unlock'
  alias: Notify on Unlock
  initial_state: true
  trigger:
    - platform: state
      entity_id: sensor.front_door_report,sensor.basement_door_report
  condition:
    condition: and
    conditions:
      - condition: template
        value_template: >-
          {{ trigger.to_state.state.lower().startswith('keypad unlock') }}
      - condition: template
        value_template: >-
          {% set object_id = trigger.to_state.entity_id.split(".")[1] %}
          {% set door_unlocked = object_id.split("_")[0] %}
          {% set alarm_level_object_id = 'lock_' ~ door_unlocked ~ '_door_deadbolt_alarm_level' %}
          {% set code_used = states['sensor'][alarm_level_object_id].state %}
          {% set notify_input_object_id = 'code_' ~ code_used ~ '_notify' %}
          {{ states['input_boolean'][notify_input_object_id].state == 'on' }}
  action:
    - service: notify.ios
      data_template:
        title: >-
          {% set object_id = trigger.to_state.entity_id.split(".")[1] %}
          {% set door_unlocked = object_id.split("_")[0] %}
          {% set title = door_unlocked + ' door unlocked by:' %}
          {{ title | title }}
        message: >-
          {% set object_id = trigger.to_state.entity_id.split(".")[1] %}
          {% set door_unlocked = object_id.split("_")[0] %}
          {% set door = door_unlocked + '_door_code' %}
          {{ states['sensor'][door].state }}

Notes:

Your entity_ids probably don’t match mine, so you’ll probably have to comb through the code to change those where appropriate. Also, don’t forget to update the notify service to whatever you’re using.

Hopefully this will help someone along their HomeAssistant journey!

4 Likes

This is great. I’ll add this to my lock package soon. Such a great idea and very easy. I have a separate automation outside this package to notify me if the doors are unlocked while we’re “away”. This is a better option or at least a different option

1 Like

Another addition I’ve made - Updating the Keypad’s Group Name automatically. This just changes the name that shows up in LoveLace and makes it a little easier to remember which code slot belongs to each user.

Add this to your automations.yaml or to the automations section of lock-manager.yaml

- id: 'set_door_code_name'
  alias: Set Door Code Name
  initial_state: true
  trigger:
    - platform: state
      entity_id: input_text.door_keypad_1_name,input_text.door_keypad_2_name,input_text.door_keypad_3_name,input_text.door_keypad_4_name,input_text.door_keypad_5_name,input_text.door_keypad_6_name,input_text.door_keypad_7_name,input_text.door_keypad_8_name,input_text.door_keypad_9_name,input_text.door_keypad_10_name
  condition: []
  action:
    - service: group.set
      data_template:
        object_id: >-
          {% set keypad = trigger.to_state.entity_id.split(".")[1] %}
          {% set number = keypad.split("_")[2] %}
          {% set object_id = 'door_keypad_' + number %}
          {{ object_id }}
        name: >-
          {% set keypad = trigger.to_state.entity_id.split(".")[1] %}
          {% set number = keypad.split("_")[2] %}
          {% set name_object_id = 'door_keypad_' ~ number ~ '_name' %}
          {{ states['input_text'][name_object_id].state }}

Note:

In this code, I’m only watching for the first 10 code slots to change. It’s easy enough to add the rest of your code slots if you wish, just add their names to the list of triggers.

2nd Note:

I just discovered the names revert back on rebooting HA. I may work on a script that fires on HA start that will update all keypad group names to whatever is set in their name field.

Just in case anyone is running hassio in docker, here is how to use @ptdalen zwave branch:

First you would want to git clone his fork, I found it easiest to create a folder inside your config folder which is found in /usr/share/hassio/homeassistant on your host.
Then cd into that directory and:
git clone -b hass https://github.com/ptdalen/open-zwave

Once that is done, execute a shell in your homeassistant container:
docker exec -i -t homeassistant bash
In the container run:
apk update
apk add alpine-sdk openzwave-libs linux-headers eudev-dev

Now you are ready to remove the old and install the new, all inside the container:
export LOCAL_OPENZWAVE=/config/<name of folder you created earlier>/open-zwave
pip uninstall -y homeassistant-pyozw==0.1.4 # this is the current version as of 5/2019
pip install homeassistant-pyozw==0.1.4 --no-cache-dir --no-deps --install-option="--flavor=dev"

Now you should be able to restart your container and it should be installed. As noted I actually ran make and make install inside the container before the last 3 lines but that was mostly to see what packages were missing in the errors. It should not be needed.
You will probably need to do this after every update (not exactly sure how hassio installs its updates).

2 Likes

I am using 6 digit codes, but I cannot get it to generate a random code. I changed the range to be 6 digits, but its just not computing now.

EDIT: There is a range limit, can’t be greater than 100,000, so most you can use is 5 digits, or you will need to use a subset of the most codes you can have. so:

value: ‘{{ range(100000, 200000) | random }}’

Also, I have the same issue with clearing codes. From what I see the delete script doesn’t actually issue the command to clear the code, it only clears it in HA. I could be missing something though.

Edit: Cannot test atm, but this should work:

door_keypad_16_delete:
  alias: Delete Door Code 16
  sequence:
  - service: input_text.set_value
    data:
      value: ''
      entity_id: input_text.door_keypad_16_name
  - service: input_text.set_value
    data:
      value: ''
      entity_id: input_text.door_keypad_16_code
  - service: lock.set_usercode
    data:
      node_id: 5
      code_slot: 16
    data_template:
      usercode: "{{ states.sensor.random_number.state }}"
  - service: input_select.select_option
    data:
      option: 'Disabled'
      entity_id: input_select.door_keypad_16_access_schedule
  - service: input_boolean.turn_off
    entity_id:
    - input_boolean.door_keypad_16_kitchen_switch

I also used the random sensor built into home assistaant

  - platform: random
    name: random number
    minimum: 100000
    maximum: 999999

Also don’t forget to setup an uptime sensor in minutes named sensor.ha_runtime_in_minutes, or the onetime use codes will not clear.

1 Like

Thanks again for this. I updated my main package (3 locks) and tested and it works as expected. Now I just need to put the time into scheduled codes. Like Mon-Fri 8am-5pm, etc. Another one I will eventually get to is, Disable codes when I’m home (presence based). Like for workers, etc. All of these are not that hard to do, just need to create a lot of repetitive codes, inputs, etc.

I feel like once those are done, this will be nearly as good as the lock manager from rboy on smartthings

5 Likes

did you find any info on this? I have 3 kwikset 914 zigbees on ST’ and same boat as you want to move over.

Nope - still stuck. My lock is still on Smartthings. Works really well there, but I’d like to move it to HA. ZigBee seems to be a second class citizen compared to Zwave for some reason.

1 Like

So doe the lock not pair at all with HA? Just curious for the most part. If it pairs, I’d think that although it might take a bit of research, this lock manager for the most part might work.