Linear NGDZ00-4 Garage Door

New update. Some things maybe not relevant, just documenting for other’s benefit. Summarizing some steps for the sake of typing…

Running a fresh install of Hassbian 1.23. Z wave installed via the Hassbian PIP script. No issues. Backed up my config and SD card prior to doing this.

Stopped HASS. Ran the following commands:

sudo -u homeassistant -H /bin/bash
source /srv/homeassistant/bin/activate
pip3 uninstall python_openzwave
pip3 install python_openzwave --install-option="--flavor=ozwdev"
deactivate
exit

Copied my options.xml into the /srv/homeassistant/lib/python3.4/site-packages/python_openzwave/ozw_config
I dont know if that step is necessary any more or not, but wanted to make sure my security key was included.

Modified the init.py file to get rid of the z wave requirement

Started Hass. Started OK with the exception of this error in the home-assistant.log
2017-08-10 16:36:38 ERROR (Dummy-21) [libopenzwave] notif_callback exception
Traceback (most recent call last):
File “src-lib/libopenzwave/libopenzwave.pyx”, line 494, in libopenzwave.notif_callback
IndexError: list index out of range

Once the front end loaded, I noticed I lost names on all of my 30+ z wave devices, but I did have a cover component.
NOTE: I had done a secure add of the Linear device previously.

I saw how the new Z wave version uses ozwcache_deviceid.xml vs zwcfg_deviceid.xml so I thought I would test out what would happen if I renamed my old zwcfg to ozwcache. So I stopped HASS, did the rename and started up. Hass loaded the front end then promptly crashed with no errors. Front end just wouldnt load.

Ran the restart command and Hass loaded and my device names were back! But…no cover any more! Same traceback error in my log.

In the Z wave configuration page, I now had two components with the same node (the Linear device). One was:
zwave.unknown_id014f_unknown_type4744_id3030

The other was just
zwave._

Then Hass crashed again. No errors. No nothing.

Restarted HASS. Traceback error in log again. Thought I would try and remove and re add the Linear device. So I removed it (after z wave said it was ready), then ran a secure add. Then Hass crashed again.

Log did show this error:
2017-08-10 16:52:52 WARNING (Thread-12) [openzwave] Can't lock controller for command : add_node

So, too unstable. Flashing my backup image back. Progress, but no stability.

EDIT: Hass MIGHT run stable if I would have left the ozwcache file as is, but losing names on 30+ devices would be 2 days of making everything run again.

Copy your zwcfg over the ozwcache, but try removing the linear device from the XML first.

I already rolled back to my working image. Wouldn’t feel good about running that kind of setup 24/7 right now. Will wait for the official version.

Yes, the latest python_openzwave will work, the problem is when you do this:

pip3 install python_openzwave --install-option="--flavor=ozwdev"

Then you have to make sure you edit:

homeassistant/components/zwave/__init__.py

and edit:

REQUIREMENTS = ['pydispatcher==2.0.5', 'python_openzwave==0.4.0.31']

line so the version matches. I am pretty sure if you don’t do this, when HA starts it will stick the version of python_openzwave from REQUIREMENTS in the ./deps directory because it wants the exact version. ( == vs >= )

2 Likes

I did update homeassistant/components/zwave/__init__.py, but I completely removed the python_openzwave requirement. That entry now looks like this for me:

REQUIREMENTS = ['pydispatcher==2.0.5', ]

I used this sed command in my Dockerfile:

sed -i "s/'python_openzwave==.*'//" /usr/local/lib/python3.5/dist-packages/homeassistant/components/zwave/__init__.py

I’m not using the Dockerfile provided by the project, I wrote my own because I’m not using all the features in the project’s Dockefile.

I had to remove the Linear GDO and re-add it after switching to the Dev branch. It’s working great now. I had to do the same with my Zooz multisensor. It is working great now too.

1 Like

@firstof9 This morning my garage door was at the 66 error. So I go and check, low and behold there is an update. So I make a copy of my SD card and upgrade. Run the script. The first time it bombed somewhere (did not get a snapshot) and now when I run it I get this …

