RaZberry Gateway (Door Lock)

Forum rules

Questions about hardware that can be controlled by Indigo (but not through the interfaces and plugins listed). If Indigo doesn't support some bit of hardware you're interested in, and you don't find a 3rd Party Plugin for it, add it to this forum. Be sure to include links to as much information as you can find about it.

Note: adding it here does not mean we're going to add it - in fact it's possible one of our 3rd party developers may decide to write a plugin for it. We add hardware/features based on a lot of different factors beyond just having a request for it.

Posted on
Tue Sep 16, 2014 2:51 pm
iblis offline
Posts: 75
Joined: Sep 16, 2014

RaZberry Gateway (Door Lock)

Hello fellow domotica geeks 8)

I have been testing Indigo for a couple of days now using the z-wave and rfxcom interfaces and I must say that I'm really impressed so far. Coming from Fibaro HC2 that I have been fighting with for the last two years (various bugs, quick fixes and other problems) to just installing Indigo two days ago and everything just works out of the box! It's almost scary, I'm just sitting here waiting for things to f*** up, BUT IT DON'T!!

You guys have done an amazing job with this software. So simple, so elegant, but yet so powerful.

There is only one thing I'm missing from my old setup and that is to interface my z-wave door lock. I know you have a workaround for this by using the Vera Gateway plugin, but unfortunately I do not own a Vera unit. What I got is the RaZberry z-wave controller from Z-Wave.Me interfaced with a Raspberry Pi (using the z-wave.me software, not the open-zwave library).

This setup has been working flawless for me for the past year now setting it up as virtual device in HC2 using LUA with support for Lock, Unlock & Status Update by using the well documented Z-Wave JSON-API that can be found here: http://razberry.z-wave.me/docs/zwayDev.pdf

I don't know my way around Python scripting (yet) and as I mentioned earlier I have only used your software for about two days. So would it be possible and without too much effort from your part to adapt and modify the Vera Gateway Plugin to also work with the RaZberry controller? If not, is it an easier way for me to get basic control over my door lock using RaZberry ? Is it possible to use Python scripting to create a virtual device that will communicate with the RaZberry over JSON-API?

Please point a Indigo newbie in the right direction. :D

All the best,
iblis

Posted on
Tue Sep 16, 2014 3:47 pm
DaveL17 offline
User avatar
Posts: 6742
Joined: Aug 20, 2013
Location: Chicago, IL, USA

RaZberry Gateway (Door Lock)

Welcome!

I'll just say that if you can write LUA, you can learn Python with little effort (probably.)

Indigo works really well with Python and simpleJSON is a terrific JSON handler for Python 2.5.

I've found that working with JSON and XML to be a great approach to handle custom stuff in Indigo scripting.

EDIT-to create a device your best bet may be to write a plugin--basic ones are really pretty easy to create given the SDK.

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Posted on
Tue Sep 16, 2014 5:34 pm
jay (support) offline
Site Admin
User avatar
Posts: 18199
Joined: Mar 19, 2008
Location: Austin, Texas

Re: RaZberry Gateway (Door Lock)

iblis wrote:
I have been testing Indigo for a couple of days now using the z-wave and rfxcom interfaces and I must say that I'm really impressed so far. Coming from Fibaro HC2 that I have been fighting with for the last two years (various bugs, quick fixes and other problems) to just installing Indigo two days ago and everything just works out of the box! It's almost scary, I'm just sitting here waiting for things to f*** up, BUT IT DON'T!!

You guys have done an amazing job with this software. So simple, so elegant, but yet so powerful.


Thanks. That's our goal.

iblis wrote:
There is only one thing I'm missing from my old setup and that is to interface my z-wave door lock. I know you have a workaround for this by using the Vera Gateway plugin, but unfortunately I do not own a Vera unit. What I got is the RaZberry z-wave controller from Z-Wave.Me interfaced with a Raspberry Pi (using the z-wave.me software, not the open-zwave library).

