ZWay: most interesting data for a binary sensor

In order to be able to refresh the persisted state of my binary sensors on my little web application, I extended my "Z-Wave proxy" to send some information when it initially starts. It retrieves data from a few "data holders":
  • The current level (if the sensor is triggered or not).
  • The configured wake-up interval.
  • The last sleep time.
  • The last wake-up time.
  • The battery level.
The following code can be used to do so.


 const ZWBYTE COMMAND_CLASS_ALARM = 113;
 const ZWBYTE COMMAND_CLASS_BATTERY = 128;
 const ZWBYTE COMMAND_CLASS_SENSOR_BINARY = 48;
 const ZWBYTE COMMAND_CLASS_WAKE_UP = 132;
 
 [...]

 bool level = findInstanceDataAsBoolean(aZWay, COMMAND_CLASS_SENSOR_BINARY, "level");
 int wakeUpInterval = findInstanceDataAsInt(aZWay, COMMAND_CLASS_WAKE_UP, "interval");
 int lastSleepTime = findInstanceDataAsInt(aZWay, COMMAND_CLASS_WAKE_UP, "lastSleep");
 int lastWakeUpTime = findInstanceDataAsInt(aZWay, COMMAND_CLASS_WAKE_UP, "lastWakeup");
 int batteryLevel = findInstanceDataAsInt(aZWay, COMMAND_CLASS_BATTERY, "last");

 [...]

bool ZWaveDevice::findInstanceDataAsBoolean(ZWay aZWay, ZWBYTE aCommandClass, const char * aPath) {
 zway_data_acquire_lock(aZWay);
 bool booleanValue;
 ZDataHolder dataHolder = zway_find_device_instance_cc_data(aZWay, mDeviceId, 0, aCommandClass, aPath);
 if(dataHolder != NULL) {
  ZWBOOL value = false;
  zway_data_get_boolean(aZWay, dataHolder, &value);
  switch (value) {
   case 0:
   booleanValue = false;
   break;
   case 1:
   booleanValue = true;
   break;
   default:
   cerr << "Invalid value for level: " << value << endl;
  }
 } else {
  cerr << "No '" << aPath << "' data holder for deviceId=" << (int) mDeviceId << endl;
 }
 zway_data_release_lock(aZWay);
 return booleanValue;
}

int ZWaveDevice::findInstanceDataAsInt(ZWay aZWay, ZWBYTE aCommandClass, const char * aPath) {
 zway_data_acquire_lock(aZWay);
 int intValue = 0;
 ZDataHolder dataHolder = zway_find_device_instance_cc_data(aZWay, mDeviceId, 0, aCommandClass, aPath);
 if(dataHolder != NULL) {
  zway_data_get_integer(aZWay, dataHolder, &intValue);
 } else {
  cerr << "No '" << aPath << "' data holder for deviceId=" << (int) mDeviceId << endl;
 }
 zway_data_release_lock(aZWay);
 return intValue;
}
The last thing I am missing in my system, is the notification for tampering. Unfortunately it seems this Z-Wave command class is not yet supported in the ZWay library. :-( This is visible in the logs as such:
[2013-08-29 08:30:43.561] Got frame from device 2 to controller, but command class 0x71 is not implemented
According to ZWay forums, this should be supported in the future versions...

Comments

  1. i am having same problem. how do we determinate motion sensor is triggered (lets say i have multiple motion sensors)

    ReplyDelete

Post a Comment

Popular posts from this blog

ZWay: getting the device list.

First steps with the ZWay library

Libcurl: perform a REST HTTP PUT