pi@hassbian:~ $ hassctl stop
pi@hassbian:~ $ sudo -u homeassistant -H /bin/bash
homeassistant@hassbian:/home/pi $ source /srv/homeassistant/bin/activate
(homeassistant) homeassistant@hassbian:/home/pi $ pip3 uninstall python_openzwave
Cannot uninstall requirement python-openzwave, not installed
(homeassistant) homeassistant@hassbian:/home/pi $ pip3 install python_openzwave --install-option="--flavor=ozwdev"
/srv/homeassistant/lib/python3.4/site-packages/pip/commands/install.py:194: UserWarning: Disabling all use of wheels due to the use of --build-options / --global-options / --install-options.
  cmdoptions.check_install_build_global(options)
Collecting python_openzwave
  Using cached python_openzwave-0.4.0.35.zip
Requirement already satisfied: six in /srv/homeassistant/lib/python3.4/site-packages (from python_openzwave)
Requirement already satisfied: PyDispatcher>=2.0.5 in /srv/homeassistant/lib/python3.4/site-packages (from python_openzwave)
Installing collected packages: python-openzwave
  Running setup.py install for python-openzwave ... error
    Complete output from command /srv/homeassistant/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-b4k0vaq3/python-openzwave/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-jilemwhl-record/install-record.txt --single-version-externally-managed --compile --install-headers /srv/homeassistant/include/site/python3.4/python-openzwave --flavor=ozwdev:
    ImportError in : from wheel.bdist_wheel import bdist_wheel as _bdist_wheel
    NameError in : class bdist_wheel(_bdist_wheel) - Use bdist_egg instead
    <pyozw_setup.OzwdevTemplate object at 0x762c5af0>
    Requirement already satisfied: Cython in /srv/homeassistant/lib/python3.4/site-packages
    {'include_dirs': ['openzwave-git/open-zwave-Dev/cpp/src', 'openzwave-git/open-zwave-Dev/cpp/src/value_classes', 'openzwave-git/open-zwave-Dev/cpp/src/platform', 'openzwave-git/open-zwave-Dev/cpp/build/linux'], 'extra_objects': ['openzwave-git/open-zwave-Dev/libopenzwave.a'], 'name': 'libopenzwave', 'extra_link_args': [], 'define_macros': [('PY_LIB_VERSION', '0.4.0.35'), ('PY_SSIZE_T_CLEAN', 1), ('PY_LIB_FLAVOR', 'ozwdev'), ('PY_LIB_BACKEND', 'cython')], 'extra_compile_args': [], 'language': 'c++', 'libraries': ['udev', 'stdc++', 'resolv'], 'sources': ['src-lib/libopenzwave/libopenzwave.pyx']}
    ['six', 'PyDispatcher>=2.0.5', 'Cython']
    Requirement already satisfied: Cython in /srv/homeassistant/lib/python3.4/site-packages
    running install
    flavor --flavor=ozwdev
    running build_openzwave
    Found g++ : /usr/bin/g++
    Found gcc : /usr/bin/gcc
    Found make : /usr/bin/make
    Found gmake : None
    Found pkg-config : /usr/bin/pkg-config
    Found library udev : True
    Found library stdc++ : False
    Found library resolv : False
    Found library yaml-0.1 : True
    Found library libopenzwave : False
    Found library python : True
    Found library python2 : True
    Found library python3 : True
    fetching https://codeload.github.com/OpenZWave/open-zwave/zip/Dev into openzwave-git/open-zwave.zip for version 0.4.0.35
    Build openzwave ... be patient ...
    running openzwave_config
    copying openzwave-git/open-zwave-Dev/config/fakro/zws230.xml -> /srv/homeassistant/lib/python3.4/site-packages/python_openzwave/ozw_config/fakro
    copying openzwave-git/open-zwave-Dev/config/fakro/zwrs.xml -> /srv/homeassistant/lib/python3.4/site-packages/python_openzwave/ozw_config/fakro
    copying openzwave-git/open-zwave-Dev/config/fakro/zws12.xml -> /srv/homeassistant/lib/python3.4/site-packages/python_openzwave/ozw_config/fakro
    copying openzwave-git/open-zwave-Dev/config/fakro/zwp10.xml -> /srv/homeassistant/lib/python3.4/site-packages/python_openzwave/ozw_config/fakro
    copying openzwave-git/open-zwave-Dev/config/nodon/crc360xSofremote.xml -> /srv/homeassistant/lib/python3.4/site-packages/python_openzwave/ozw_config/nodon
    copying openzwave-git/open-zwave-Dev/config/nodon/cws3101wallswitch.xml -> /srv/homeassistant/lib/python3.4/site-packages/python_openzwave/ozw_config/nodon
    copying openzwave-git/open-zwave-Dev/config/nodon/msp31xxMicroSmartPlug.xml -> /srv/homeassistant/lib/python3.4/site-packages/python_openzwave/ozw_config/nodon
    copying openzwave-git/open-zwave-Dev/config/nodon/crc3100OctanRemote.xml -> /srv/homeassistant/lib/python3.4/site-packages/python_openzwave/ozw_config/nodon
    copying openzwave-git/open-zwave-Dev/config/nodon/asp3100SmartPlug.xml -> /srv/homeassistant/lib/python3.4/site-packages/python_openzwave/ozw_config/nodon
    copying openzwave-git/open-zwave-Dev/config/nexia/db100z.xml -> /srv/homeassistant/lib/python3.4/site-packages/python_openzwave/ozw_config/nexia
    copying openzwave-git/open-zwave-Dev/config/zipato/RGBBulb2.xml -> /srv/homeassistant/lib/python3.4/site-packages/python_openzwave/ozw_config/zipato
    copying openzwave-git/open-zwave-Dev/config/zipato/zp3102.xml -> /srv/homeassistant/lib/python3.4/site-packages/python_openzwave/ozw_config/zipato
    copying openzwave-git/open-zwave-Dev/config/zipato/vszd2102.xml -> /srv/homeassistant/lib/python3.4/site-packages/python_openzwave/ozw_config/zipato
    copying openzwave-git/open-zwave-Dev/config/zipato/RGBBulb.xml -> /srv/homeassistant/lib/python3.4/site-packages/python_openzwave/ozw_config/zipato
    copying openzwave-git/open-zwave-Dev/config/zipato/MiniKeypad.xml -> /srv/homeassistant/lib/python3.4/site-packages/python_openzwave/ozw_config/zipato
    copying openzwave-git/open-zwave-Dev/config/everspringct/hsm02.xml -> /srv/homeassistant/lib/python3.4/site-packages/python_openzwave/ozw_config/everspringct
    copying openzwave-git/open-zwave-Dev/config/greenwave/powernode6.xml -> /srv/homeassistant/lib/python3.4/site-packages/python_openzwave/ozw_config/greenwave
    copying openzwave-git/open-zwave-Dev/config/greenwave/powernode1.xml -> /srv/homeassistant/lib/python3.4/site-packages/python_openzwave/ozw_config/greenwave
    copying openzwave-git/open-zwave-Dev/config/leviton/vrf01.xml -> /srv/homeassistant/lib/python3.4/site-packages/python_openzwave/ozw_config/leviton
    copying openzwave-git/open-zwave-Dev/config/leviton/rzi10.xml -> /srv/homeassistant/lib/python3.4/site-packages/python_openzwave/ozw_config/leviton
    copying openzwave-git/open-zwave-Dev/config/leviton/vri10.xml -> /srv/homeassistant/lib/python3.4/site-packages/python_openzwave/ozw_config/leviton
    copying openzwave-git/open-zwave-Dev/config/leviton/vrcpg.xml -> /srv/homeassistant/lib/python3.4/site-packages/python_openzwave/ozw_config/leviton
    copying openzwave-git/open-zwave-Dev/config/leviton/vri06.xml -> /srv/homeassistant/lib/python3.4/site-packages/python_openzwave/ozw_config/leviton
    copying openzwave-git/open-zwave-Dev/config/leviton/dzpd3.xml -> /srv/homeassistant/lib/python3.4/site-packages/python_openzwave/ozw_config/leviton
    copying openzwave-git/open-zwave-Dev/config/leviton/dz6hd.xml -> /srv/homeassistant/lib/python3.4/site-packages/python_openzwave/ozw_config/leviton
    copying openzwave-git/open-zwave-Dev/config/leviton/dz15s.xml -> /srv/homeassistant/lib/python3.4/site-packages/python_openzwave/ozw_config/leviton
    copying openzwave-git/open-zwave-Dev/config/heiman/HS1WL-Z.xml -> /srv/homeassistant/lib/python3.4/site-packages/python_openzwave/ozw_config/heiman
    error: could not delete '/srv/homeassistant/lib/python3.4/site-packages/python_openzwave/ozw_config/heiman/HS1WL-Z.xml': Permission denied

    ----------------------------------------
