Linear NGDZ00-4 Garage Door

Give this one a shot it should complete the required steps to get your OZW_Log.txt showing version 1.5.xxxx

#!/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 again by firstof9 for use with the dev branch of the OpenZwave Library."
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 <<EOF

echo "Activating virtualenv"
source /srv/homeassistant/homeassistant_venv/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 "Removing old python-openzwave"
pip3 uninstall -y python-openzwave
rm -f /srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/libopenzwave.cpython-34m.so

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 "Replacing openzwave source files to add barrier_operator support"
#wget -O openzwave/config/device_classes.xml https://raw.githubusercontent.com/OpenZWave/open-zwave/c808b7431fb6c28b408e7fdc5492e46420cb6926/config/device_classes.xml
#wget -O openzwave/cpp/src/command_classes/BarrierOperator.cpp https://raw.githubusercontent.com/OpenZWave/open-zwave/c808b7431fb6c28b408e7fdc5492e46420cb6926/cpp/src/command_classes/BarrierOperator.cpp
#wget -O openzwave/cpp/src/command_classes/BarrierOperator.h https://raw.githubusercontent.com/OpenZWave/open-zwave/c808b7431fb6c28b408e7fdc5492e46420cb6926/cpp/src/command_classes/BarrierOperator.h
#wget -O openzwave/cpp/src/command_classes/CommandClasses.cpp https://raw.githubusercontent.com/OpenZWave/open-zwave/c808b7431fb6c28b408e7fdc5492e46420cb6926/cpp/src/command_classes/CommandClasses.cpp

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

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 "Patching __init__.py"
# This should create the file for patching
FILE="./__init__.py.diff"

cat <<EOM >$FILE
*** /srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/homeassistant/components/zwave/__init__.py.old    2017-07-09 19:27:23.264954710 -0700
--- /srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/homeassistant/components/zwave/__init__.py        2017-07-03 10:35:09.826370100 -0700
***************
*** 37,43 ****
  from .discovery_schemas import DISCOVERY_SCHEMAS
  from .util import check_node_schema, check_value_schema, node_name

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

  _LOGGER = logging.getLogger(__name__)

--- 37,44 ----
  from .discovery_schemas import DISCOVERY_SCHEMAS
  from .util import check_node_schema, check_value_schema, node_name

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

  _LOGGER = logging.getLogger(__name__)
EOM

patch -i __init__.py.diff /srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/homeassistant/components/zwave/__init__.py

