Controlling and Querying devices

Discussions about Z-Way software and Z-Wave technology in general
Mike Yeager
Posts: 160
Joined: 03 May 2014 07:02

Controlling and Querying devices

Post by Mike Yeager »

I am trying to figure out how to control and query devices from a Python program. I have figured out how to lock and unlock a Kwikset deadbolt using the HTML command:

http://192.168.0.220:8083/ZWaveAPI/Run/ ... 2].Set[255]

Using Set(0) unlocks it. What I'm trying to figure out now is how to query the battery level and current state of the lock. The system that I am running stores data in a database (SQLite3) and acts on it from there in various Python modules as well as a web page. If someone has an idea of how to catch events and update a database from them, I'm listening. I'm sure that catching the events as they are reported to the controller would be far more efficient than polling for them all the time (much friendlier to battery devices as well). Obviously right at the moment I'm concerned with lock events. Lock and unlock events as well as battery are a must. Programming users and tracking which user used the keypad would also be nice.
pofs
Posts: 688
Joined: 25 Mar 2011 19:03

Re: Controlling and Querying devices

Post by pofs »

To query door lock state (don't need to query it after .Set(), it is done automatically):

Code: Select all

/ZWaveAPI/Run/devices[2].DoorLock.Get()
To read door lock state:

Code: Select all

/ZWaveAPI/Run/devices[2].DoorLock.data.mode.value
0xFF means secured, 0xFE means unknown (the bolt is not completely locked/unlocked), others mean unsecured (with different options)

To forcefully query battery value:

Code: Select all

/ZWaveAPI/Run/devices[2].Battery.Get()
To get last reported battery value:

Code: Select all

/ZWaveAPI/Run/devices[2].Battery.data.last.value
In latest HA (Home Automation) UI there's a BatteryPolling module which allows you to query battery level on schedule basis (once a day), and notify if battery level is low.

It is also reasonable not to use external program, but to write a HA module (in javascript). You can bind to value changes and perform callbacks without need to poll values periodically. Though you cannot write into database directly from JS code, you might perform HTTP requests to a web service, which will store data in DB. Or, as another approach, you may invoke sqlite3 program (via system() call) with your query as an argument.
Mike Yeager
Posts: 160
Joined: 03 May 2014 07:02

Re: Controlling and Querying devices

Post by Mike Yeager »

Thank you very much for your reply. This is exactly what I needed to know. I haven't been able to figure out yet how to tap into the module system to help me do what I want to do. Assuming that the lock reports it's battery status fairly regularly and that this call queries the last reported status and doesn't wake the lock every time it's called, it will work for now. I'd much rather find a way to know the moment the lock changes state but for what I'm doing right now, this is good. How much do you know about the locks? Do you know anything about sending access codes to it and reading what code opened it? I realize that the Razberry device is new and the software for it is growing. I'm curious to know what it's capable of doing and going to try to get the most out of it as I learn to do so. I'm sure that I'm going to have to learn the way the modules work eventually to get the most out of it. My current setup is a mix of Arduino devices, Wemo devices and starting to incorporate a Z-Wave devices. Each has it's own strengths so I'm using what fits my needs. Current status page can be seen at http://myeager.no-ip.biz/ and to be honest it's modeled after the Desert Home project (Google Desert Home to see an involved automation project). Next device will be another lock (for the back door) followed by a power monitor to track energy consumption.
pofs
Posts: 688
Joined: 25 Mar 2011 19:03

Re: Controlling and Querying devices

Post by pofs »

The moment lock is opened/closed either DoorLock operation report, or Alarm event to association group 1 might be sent (not sure which). But Kwikset seems to have Alarm version 1, so reported alarm types are vendor-specific, and you must learn them on your own – just add RaZberry to device association group 1.

There's also a DoorLockLogging command class to get a short history of recent events happened to the lock. Each record resides under /ZWaveAPI/Run/devices[2].DoorLockLogging.data.<number>, where <number> is an integer slot number (max number of slots supported is indicated in the /ZWaveAPI/Run/devices[2].DoorLockLogging.data.maxRecords.value), and contains time, event type and id of the user who triggered the event. I'm not sure if events are automatically reported as they happen, so you might need to query them manually (by running /ZWaveAPI/Run/devices[2].DoorLockLogging.Get(<number>), zero means to get most recent record) when some other lock event (alarm or operation report) happens.

To control access codes there's a UserCode command class. It is pretty straightforward, as it has only .Get(userId) and .Set(userId, "code", status) methods. User id is an integer from 1 to /ZWaveAPI/Run/devices[2].UserCode.data.maxUsers.value, or 0 to get/set for all users. Status is either 1 to set code, or 0 to clear it. Code should be 4 to 10 ASCII characters.

Type of user id slot (like owner, guest, employee) can be controlled via configuration parameters of the device. For some of user types schedule can be applied (for example, allow entry only on workdays from 8:00am to 6:00pm). Schedule is done with ScheduleEntryLock command class, but it seems it goes far beyond this post :) Check dev documentation and include files for that.
Mike Yeager
Posts: 160
Joined: 03 May 2014 07:02