Command "/srv/homeassistant/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-b4k0vaq3/python-openzwave/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-jilemwhl-record/install-record.txt --single-version-externally-managed --compile --install-headers /srv/homeassistant/include/site/python3.4/python-openzwave --flavor=ozwdev" failed with error code 1 in /tmp/pip-build-b4k0vaq3/python-openzwave/
(homeassistant) homeassistant@hassbian:/home/pi $ deactivate
homeassistant@hassbian:/home/pi $ exit

@penright
Issue this command sudo chown -R homeassistant:homeassistant /srv/homeassistant/lib/python3.4/site-packages/python_openzwave/

Then try again.

Looks like it went without error

pi@hassbian:~ $ sudo chown -R homeassistant:homeassistant /srv/homeassistant/lib/python3.4/site-packages/python_openzwave/
pi@hassbian:~ $ hassctl stop                                                    pi@hassbian:~ $ sudo -u homeassistant -H /bin/bash
homeassistant@hassbian:/home/pi $ source /srv/homeassistant/bin/activate
(homeassistant) homeassistant@hassbian:/home/pi $ pip3 uninstall python_openzwave
Cannot uninstall requirement python-openzwave, not installed
(homeassistant) homeassistant@hassbian:/home/pi $ pip3 install python_openzwave --install-option="--flavor=ozwdev"
/srv/homeassistant/lib/python3.4/site-packages/pip/commands/install.py:194: UserWarning: Disabling all use of wheels due to the use of --build-options / --global-options / --install-options.
  cmdoptions.check_install_build_global(options)