This setup has been working flawless for me for the past year now setting it up as virtual device in HC2 using LUA with support for Lock, Unlock & Status Update by using the well documented Z-Wave JSON-API that can be found here: http://razberry.z-wave.me/docs/zwayDev.pdf

I don't know my way around Python scripting (yet) and as I mentioned earlier I have only used your software for about two days. So would it be possible and without too much effort from your part to adapt and modify the Vera Gateway Plugin to also work with the RaZberry controller? If not, is it an easier way for me to get basic control over my door lock using RaZberry ? Is it possible to use Python scripting to create a virtual device that will communicate with the RaZberry over JSON-API?

Please point a Indigo newbie in the right direction. :D


The Vera Bridge plugin is quite specific to the Vera, so modifying it to support a completely different device is not really something we'd be willing to tackle.

However, as Dave points out, Python and JSON are very well suited to each other (see the SimpleJSON docs). There are several options for you actually, but all will require writing Python. We have extensive documentation on our Python integration and our Plugin API/SDK. I agree with him - if you can script LUA then I suspect picking up Python won't be terribly hard for you (I suspect you'll like it a lot more than LUA once you get into it - it's a fantastic language). And there are far more sources of Python knowledge and modules on the internet than there are for LUA since it's a general-purpose language.

You can use a Virtual On/Off Device and create On and Off (and status if you like) action groups which execute a Python script that uses the JSON API to lock/unlock the lock. You could even write a stay-open Python script that periodically polls the rPi for the status of the lock and updates a variable (which would then automatically update the status of the virtual device). This is probably the fastest way to accomplish the task.

A more complete solution (that could potentially be reusable by others) would be to build a plugin that would create a on/off device to represent the lock. It would do all the necessary processing and would make it look exactly like any other on/off device to Indigo. That could even support multiple devices if you like. See the Example Device - Relay and Dimmer.indigoPlugin example plugin in the SDK for a good starting point.

I don't know much about the RaZberry or what it can do, but if it's a generic Z-Wave controller (akin to the Vera) then you could write a plugin that functions much like the Vera Bridge plugin does - which would expose any devices it controls to Indigo.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Wed Sep 17, 2014 8:07 am
iblis offline
Posts: 75
Joined: Sep 16, 2014

Re: RaZberry Gateway (Door Lock)

Thanks for the reply and all your info. Really appreciate it.

I might have given you the wrong impression that I'm a LUA expert, unfortunately that is far from the truth and my expertise in LUA doesn't go further than copy/paste others work and do some minor modifications to adapt to my needs. :P

But I'm willing to learn and now I got a good reason to learn python so I can create my own plugin for the door lock.

To get me started with this and most important to get my door lock up and running as soon as possible in Indigo I need a couple of pointers.

I want to create a virtual device with 4 functions.

1. Get door lock safe/unsafe status: http://192.168.11.9:8083/ZWaveAPI/Run/d ... mode.value
Response: 0 if unsafe, 255 if safe
2. Get door lock battery status: http://192.168.11.9:8083/ZWaveAPI/Run/d ... last.value
Response: 74 (74 = 74% battery left)
3. Lock the door: http://192.168.11.9:8083/ZWaveAPI/Run/d ... 5D.Set(255)
Response: null
4. Unlock the door: http://192.168.11.9:8083/ZWaveAPI/Run/d ... 2%5D.Set(0)
Response: null

This is the basics of what I need working and I would really appreciate it if somebody could show me the python code and how to add this to a virtual device. Then it's easier for me to get a starting point to learn python scripting so I can add features to the script myself (lock logging, user codes, schedules etc.) and then create my own plugin to share with the community down the road.


All the best,
iblis

Posted on
Wed Sep 17, 2014 10:40 am
jay (support) offline
Site Admin
User avatar
Posts: 18199
Joined: Mar 19, 2008
Location: Austin, Texas

Re: RaZberry Gateway (Door Lock)