Re: Controlling and Querying devices

Post by Mike Yeager »

I'll have to experiment with this a bit to truly get it but it seems easy enough. I tried the get usercode command but since I entered the codes at the lock itself, I'm getting a null return. Obviously not going to mess with that at 11pm.... Now that I'm learning a few things, the dev guide may be a little easier to follow. Still not going to be up to the JS stuff anytime soon as I don't need that level of control. Maybe some day soon, but need to understand what I'm doing first...

Am I correct in assuming that these commands are querying the Razberry controller and it's software (for the most part) and not actually polling the lock itself? Since the lock reports it's status when it changes and Z-Way most likely stores this, I'd like to think I'm just checking the last reported status and not actually polling the lock.
Mike Yeager
Posts: 160
Joined: 03 May 2014 07:02

Re: Controlling and Querying devices

Post by Mike Yeager »

Okay, I am learning that when the lock is manually locked or unlocked, the value is not being changed. This, I'm guessing, is because it's being reported as an alarm event as you mentioned above. I'm going to look for it, but how do I associate the Razberry to group 1? When I activate the lock from software, the value is updated immediately. Just doesn't update when operated from the lock itself. Does that make sense?

Edit - Thought I had some idea what I was looking at but I'm lost once again. Was trying to associate the controller to group 1 so I might get the status change updates but all I keep getting are errors. I'll press on with something else and wait for someone a bit more knowledgeable than me to point me in the right direction. To those that monitor this group and do their best to help, please know that those of us who are trying to learn appreciate every bit of it.

Not much luck with the UserCode stuff either. Tried Set and Get, Set works but get returns NULL. Will keep at it...
Mike Yeager
Posts: 160
Joined: 03 May 2014 07:02

Re: Controlling and Querying devices

Post by Mike Yeager »

Update...

I figured out the Kwikset lock. I posted a new thread on it in case anyone is interested. Thanks again Poltos for nudging me along until I figured it out. If nothing else, I've learned how to dig through and find what I need in the documentation and the logs.....
lhf_leo
Posts: 1
Joined: 23 Dec 2014 03:22

Re: Controlling and Querying devices

Post by lhf_leo »

Mike, what I'm trying to do now is to extract and store data from Aeon Labs appliance switch, which is similar to what you did in here. But I'm actually new to zwave, could you help me by teaching me how can I use python script on raspberry pi?
Mike Yeager
Posts: 160
Joined: 03 May 2014 07:02

Re: Controlling and Querying devices

Post by Mike Yeager »

Just saw this message.... It would probably be easier to send you what I have and let you pull it apart and learn from it. Are you fairly proficient in Python?
hp1
Posts: 32
Joined: 09 Jun 2015 07:00

Re: Controlling and Querying devices

Post by hp1 »

So, to set a user code, I should be able to do this:

curl --globoff "http://razberry:8083/ZWaveAPI/Run/devic ... 10,1234,1)"

And this will set user 10 with code 1234?

and then:

curl --globoff "http://razberry:8083/ZWaveAPI/Run/devic ... ode.Get(0)"

Should show me all the users?

I must be doing something wrong, as I just get a 'null' response for both command.
Post Reply