SensorValueLogging with Fibaro FGFS-101

Discussions about existing Z-Wave device and their usage with Z-Way/Z-Cloud/Z-Box
Post Reply
User avatar
kambis
Posts: 36
Joined: 23 Jun 2014 08:06
Location: Germany
Contact:

SensorValueLogging with Fibaro FGFS-101

Post by kambis »

My aim is to set up the SensorValueLogging home-automation module to send Fibaro's Flood sensor (FGFS-101) events to a remote sever for further actions. Below a screenshot of successfully included Flood sensor (with no assosiations):
floodsensor.png
floodsensor.png (52.51 KiB) Viewed 14061 times
As a result the Z-Way-Server creates widgets related to this sensor for home automation actions:
floodsensor-widgets.png
floodsensor-widgets.png (131.69 KiB) Viewed 14061 times
Here the entries in the log file telling more in detail about the 4 created virtual devices:
  • Creating device sensorBinary ZWayVDev_12:0:48:1
    Creating device battery ZWayVDev_12:0:128
    Creating device sensorBinary ZWayVDev_12:1:48:1
    Creating device sensorMultilevel ZWayVDev_12:2:49:1
Two binary sensors are now available: I assume one is for water-alarm and the second one is for tilt-alarm. So I created two SensorValueLogging settings for both binary sensors in the automation panel:
floodsensor-automation.png
floodsensor-automation.png (21.39 KiB) Viewed 14061 times
Unfortunately the SensorValueLogging module gets never triggered :(
Looking in the z-wave-server log file gives me an idea why. When tilting the sensor then following messages appear in the log file:
  • RECEIVED: ( 01 11 00 04 00 0C 0B 60 0D 02 02 9C 02 0C 00 FF 00 00 ED )
    SENT ACK
    SETDATA devices.12.data.lastReceived = 0 (0x00000000)
    SETDATA devices.12.instances.2.commandClasses.156.data.0.srcId = 12 (0x0000000c)
    SETDATA devices.12.instances.2.commandClasses.156.data.0.sensorState = 255 (0x000000ff)
    SETDATA devices.12.instances.2.commandClasses.156.data.0.sensorTime = 0 (0x00000000)
If my understanding is correct, to trigger this event I need to have a widget named: ZWayVDev_12:2:156:0
Can someone tell me if I'm right, or not?

Next test was to activate the water-alarm. The result in the log file is:
  • RECEIVED: ( 01 0D 00 04 00 0C 07 60 0D 01 01 20 01 FF 4E )
    SENT ACK
    SETDATA devices.12.data.lastReceived = 0 (0x00000000)
    SETDATA devices.1.instances.1.commandClasses.32.data.srcNodeId = 12 (0x0000000c)
    SETDATA devices.1.instances.1.commandClasses.32.data.srcInstanceId = 1 (0x00000001)
    SETDATA devices.1.instances.1.commandClasses.32.data.level = 255 (0x000000ff)
    RECEIVED: ( 01 0D 00 04 00 0C 07 60 0D 01 01 20 01 00 B1 )
    SENT ACK
    SETDATA devices.12.data.lastReceived = 0 (0x00000000)
    SETDATA devices.1.instances.1.commandClasses.32.data.srcNodeId = 12 (0x0000000c)
    SETDATA devices.1.instances.1.commandClasses.32.data.srcInstanceId = 1 (0x00000001)
    SETDATA devices.1.instances.1.commandClasses.32.data.level = 0 (0x00000000)
Now in this case I was surprised not even to see alarm data from sensor. Only the controller seems to emit an event in the event bus. So how can I catch those data in my SensorValueLogging module to send event notifications to a remote server?
pofs
Posts: 688
Joined: 25 Mar 2011 19:03

Re: SensorValueLogging with Fibaro FGFS-101

Post by pofs »

kambis wrote:Looking in the z-wave-server log file gives me an idea why. When tilting the sensor then following messages appear in the log file:
  • RECEIVED: ( 01 11 00 04 00 0C 0B 60 0D 02 02 9C 02 0C 00 FF 00 00 ED )
    SENT ACK
    SETDATA devices.12.data.lastReceived = 0 (0x00000000)
    SETDATA devices.12.instances.2.commandClasses.156.data.0.srcId = 12 (0x0000000c)
    SETDATA devices.12.instances.2.commandClasses.156.data.0.sensorState = 255 (0x000000ff)
    SETDATA devices.12.instances.2.commandClasses.156.data.0.sensorTime = 0 (0x00000000)
If my understanding is correct, to trigger this event I need to have a widget named: ZWayVDev_12:2:156:0
Can someone tell me if I'm right, or not?
Yes, you're right. But alarm sensors (class 156) are currently not present in the UI, so you can't use SensorValueLogging for them.
kambis wrote: Next test was to activate the water-alarm. The result in the log file is:
  • RECEIVED: ( 01 0D 00 04 00 0C 07 60 0D 01 01 20 01 FF 4E )
    SENT ACK
    SETDATA devices.12.data.lastReceived = 0 (0x00000000)
    SETDATA devices.1.instances.1.commandClasses.32.data.srcNodeId = 12 (0x0000000c)
    SETDATA devices.1.instances.1.commandClasses.32.data.srcInstanceId = 1 (0x00000001)
    SETDATA devices.1.instances.1.commandClasses.32.data.level = 255 (0x000000ff)
    RECEIVED: ( 01 0D 00 04 00 0C 07 60 0D 01 01 20 01 00 B1 )
    SENT ACK
    SETDATA devices.12.data.lastReceived = 0 (0x00000000)
    SETDATA devices.1.instances.1.commandClasses.32.data.srcNodeId = 12 (0x0000000c)
    SETDATA devices.1.instances.1.commandClasses.32.data.srcInstanceId = 1 (0x00000001)
    SETDATA devices.1.instances.1.commandClasses.32.data.level = 0 (0x00000000)
Now in this case I was surprised not even to see alarm data from sensor. Only the controller seems to emit an event in the event bus. So how can I catch those data in my SensorValueLogging module to send event notifications to a remote server?
This doesn't trigger anything on device itself, but sends Basic set to other device (controller) instead. You couldn't apply SensorValueLogging to controller as well. If you change parameter 5 of the device from 255 to 0, it should send Alarms instead.
User avatar
kambis
Posts: 36
Joined: 23 Jun 2014 08:06
Location: Germany
Contact:

HA module for EventLogging

Post by kambis »

Thank you pofs,
this leads me to think of making a userModule to realize event logging to a remote site, even if the desired monitoring event is an alarm. I've started to investigate a bit to write a module, were you can pass-over manually a path to the Z-Way object tree like 12:2:156:0 (Node:Instance:CommandClass:Scale) and the module creates out of that a virtual device to be able to bind itself to changes using the device.on(...) function for monitoring.

If there are pros & contras for making such a module, just drop here your suggestions.
Could be very helpful ...
pofs
Posts: 688
Joined: 25 Mar 2011 19:03

Re: SensorValueLogging with Fibaro FGFS-101

Post by pofs »

If you want to monitor arbitrary low-level values, I'd suggest you to use the following input values for your module:

1. Data subtree (DS) to monitor (like "devices[12].instances[0].commandClasses[32].data" or "devices[12].instances[0].commandClasses[48].data[1]" if your device has a scale). You need to only bind this one data holder, and it will receive notifications when any child is changed.

2. Value/path to get device identifier for the event. Might be specified manually (in case you know the device) or resolved from a data subtree (like srcNodeId and srcInstanceId in your example).

3. Path to get value from a data subtree. Mostly the same as previous one.

4. HTTP url to store value to.


This way, your settings for first one will be: And in case of basic set on controller: Technically it might be a JS function body resolved with DS as "this". In this case you don't need any checks whether it is constant or not:

Code: Select all

// config:
var subtree = "devices[12].instances[2].commandClasses[156].data[0]";
var devicePath = " '12:2:156:0' ";
var valuePath = " sensorState.value ";
var url = "http://someserver.org/script?device=${device}&value=${value}";
 
subtree = eval("zway." + subtree);
if (!subtree) {
    console.log("subtree not exitst");
    return;
}

subtree.bind(function(type, arg) {
    if (type != 0x81 /* Updated | ChildEvent */) return;
    
    // dataholder is in 'this'
    var device = arg.deviceFunc.call(this);
    var value = arg.valueFunc.call(this);

    // neither device nor value has changed
    // no need to log it
    if ((arg.oldValue !== null && value === arg.oldValue) && 
        (arg.oldDevice !== null && device === arg.oldDevice)) return;

    http.request({
        url: arg.url.replace("${device}", device).replace("${value}", value),
        method: "GET",
        async: true,
        success: function(r) {
            console.log("logged something");
        },
        error: function(r) {
            console.log("logging error");
        }
    });

    // save new old values
    arg.oldValue = value;
    arg.oldDevice = device;
}, {
    deviceFunc = new Function("with(this) { return " + devicePath + " }"),
    valueFunc = new Function("with(this) { return " + valuePath + " }"),
    url = url,
    oldDevice = null,
    oldValue = null
 }, true /* watch subtree */);
Of course it lacks a lot of checks for validity of input values, but I've only spent 10 minutes on it :)

EDIT: or maybe it's even better to use the same path syntax as in logs (devices.X.instances.Y.commandClasses.Z.data) and use evalPath() instead of eval(). It is not currently bundled with z-way, but it will be like this:

Code: Select all

function evalPath(s) {
    var parts = s.split('.'), obj = global;
    for (var k in parts) {
        if (!obj) break;
        if (parts[k] === "") continue;
        obj = obj[parts[k]];
    }
    return obj;
}
User avatar
kambis
Posts: 36
Joined: 23 Jun 2014 08:06
Location: Germany
Contact:

Re: SensorValueLogging with Fibaro FGFS-101

Post by kambis »

pofs, I have to study all these and try around. I'll share my results as soon I have something working.
Thank you for the input.
User avatar
kambis
Posts: 36
Joined: 23 Jun 2014 08:06
Location: Germany
Contact:

Re: SensorValueLogging with Fibaro FGFS-101

Post by kambis »

After studying all provided information in this post I was able to create my own automation userModule and solve my problem discussed in this post. More data is available in this post:
viewtopic.php?f=3424&t=20528
Post Reply