Collecting python_openzwave
  Using cached python_openzwave-0.4.0.35.zip
Requirement already satisfied: six in /srv/homeassistant/lib/python3.4/site-packages (from python_openzwave)
Requirement already satisfied: PyDispatcher>=2.0.5 in /srv/homeassistant/lib/python3.4/site-packages (from python_openzwave)
Installing collected packages: python-openzwave
  Running setup.py install for python-openzwave ... done
Successfully installed python-openzwave-0.4.0.35
(homeassistant) homeassistant@hassbian:/home/pi $ deactivate
homeassistant@hassbian:/home/pi $ exit
exit

Ran without errors, even after restarting hass 3 times still getting 66 error. I hope that not the same as order 66. :slight_smile:

What does the first line of OZW_Log.txt say?

Just like always the unhandled 66 command. Is there more I could look at to see?
All other Zwave works.
Who do we ask about merging the fixes at open zwave? I found this emial address ‘[email protected]’.
I was wondering if anyone with hass is also member of the the open zwave team. I don’t want to bug them if there is a better route.

2017-08-15 16:14:36.125 Info, Node012, Sending (Send) message (Callback ID=0x01, Expected Reply=0x00) - Nonce_Report - 0x01, 0x11, 0x00, 0x13, 0x0c, 0x0a, 0x98, 0x80, 0x26, 0xe1, 0xa4, 0x6e, 0x9e, 0x47, 0xc9, 0x4e, 0x05, 0x01, 0xb4:
2017-08-15 16:14:36.134 Detail,   Received: 0x01, 0x04, 0x01, 0x13, 0x01, 0xe8
2017-08-15 16:14:36.135 Detail,   ZW_SEND_DATA delivered to Z-Wave stack
2017-08-15 16:14:36.151 Detail,   Received: 0x01, 0x07, 0x00, 0x13, 0x01, 0x00, 0x00, 0x03, 0xe9
2017-08-15 16:14:36.151 Detail,   ZW_SEND_DATA Request with callback ID 0x01 received (expected 0x01)
2017-08-15 16:14:36.168 Detail, Node012,   Received: 0x01, 0x1d, 0x00, 0x04, 0x00, 0x0c, 0x17, 0x98, 0x81, 0xea, 0x10, 0x06, 0xb9, 0x94, 0x35, 0x9c, 0x15, 0xca, 0x8c, 0x17, 0x5b, 0x26, 0x92, 0x00, 0xb2, 0x18, 0x47, 0x0c, 0x3e, 0x0e, 0xe6
2017-08-15 16:14:36.169 Info, Raw: 0x98, 0x81, 0xea, 0x10, 0x06, 0xb9, 0x94, 0x35, 0x9c, 0x15, 0xca, 0x8c, 0x17, 0x5b, 0x26, 0x92, 0x00, 0xb2, 0x18, 0x47, 0x0c, 0x3e, 0x0e, 0xe6
2017-08-15 16:14:36.169 Detail, Node012, Decrypted Packet: 0x00, 0x66, 0x03, 0xff
2017-08-15 16:14:36.169 Detail, 
2017-08-15 16:14:36.169 Info, Node012, ApplicationCommandHandler - Unhandled Command Class 0x66