Python has a nice built-in libraries for http communication. I suspect you'll want to look at the urllib documentation to use urlopen from your script. The action group would just have one action of type Server Actions->Script and File Actions->Execute Script. Since it's doing network communication (and could timeout) I'd recommend ultimately putting it in a separate Python file (where it can take it's time processing without hanging up other embedded scripts), but certainly for testing you can just use the embedded Python option.

Virtual On/Off Devices don't support battery, though you could write a script that stuck it into a variable. See the Variable Examples in the Indigo Scripting Tutorial in our documentation for examples of setting variable values. You could then just monitor the variable to know when the battery is running down.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Fri Sep 19, 2014 6:08 pm
iblis offline
Posts: 75
Joined: Sep 16, 2014

Re: RaZberry Gateway (Door Lock)

Thanks again for your help and not just showing me the easy way. This way I learn a lot more. :wink:

This is what I have managed to do so far.

First I created two variables.

Function: Variable
Name: DoorLockState
Value: 0 or 255

Function: Variable
Name: DoorLockStateReadable
Value: On or Off

Then I created 3 action group items.

1.
Function: Action Group
Name: Lock the main door
Type1: Embedded Python Script
Code: Select all
import urllib, urllib2
urllib2.urlopen("http://192.168.11.9:8083/ZWaveAPI/Run/devices[2].instances[0].commandClasses[0x62].Set(255)")

Type2: Modify Variable (Variable Actions)
Variable: DoorLockStateReadable
Set to: On

2.
Function: Action Group
Name: Unlock the main door
Type1: Embedded Python Script
Code: Select all
import urllib, urllib2
urllib2.urlopen("http://192.168.11.9:8083/ZWaveAPI/Run/devices[2].instances[0].commandClasses[0x62].Set(0)")

Type2: Modify Variable (Variable Actions)
Variable: DoorLockStateReadable
Set to: Off

3
Function: Action Group
Name: DoorLock - state query
Type: Embedded Python Script
Code: Select all
import urllib, urllib2
urllib2.urlopen("http://192.168.11.9:8083/ZWaveAPI/Run/devices[2].DoorLock.Get()")


The DoorLock - state query will force the RaZberry controller to query the door lock state and update itself.

I then created a scheduled event called Door Lock - State Update that will read the state of the DoorLock on the RaZberry and then update the DoorLockState variable with either 0 or 255 depending on the lock state (0 = Unlocked 255=Locked) every minute. I will try to decrease the time to 30 seconds or less for a more accurate result, but for now I just want to see that it works and I will do the tweaking later.

Function: Scheduled Event
Name: DoorLock - read state
Time: Every 1 minute
Type: Embedded Python Script
Code: Select all
import urllib2
import simplejson
var1 = urllib2.urlopen("http://192.168.11.9:8083/ZWaveAPI/Run/devices[2].DoorLock.data.mode.value")

var2 = var1.read()

indigo.variable.updateValue(1740577043, value=str(var2))


I also created two trigger events that will update the DoorLockStateReadable variable with On or Off depending on the DoorLockState variable. This is to make the result readable for the Virtual On/Off device.

Function: Trigger Event
Name: DoorLockState - Locked
Trigger: Variable Changed
Variable: DoorLockState
Becomes equal to: 255
Condition: Always
Actions: Modify Variable (Variable Actions)
Variable: DoorLockStateReadable
Set to: On

Function: Trigger Event
Name: DoorLockState - Unlocked
Trigger: Variable Changed
Variable: DoorLockState
Becomes equal to: 0
Condition: Always
Actions: Modify Variable (Variable Actions)
Variable: DoorLockStateReadable
Set to: Off

Lastly, I created a Virtual Device called Door Lock with these preferences:

Function: Virtual On/Off Device
Name: Door Lock
Execution Model: Action Groups
On Group: Lock the main door
Off Group: Unlock the main door
Status Variable: DoorLockStateReadable
Status Group: DoorLock - state query

Locking and unlocking the door works good and the link between RaZberry and Indigo is very reliable. If the state of the door lock changes manually by human interference the status on the virtual device will also update within 1 minute (I will try to decrease this number when I get some time for tweaking).