echo "Clearing HomeAssistant deps directory"
rm -Rf /home/homeassistant/.homeassistant/deps/*

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

You may have to modify the paths depending on your installation. I installed via the AIO installer on my Pi.
Quick way to confirm it’s working is run the OZWCP from the /srv/homeassistant/src/open-zwave-control-panel directory.

the above works on the AIO installation? Correct? Confusing because of the content of the script.

do you run the script as sudo? as which user to start? pi?

Thanks for this.

I’ve been baking my brain trying to find any info on this. pretty much completely new to linux.

never mind the above i got it figured out… i just had to really read the script. duh.

but…

now when i try to run ozwcp i get “command not found”.

looking in the /srv/homeassistant/src/open-zwave-control-panel directory i don’t have the ozwcp file any longer.

what did I do wrong?

If ozwcp is missing that usually means it didn’t compile for some reason, check for errors in the wall of text that’s produced.

It’s been too long and i’ve tried too many other things to see that now.

can i re-run the same script again on the same install of home assistant without it causing additional troubles?

and i guess another thought is…if it’s easy enough to fix with a known patch then why hasn’t it already been incorporated into the main install repository?

It’s still considered an unstable version. Re-running the script will not hurt anything.

I had to basically start over again…

i had another SD card that was setup using the latest hassbian image.

set up all the security stuff (DNS & letsencrypt, etc)

configured zwave & gave it a network key for secure access

both webserver & ozwcp recognized my z-stick.

(i then did a back up to save myself a lot more work if something went wrong)

i modified what i am pretty sure (?) were the appropriate locations for the files in hassbian compared to the AIO.

ran the patch.

added the GDO.

it now sees the GDO in both HA & ozwcp but there are no cover components in home assistant. OZWCP doesn’t have any means to issue open or close commands nor does it recognize the open close position switch.

this is getting really frustrating to have to keep asking questions but i don’t get what i’m not doing right.

i tried re-running the script but then for some reason i lost the ability to log in to the web server so i had to reload my good saved image again.

any ideas on where to go from here?

In OZWCP when everything was detected properly, you get a drop down showing Opened/Closed/Opening/Closing.

You use that drop down (assuming secure pairing completed), setting it “Opened” will open the door, setting “Closed” will close the door. The value will update while the door is in motion as well.

The view from inside HA should look something like this:

@firstof9 did you get your patch for HA to work with the dev branch of OZW?

https://github.com/home-assistant/home-assistant/issues/8323

I have added a script to the Dockerfile that removes python-openzwave, clones the python-openzwave source (branch version via requirements_all.txt) , clones open-zwave master, applies barrier patch, build and install.

I couldn’t get it to work with the dev branch of open-zwave.

What barrier patch are you attempting to use?
You only need to clone the open-zwave dev branch, and apply my small patch to HA.

Think I forgot to put it into the script I posted… here’s a link to it.
https://raw.githubusercontent.com/firstof9/home-assistant/dev/homeassistant/components/cover/zwave.py

Place it in your /srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/homeassistant/components/cover/ directory, or wherever is suitable for the docker version.

Sorry @finity doing this last step after you had HA and OZWCP showing the door should have fixed it in HA for you.

@firstof9 I really appreciate the help on this.

I first used a clean installation of the All-In-One setup and did a straight copy-paste of your last posted script above.

that’s when the ozwcp executable file disappeared.

I tried to run the script again but then i couldn’t connect to the web interface of HA (“could not connect” even though the status of the HA service showed running).

Then I used a previously newly built hassbian setup on which I had already set up all the security related stuff and set a udev rule to make my z-stick location persistent.

That setup could see the z-stick and the GDO in both HA and OZWCP but wasn’t showing the sensors correctly nor any cover component in HA

I ran the same patch on the hassbian setup as you posted above but I modified the script to eliminate any reference to the “homeassistant_venv” (i.e. “source /srv/homeassistant/homeassistant_venv/bin/activate” became “source /srv/homeassistant//bin/activate”). I did that for all lines of the script that referenced the “homeassistant_venv” directory.

After that there was no change to the operation of HA or OZWCP. Both still displayed the sensors incorrectly.

Looking at the OZW_log.txt it still shows v1.4.xxx. So it looks like, for some reason, the patch isn’t taking.

I tried again to rerun the patch, but again, I lost connectivity to the HA webserver.

I have now re-burned my SD card with a backup of the Hassbian setup above.

And for S&G’s I am re-installing the All-In-One installer on a different SD card i have just so i have a known good clean install of a non-hassbian setup to try this on again.

I have never updated the “zwave.py” file yet. Maybe that’s what I’m missing?

I tried looking through the putty log for the time that I ran your patch on the hassbian version.

I see several lines (maybe 30 lines or so) that say, for example, “Proceed (y/n)? Your response (‘rm -f /srv/homeassistant/lib/python3.4/site-packages/libopenzwave.cpython-34m.so’) was not one of the expected responses: y, n”.

Another line says “mkdir: cannot create directory ‘libmicrohttpd’: File exists”

Yet another line says “fatal: destination path ‘open-zwave-control-panel’ already exists and is not an empty directory.”

then a later couple of lines:
“Linking ozwcp config directory
ln: failed to create symbolic link ‘./config’: File exists”

Then the installation reports as done.

I don’t know if any of those errors are a serious problem but I expect they are. I just don’t know how to fix them.

I will try to run your latest patch script again on a new installation using the AIO installer and then update the zwave.py file according to your link above and see where I stand then.

Unless you are seeing some other glaring error in what I’m doing?

I’m not sure what you mean when you say you are using the dev version of OZWCP.

Is the OZWCP included in the AIO installer not the dev version? Could that be why your patch script won’t work?

This is the part that needs to work in order to get the updated version, so you don’t use a venv, I’ll see about modifying it for your version.

@firstof9

Awesome!

thank you!

This has definitely been a crash course in linux for me!

@firstof9 I believe Hasbian uses a venv, it just doesn’t create a separate folder.

@firstof9

i just created a brand new clean install using AIO

ran your patch as last listed above.

added the changes to zwave.py

now, HA sees 2 zwave devices and both say “ready” but neither show any names.

there are some sensors that show up in the entities list but nothing referring to a cover component.

when i try to run OZWCP (switching to the directory & running the ozwcp command from there) it says “command not found”.

doing a search for “ozwcp” shows the file doesn’t exist.

Should the script above work for the AIO installer version with no modifications?

how could i just re-install ozwcp from this point? i don’t know what the commands would be to do that.

@firstof9 I am currently using the original patch to OZW on the release branch. Thanks for the cover/zwave.py link, I will work on updating my script to patch HA as well as using OZW dev branch to help test.

Question about your cover/zwave.py patch: Should it work with the a patch OZW from the release branch?

I am wondering if there are cases where COMMAND_CLASS_BARRIER_OPERATOR would be a bool again instead of list. Or would will it always be a list?

They have it now as a list, they said they prefer that method over the previous bool setting that existed.

It shouldn’t break anything as the only parts modified where regarding the GDO devices.

These commands will take you to the OZWCP directory and tell it to compile, let me know if any errors occur we’ll get them debugged :smiley:

cd /srv/homeassistant/src/open-zwave-control-panel
make

It should work modified or not on an AIO install.

@firstof9

Here is the response when switching to the listed directory and running “make”:

g++ -o ozwcp -g ozwcp.o webserver.o zwavelib.o /srv/homeassistant/src/python-openzwave/openzwave/libopenzwave.a -lgnutls /usr/local/lib/libmicrohttpd.a -pthread -ludev
webserver.o: In function Webserver::SendTopoResponse(MHD_Connection*, char const*, char const*, char const*, char const*)': /srv/homeassistant/src/open-zwave-control-panel/webserver.cpp:338: warning: the use of mktemp’ is dangerous, better use mkstemp' or mkdtemp’
/srv/homeassistant/src/python-openzwave/openzwave/libopenzwave.a(DNSImpl.o): In function OpenZWave::DNSImpl::LookupTxT(std::string, std::string&)': DNSImpl.cpp:(.text+0x54): undefined reference to __res_query’
DNSImpl.cpp:(.text+0x6c): undefined reference to ns_initparse' DNSImpl.cpp:(.text+0x84): undefined reference to ns_parserr’
collect2: error: ld returned 1 exit status
Makefile:71: recipe for target ‘ozwcp’ failed
make: *** [ozwcp] Error 1

Edit the file Makefile in that directory modified line 38 to this:

LIBS := -lresolv $(LIBZWAVE) $(GNUTLS) $(LIBMICROHTTPD) -pthread $(LIBUSB)

and re-run the command make that will fix it up. I had forgotten about that little quirk as well, sorry.