head OZW_Log.txt
Should produce: 2017-08-14 18:46:40.176 Always, OpenZwave Version 1.5.2717 Starting Up
or similar. The key is the 1.5.xxxxx version number. If it says 1.4.xxxxx then HA is using the wrong library.

That’s it. So I need to back way to the top to install the beta version?

2017-08-15 13:37:28.347 Always, OpenZwave Version 1.4.2508 Starting Up
2017-08-15 13:37:31.167 Info, Setting Up Provided Network Key for Secure Communications
2017-08-15 13:37:31.168 Info, mgr,     Added driver for controller /dev/zwave
2017-08-15 13:37:31.168 Info,   Opening controller /dev/zwave
2017-08-15 13:37:31.168 Info, Trying to open serial port /dev/zwave (attempt 1)
2017-08-15 13:37:31.169 Info, Serial port /dev/zwave opened (attempt 1)

I’m not sure why the pip uninstall/install isn’t working correctly.
Maybe @hawk259 has some insight?

Trying to reinstall using the script I did the first time.
Just curious why it was giving me the 66 error before I installed. Now I know to look and make sure it is running 1.5.xxx.
I wonder what it would take for open zwave to put the beta into production. If I understand correctly that would keep us from having to jump through hoops.

It has been sitting on resolving deltas: 83% for a while.

pi@hassbian:~/scripts $ sudo ./ha_openzwave.sh

Open Z-Wave Installer for Hassbian
Modified by Landrash for use with Hassbian.
Remodified by unt1tled for use with Linear NGDZ00-4  (barrier_operator).
Remodified by Paul, for Hassbian .48.1 7/18/2017
Copyright(c) 2016 Dale Higgs <https://gitter.im/dale3h>

Running apt-get preparation
Get:1 http://ftp.debian.org jessie-backports InRelease [166 kB]
Hit http://mirrordirector.raspbian.org jessie InRelease
Hit http://repo.mosquitto.org jessie InRelease
Hit http://archive.raspberrypi.org jessie InRelease
Hit http://mirrordirector.raspbian.org jessie/main armhf Packages
Hit http://repo.mosquitto.org jessie/main armhf Packages
Ign http://ftp.debian.org jessie-backports InRelease
Hit http://mirrordirector.raspbian.org jessie/contrib armhf Packages
Hit http://archive.raspberrypi.org jessie/main armhf Packages
Hit http://mirrordirector.raspbian.org jessie/non-free armhf Packages
Hit http://mirrordirector.raspbian.org jessie/rpi armhf Packages
Hit http://archive.raspberrypi.org jessie/ui armhf Packages
Hit http://ftp.debian.org jessie-backports/main Translation-en
Hit http://ftp.debian.org jessie-backports/main armhf Packages
Ign http://repo.mosquitto.org jessie/main Translation-en_GB
Ign http://ftp.debian.org jessie-backports/main Translation-en_GB
Ign http://repo.mosquitto.org jessie/main Translation-en
Ign http://archive.raspberrypi.org jessie/main Translation-en_GB
Ign http://mirrordirector.raspbian.org jessie/contrib Translation-en_GB
Ign http://mirrordirector.raspbian.org jessie/contrib Translation-en
Ign http://archive.raspberrypi.org jessie/main Translation-en
Ign http://mirrordirector.raspbian.org jessie/main Translation-en_GB
Ign http://mirrordirector.raspbian.org jessie/main Translation-en
Ign http://archive.raspberrypi.org jessie/ui Translation-en_GB
Ign http://mirrordirector.raspbian.org jessie/non-free Translation-en_GB
Ign http://mirrordirector.raspbian.org jessie/non-free Translation-en
Ign http://archive.raspberrypi.org jessie/ui Translation-en
Ign http://mirrordirector.raspbian.org jessie/rpi Translation-en_GB
Ign http://mirrordirector.raspbian.org jessie/rpi Translation-en
Fetched 166 kB in 12s (13.1 kB/s)
Reading package lists... Done
W: GPG error: http://ftp.debian.org jessie-backports InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 8B48AD6246925553 NO_PUBKEY 7638D0442B90D010
Reading package lists... Done
Building dependency tree
Reading state information... Done
Calculating upgrade... The following packages were automatically installed and are no longer required:
  easy-rsa libpkcs11-helper1 opensc opensc-pkcs11