I believe there is something I can do better with the state update so I don't need 2 variables and two triggers to get a readable result for the Virtual Device, but for me to do that I need some help with Python Scripting and JSON.
In the script below as I understand it json reads the output from urllib2 and then adds the value to the indigo.variable. Now, is there a way to get json to convert the value depending on the output from urllib2 before it adds the value to the indigo.variable? So if output is 0 json will convert that to Off and then add it to indigo.variable, but if its 255 it will be converted to On instead. Is this possible :?:

Code: Select all
import urllib2
import simplejson
var1 = urllib2.urlopen("http://192.168.11.9:8083/ZWaveAPI/Run/devices[2].DoorLock.data.mode.value")

var2 = var1.read()

indigo.variable.updateValue(1740577043, value=str(var2))




And as I understand it the Virtual On/Off Device can only use On/Off as status? So if I want to use Locked/Unlocked I need to create a plugin. Is that correct?

PS: Please take into consideration that this is my first Virtual Device I have ever created with Indigo and if you see something wrong or stupid then don't hesitate to speak your mind about it. That is the only way I can learn. :)

Posted on
Sat Sep 20, 2014 1:08 am
iblis offline
Posts: 75
Joined: Sep 16, 2014

Re: RaZberry Gateway (Door Lock)

Another question. How do I add the toggle function to the virtual device?

Posted on
Sun Sep 21, 2014 10:07 am
iblis offline
Posts: 75
Joined: Sep 16, 2014

Re: RaZberry Gateway (Door Lock)

Anyone?

Posted on
Mon Sep 22, 2014 5:01 pm
jay (support) offline
Site Admin
User avatar
Posts: 18199
Joined: Mar 19, 2008
Location: Austin, Texas

Re: RaZberry Gateway (Door Lock)

iblis wrote:
Function: Scheduled Event
Name: DoorLock - read state
Time: Every 1 minute
Type: Embedded Python Script
Code: Select all
import urllib2
import simplejson
var1 = urllib2.urlopen("http://192.168.11.9:8083/ZWaveAPI/Run/devices[2].DoorLock.data.mode.value")

var2 = var1.read()

indigo.variable.updateValue(1740577043, value=str(var2))


I also created two trigger events that will update the DoorLockStateReadable variable with On or Off depending on the DoorLockState variable. This is to make the result readable for the Virtual On/Off device.

Function: Trigger Event
Name: DoorLockState - Locked
Trigger: Variable Changed
Variable: DoorLockState
Becomes equal to: 255
Condition: Always
Actions: Modify Variable (Variable Actions)
Variable: DoorLockStateReadable
Set to: On

Function: Trigger Event
Name: DoorLockState - Unlocked
Trigger: Variable Changed
Variable: DoorLockState
Becomes equal to: 0
Condition: Always
Actions: Modify Variable (Variable Actions)
Variable: DoorLockStateReadable
Set to: Off

Lastly, I created a Virtual Device called Door Lock with these preferences:

Function: Virtual On/Off Device
Name: Door Lock
Execution Model: Action Groups
On Group: Lock the main door
Off Group: Unlock the main door
Status Variable: DoorLockStateReadable
Status Group: DoorLock - state query

Locking and unlocking the door works good and the link between RaZberry and Indigo is very reliable. If the state of the door lock changes manually by human interference the status on the virtual device will also update within 1 minute (I will try to decrease this number when I get some time for tweaking).

I believe there is something I can do better with the state update so I don't need 2 variables and two triggers to get a readable result for the Virtual Device, but for me to do that I need some help with Python Scripting and JSON.
In the script below as I understand it json reads the output from urllib2 and then adds the value to the indigo.variable. Now, is there a way to get json to convert the value depending on the output from urllib2 before it adds the value to the indigo.variable? So if output is 0 json will convert that to Off and then add it to indigo.variable, but if its 255 it will be converted to On instead. Is this possible :?:

Code: Select all
import urllib2
import simplejson
var1 = urllib2.urlopen("http://192.168.11.9:8083/ZWaveAPI/Run/devices[2].DoorLock.data.mode.value")

var2 = var1.read()

indigo.variable.updateValue(1740577043, value=str(var2))


And as I understand it the Virtual On/Off Device can only use On/Off as status? So if I want to use Locked/Unlocked I need to create a plugin. Is that correct?


You're doing pretty much exactly what I would have done. This last part though seems a bit overly complex: rather than sticking the lock state directly into the variable, I'd just insert "on" when the lock is locked and "off" when it's unlocked. It's not a direct parallel of course, but it's close enough (well for me anyway). That would get rid of the extra triggers and variable.

Indigo doesn't currently have a "lock" device type, so even if you built a plugin, you'd still have to decide: either build the lock as a custom device type (in which case it wouldn't have any built-in controls in Indigo Touch) or implement it as a relay device so it uses the standard on/off controls (which is what I did with the Vera Bridge). Nomenclature aside, I really think implementing it as a relay device is the way to go, but again that's IMHO.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Mon Sep 22, 2014 5:04 pm
jay (support) offline
Site Admin
User avatar
Posts: 18199
Joined: Mar 19, 2008
Location: Austin, Texas

Re: RaZberry Gateway (Door Lock)

iblis wrote:
Another question. How do I add the toggle function to the virtual device?


Implement another action group that first looks at the current state of the lock, determines whether it should go on or off, then send the right command. Then you check the Supports Toggle checkbox in the device config and select that action group.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Tue Sep 23, 2014 10:42 am
iblis offline
Posts: 75
Joined: Sep 16, 2014

Re: RaZberry Gateway (Door Lock)

Thanks for the input and explanation jay.

I modified the code in the DoorLock - read state schedule event like this:
Code: Select all
import urllib2
import simplejson
data = urllib2.urlopen("http://192.168.11.9:8083/ZWaveAPI/Run/devices[2].DoorLock.data.mode.value")
json_string = data.read().decode('utf-8')
parsed_json = simplejson.loads(json_string)

if parsed_json == 0:
   indigo.variable.updateValue(1740577043, "Off")
elif parsed_json == 255:
   indigo.variable.updateValue(1740577043, "On")
else:
   indigo.server.log("Error getting Door Lock state")


That way I only need one variable for the lock and the virtual device can read the output. The best way of course would be able to get RaZberry to update the variable when the state changes using the Indigo API so I don't need to poll the status every minute. I will investigate on how to do that later.

One question, is there a way to get indigo.server.log("Error getting Door Lock state") to show RED in the event log?

I solved the toggle issue by adding this script to a action group and then add that to the virtual device:
Code: Select all
myVar = indigo.variables[1740577043]
if myVar.value == "Off":
   indigo.device.turnOn(1907811423)
else:
   indigo.device.turnOff(1907811423)


So everything is working as I want it to now and you can change the subject to Answered if you like.

Thanks for all your help jay. :)

Posted on
Tue Sep 23, 2014 11:29 am
DaveL17 offline
User avatar
Posts: 6742
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: RaZberry Gateway (Door Lock)

There is.

Within a plugin, use:

self.errorLog(u'Message goes here.')

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Posted on
Tue Sep 23, 2014 11:40 am
iblis offline
Posts: 75
Joined: Sep 16, 2014

Re: RaZberry Gateway (Door Lock)

DaveL17 wrote:
There is.

Within a plugin, use:

self.errorLog(u'Message goes here.')


Thanks Dave,

I will test this when I convert the virtual device to a plugin. :wink:

Posted on
Tue Sep 23, 2014 1:00 pm
jay (support) offline
Site Admin
User avatar
Posts: 18199
Joined: Mar 19, 2008
Location: Austin, Texas

Re: RaZberry Gateway (Door Lock)

iblis wrote:
One question, is there a way to get indigo.server.log("Error getting Door Lock state") to show RED in the event log?


Code: Select all
indigo.server.log("Error getting Door Lock state", isError=true)

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 2 guests