Use 'apt-get autoremove' to remove them.
Done
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
Reading package lists... Done
Building dependency tree
Reading state information... Done
libgnutls28-dev is already the newest version.
libgnutlsxx28 is already the newest version.
libssl-dev is already the newest version.
libudev-dev is already the newest version.
make is already the newest version.
python3-dev is already the newest version.
python3-setuptools is already the newest version.
python3-sphinx is already the newest version.
The following packages were automatically installed and are no longer required:
  easy-rsa libpkcs11-helper1 opensc opensc-pkcs11
Use 'apt-get autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
Changing to homeassistant user
homeassistant@hassbian:/home/pi/scripts $ exit
exit
Activating virtualenv
Installing latest version of cython
Cache entry deserialization failed, entry ignored
Requirement already up-to-date: cython==0.24.1 in /srv/homeassistant/lib/python3.4/site-packages
Creating source directory
Cloning python-openzwave
fatal: destination path 'python-openzwave' already exists and is not an empty directory.
Cloning openzwave
error: pathspec 'python3' did not match any file(s) known to git.
Cloning into 'openzwave'...
remote: Counting objects: 25795, done.
remote: Compressing objects: 100% (35/35), done.
remote: Total 25795 (delta 28), reused 33 (delta 13), pack-reused 25745
Receiving objects: 100% (25795/25795), 101.96 MiB | 9.83 MiB/s, done.
Resolving deltas:  83% (14975/18035)

@penright All open-sourced projects suffer from lack of manpower and “got to put the kids to bed” issues. When you have an open-sourced project dependant on other open-sourced projects built with open sourced tools, things may not go as quickly or smoothly as one might want. I am sure the OpenZwave team will say that it will be ready when it is ready.
The alternative is to use a commercial Zwave hub like Wink, to connect your Zwave devices and use Home Assistant to tie things together.

I am sorry if I sounded unappreciative.
In fact, just the opposite.
I did not want to bug them if there was someone else here who knows the time line.
Just looked like they have it working in beta, and since Hass defaults to production, I was curious when they would move the beta to production.

@penright From a post I read on their issues page, they want to squash the remaining open issues listed in their milestone before releasing ‘Version 1.6’ here’s a link to their milestone page.

1 Like

Not suggesting you are unappreciative. Just stating a fact. Most open-sourced projects are under a great deal of pressure to get to some goal and don’t generally respond well to “when”, whether it is asked politely or otherwise. As I stated before, it will be done when it is done. It would be great if it were done tomorrow, but it isn’t likely.

Again, just curious.
Trying to reload using the script we worked out for hasbian, it keep locking up at the resolving deltas.
Sometime it is at 2 % other times as high as 80%.
Not sure why
here is the script

#!/bin/bash

echo
echo "Open Z-Wave Installer for Hassbian"
echo "Modified by Landrash for use with Hassbian."
echo "Remodified by unt1tled for use with Linear NGDZ00-4  (barrier_operator)."
echo "Remodified by Paul, for Hassbian .48.1 7/18/2017"
echo "Copyright(c) 2016 Dale Higgs <https://gitter.im/dale3h>"
echo

if [ "$(id -u)" != "0" ]; then
echo "This script must be run with sudo. Use \"sudo ${0} ${*}\"" 1>&2
exit 1
fi

echo "Running apt-get preparation"
apt-get update
apt-get upgrade -y
apt-get install -y make python3-dev libudev-dev python3-sphinx python3-setuptools libgnutlsxx28 libgnutls28-dev libssl-dev

echo "Changing to homeassistant user"
sudo -u homeassistant -H /bin/bash

echo "Activating virtualenv"
#################
#PE Update from
#source /srv/homeassistant/homeassistant_venv/bin/activate
# to
source /srv/homeassistant/bin/activate
#################

echo "Installing latest version of cython"
### Currently locked to this version since build fails for later versions.
pip3 install --upgrade cython==0.24.1


echo "Creating source directory"
mkdir -p /srv/homeassistant/src
chown -R homeassistant:homeassistant /srv/homeassistant/src

echo "Cloning python-openzwave"
cd /srv/homeassistant/src
git clone  https://github.com/OpenZWave/python-openzwave.git
chown homeassistant:homeassistant python-openzwave
cd python-openzwave

echo "Cloning openzwave"
git checkout python3
rm -rf openzwave
git clone git://github.com/OpenZWave/open-zwave.git openzwave
cd openzwave

echo "Changing to openzwave Dev branch to add barrier_operator support"
git checkout Dev
cd ..

echo "Building python-openzwave with barrier_operator support\nStage 1..."
make build
make install

# Remove the 1.4 non-dev branched compile and replace with the 1.5 dev branch compiled version
rm -Rf openzwave-git/open-zwave-master/
cp -R openzwave/ openzwave-git/
mv openzwave-git/openzwave/ openzwave-git/open-zwave-master/
echo "Building stage 2..."
make install

echo "Deactivating virtualenv"
deactivate
EOF

echo "Creating libmicrohttpd directory"
cd /srv/homeassistant/src
mkdir libmicrohttpd
chown homeassistant:homeassistant libmicrohttpd
cd /srv/homeassistant/src/libmicrohttpd

echo "Downloading libmicrohttpd-0.9.19"
wget ftp://ftp.gnu.org/gnu/libmicrohttpd/libmicrohttpd-0.9.19.tar.gz
chown homeassistant:homeassistant libmicrohttpd-0.9.19.tar.gz
tar zxvf libmicrohttpd-0.9.19.tar.gz
chown homeassistant:homeassistant libmicrohttpd-0.9.19

echo "Building libmicrohttpd-0.9.19"
cd libmicrohttpd-0.9.19
./configure
make
make install

echo "Cloning open-zwave-control-panel"
cd /srv/homeassistant/src
git clone https://github.com/OpenZWave/open-zwave-control-panel.git
chown -R homeassistant:homeassistant open-zwave-control-panel
cd open-zwave-control-panel

echo "Replacing open-zwave-control-panel source files with barrier_operator support"
#wget -O zwavelib.cpp https://raw.githubusercontent.com/legrego/open-zwave-control-panel/0925251a566a36543e0c6b5cb0b2c1498bddfa68/zwavelib.cpp


echo "Building open-zwave-control-panel"
rm Makefile
wget https://raw.githubusercontent.com/home-assistant/fabric-home-assistant/master/Makefile
chown homeassistant:homeassistant Makefile
make

echo "Linking ozwcp config directory"
ln -sd /srv/homeassistant/lib/python3.*/site-packages/libopenzwave-0.*-linux*.egg/config
chown -R homeassistant:homeassistant /srv/homeassistant/src

echo "Linking Home Assistant OpenZWave config directory"
cd /home/homeassistant/.homeassistant
sudo -u homeassistant ln -sd /srv/homeassistant/lib/python3.*/site-packages/libopenzwave-*-linux*.egg/config
chown -R homeassistant:homeassistant /home/homeassistant/.homeassistant

echo
echo "Installation done!"
echo
echo "If you have issues with this script, please contact @Landrash on gitter.im"
echo "Original script by @dale3h on gitter.im"
echo