http xml/json feedback

879 views
Skip to first unread message

Guillaume Vigneron

unread,
Nov 23, 2013, 3:08:11 AM11/23/13
to comman...@googlegroups.com
Hi all,
I just received a z-wave Micasaverde Vera lite with a few light dimmers. I'm successful controlling these devices with ON/OFF buttons as well as sliders via http commands. As an example, here is the command I launch via a slider on device #3:
/data_request?id=lu_action&output_format=xml&DeviceNum=3&serviceId=urn:upnp-org:serviceId:Dimming1&action=SetLoadLevelTarget&newLoadlevelTarget=[sliderval]

I am now trying to get the feedback from my device. With the following command in my browser:
http://192.168.1.90:3480/data_request?id=lu_status2&DataVersion=1&output_format=xml&DeviceNum=3

which give me in return the following XML
<root LoadTime="1385141152" DataVersion="141597519" UserData_DataVersion="141152053" TimeStamp="1385193505" ZWaveStatus="1" LocalTime="2013-11-23 08:58:25 D">
<Device_Num_3 status="-1">
<states>
<state id="133" service="urn:upnp-org:serviceId:SwitchPower1" variable="Status" value="1"/>
<state id="134" service="urn:upnp-org:serviceId:Dimming1" variable="LoadLevelStatus" value="22"/>
<state id="135" service="urn:upnp-org:serviceId:Dimming1" variable="LoadLevelTarget" value="22"/>
<state id="136" service="urn:micasaverde-com:serviceId:EnergyMetering1" variable="Watts" value="26"/>
<state id="137" service="urn:micasaverde-com:serviceId:EnergyMetering1" variable="Log" value="26,26,26,1385191800,1"/>
<state id="138" service="urn:micasaverde-com:serviceId:ZWaveDevice1" variable="Neighbors" value="1,3,"/>
<state id="139" service="urn:micasaverde-com:serviceId:ZWaveDevice1" variable="LastRouteUpdate" value="1385177593"/>
</states>
<Jobs/>
<tooltip display="0"/>
</Device_Num_3>
</root>
I can also ask for a json return value, which looks like:
{ "Device_Num_3": { "states": [ { "id": 147, "service": "urn:upnp-org:serviceId:SwitchPower1", "variable": "Status", "value": "1" }, { "id": 148, "service": "urn:upnp-org:serviceId:Dimming1", "variable": "LoadLevelStatus", "value": "22" }, { "id": 149, "service": "urn:upnp-org:serviceId:Dimming1", "variable": "LoadLevelTarget", "value": "22" }, { "id": 150, "service": "urn:micasaverde-com:serviceId:EnergyMetering1", "variable": "Watts", "value": "26" }, { "id": 151, "service": "urn:micasaverde-com:serviceId:EnergyMetering1", "variable": "Log", "value": "26,26,26,1385191800,1" }, { "id": 152, "service": "urn:micasaverde-com:serviceId:ZWaveDevice1", "variable": "Neighbors", "value": "1,3," }, { "id": 153, "service": "urn:micasaverde-com:serviceId:ZWaveDevice1", "variable": "LastRouteUpdate", "value": "1385177593" } ], "Jobs": [ ], "tooltip": { "display": 0 }, "status": -1 }, "LoadTime": 1385141152, "DataVersion": 141597519, "UserData_DataVersion": 141152053, "TimeStamp": 1385193954, "ZWaveStatus": 1, "LocalTime": "2013-11-23 09:05:54 D" }

For instance, I am just interested by the value corresponding to  "LoadLevelStatus".

Is there a direct way, I mean, without javascript, to get this value back on my slider?

Thank you very much for your help again :)
Guillaume
Message has been deleted

Guillaume Vigneron

unread,
Nov 23, 2013, 4:02:58 AM11/23/13
to comman...@googlegroups.com
If this helps, I copy the JSON feedback below in an easier way to read:

{ "Device_Num_3": 
{ "states": 
[
 { "id": 133, "service": "urn:upnp-org:serviceId:SwitchPower1", "variable": "Status", "value": "1" }
 ,
 { "id": 134, "service": "urn:upnp-org:serviceId:Dimming1", "variable": "LoadLevelStatus", "value": "22" }
 ,
 { "id": 135, "service": "urn:upnp-org:serviceId:Dimming1", "variable": "LoadLevelTarget", "value": "22" }
 , 
 { "id": 136, "service": "urn:micasaverde-com:serviceId:EnergyMetering1", "variable": "Watts", "value": "26" }
 , 
 { "id": 137, "service": "urn:micasaverde-com:serviceId:EnergyMetering1", "variable": "Log", "value": "26,26,26,1385191800,1" }
 , 
 { "id": 138, "service": "urn:micasaverde-com:serviceId:ZWaveDevice1", "variable": "Neighbors", "value": "1,3," }
 , 
 { "id": 139, "service": "urn:micasaverde-com:serviceId:ZWaveDevice1", "variable": "LastRouteUpdate", "value": "1385177593" }

  ]
  , 

  
  "Jobs": [ ], 
  "tooltip": { "display": 0 }, 
  "status": -1 }, 
  "LoadTime": 1385141152, 
  "DataVersion": 141598008, 
  "UserData_DataVersion": 141152054, 
  "TimeStamp": 1385197018, 
  "ZWaveStatus": 1, 
  "LocalTime": "2013-11-23 09:56:58 D" }

Barry Gordon

unread,
Nov 23, 2013, 9:54:59 AM11/23/13
to comman...@googlegroups.com

I strongly suggest you "Bite the Bullet" and learn enough Javascript to allow you to do feedback processing.  This is especially true for complex returns such as you are showing.  On my web site (The-gordons.net) I have posted a weather module which gets back responses in the form of JSON strings.  The feedback is all done in JS. You could use it as an example on one way of doing it. The nice thing about the JSON return format and doing the processing in JS is that there is really no parsing.  A single JS command converts the JSON text string to a true Javascript Object. Once it is in object form, retrieval of individual values is trivial.  the only non-trivial aspect to your JSON string is the fact that there is an array of objects embedded in the returned object, so for that object  you will need a loop construct to handle each of the array members (objects). The weather module does that for the 10 day forecast.

--
You received this message because you are subscribed to the Google Groups "CommandFusion Software" group.
To unsubscribe from this group and stop receiving emails from it, send an email to commandfusio...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Guillaume Vigneron

unread,
Nov 23, 2013, 10:04:46 AM11/23/13
to comman...@googlegroups.com
As usual, thanks for replying Barry :)

I actually tried understanding your Weather GUI but... Then I gave another try with the "DynamicRoom" GUI which contain XML parsing.

It's a bit more understandable for me but I'm still stuck. I think if I could get this GUI working with my XML file I would then be able to make my joins correctly...let's see.

Can someone help me correcting my JS file which display the first level (in my case "device") but not the child level "state"?
Thanks by advance.
Guillaume
Test xml feedback.GUI.zip
xml_feedback_all.xml

Guillaume Vigneron

unread,
Nov 23, 2013, 12:00:21 PM11/23/13
to comman...@googlegroups.com
OK, one more step ahead: I could manage to get my values as a final result, when querying only one device (http://192.168.1.90:3480/data_request?id=lu_status2&DataVersion=1&output_format=xml&DeviceNum=3 as the XML url), and changing a part of the javascript as follow:

self.loadRooms = function () {
// Load the XML data from a URL
CF.request(self.url, function (status, headers, body) {
// Check that the URL request returned without error
if (status == 200) {
// Use the returned body and create an XML DOM object
var parser = new DOMParser();
var xmlDoc = parser.parseFromString(body, 'text/xml');
// Get the house name
self.houseName = xmlDoc.getElementsByTagName("root")[0].attributes["LocalTime"].value;
CF.setJoin("s109", self.houseName);
// Clear any existing rooms and levels before loading the new ones
self.levels = [];
var levelNodes = xmlDoc.getElementsByTagName("states");
for (var i = 0; i < levelNodes.length; i++) {
// Create the level object
var newLevel = new Level(levelNodes[i].childNodes[0].nodeValue, 'Getfeedback');
CF.log("Level: " + levelNodes[i].childNodes[0].nodeValue);
// Get the room nodes
for (var j = 0; j < levelNodes[i].childNodes.length; j++) {
if (levelNodes[i].childNodes[j].nodeName == "state") {
// Add the room to the level
newLevel.rooms.push(new Room(levelNodes[i].childNodes[j].attributes["variable"].value, levelNodes[i].childNodes[j].attributes["value"].value));
CF.log("Room: " + levelNodes[i].childNodes[j].attributes["value"].value);
}
}
self.levels.push(newLevel);
}
// Finished parsing the XML, now sort the levels and setup the list
self.levels.sort(self.sortLevels);
self.showLevelsList();
} else {
CF.log("XML Request Failed with status " + status);
}
});
};
return self;
};

So now I'm good to get the different values in a list. Next question for the experts: how do I extract only one value from my XML to attach it a join?

Thanks again 

Guillaume Vigneron

unread,
Nov 23, 2013, 12:52:21 PM11/23/13
to comman...@googlegroups.com
Barry,
I have been examining your Weather GUI (thanks for sharing!), but it's made of a lot of functions... it's really hard to try to understand on a complex example. :(

If someone has some spare time, is it possible to have a very short JS file with just the extraction of one value from my JSON feedback, with a serial join on this value and nothing else? Based on that, I should be able to move forward and maybe make it more complex afterwards.

Thanks by advance
Guillaume

Barry Gordon

unread,
Nov 23, 2013, 2:16:23 PM11/23/13
to comman...@googlegroups.com

That is why I recommended the JSON format.  It eliminates the XML parsing issue.

 

Search the web for XML2JSON; a function written by Thomas Frank.  That might help you

 

From: comman...@googlegroups.com [mailto:comman...@googlegroups.com] On Behalf Of Guillaume Vigneron
Sent: Saturday, November 23, 2013 12:00 PM
To: comman...@googlegroups.com
Subject: Re: http xml/json feedback

 

OK, one more step ahead: I could manage to get my values as a final result, when querying only one device (http://192.168.1.90:3480/data_request?id=lu_status2&DataVersion=1&output_format=xml&DeviceNum=3 as the XML url), and changing a part of the javascript as follow:

--

Guillaume Vigneron

unread,
Nov 23, 2013, 2:19:05 PM11/23/13
to comman...@googlegroups.com
Yes, I'm working now (from scratch) with the json feedback posted earlier and your Weather demo page as a based...but I hardly get it :/

Barry Gordon

unread,
Nov 23, 2013, 2:27:01 PM11/23/13
to comman...@googlegroups.com

Look at the function Process JSON in the weather module. It does all the work.  You might also want to go to wunderground.com to look at what they return so you have a better idea of what the JSON being returned looks like.  The JSON objects are very well documented.

 

In the weather module there are also debugging and diagnostic tool that I use to see what is going on.  Are you familiar with using chrome or safari to display data as the system is running.

 

If you are still having an issue let me know tomorrow and I will write something for you that should explain it all based upon what you are getting back.  I will annotate it heavily so you should be able to understand what I am doing.  You can easily reach me by eMail my name you know and my domain you know so my email address should be obvious.

 

To make things very easy for me, send me your complete project.  The best way to do that IMHO is sendspace.com which is a free system for sending large files. In that way I will start with what you have and integrate what you need,  I will not be able to test it since I do not have the equipment, but if the JSON you posted is correct I will dummy that in as the reply.

 

From: comman...@googlegroups.com [mailto:comman...@googlegroups.com] On Behalf Of Guillaume Vigneron
Sent: Saturday, November 23, 2013 12:52 PM
To: comman...@googlegroups.com
Subject: Re: http xml/json feedback

 

Barry,

--

Guillaume Vigneron

unread,
Nov 23, 2013, 2:30:16 PM11/23/13
to comman...@googlegroups.com
Thank you very much for your help and offer Barry.

I will keep digging (probably the whole night now!), as I like to understand what I'm doing. If I'm still blocked, I will probably have to accept your offer...

Talk to you very soon.
Guillaume

Guillaume Vigneron

unread,
Nov 23, 2013, 3:36:14 PM11/23/13
to comman...@googlegroups.com
So, I could get the json from wunderground.com, it's more clear now for me. Indeed, you are right, it seems pretty straight forward to obtain the different objects with JSON feedbacks.
 
 If I understand well, based on my json sample below, I could, for example, mark as objects directly something like "LocalTime" with the following command:
var time=obj.Device_Num_3.LocalTime;
and then serial-join the object "time" this way:
CF.setJoins([{join:"s100", value:time},
 
Am I right for now?


In my case, I just want to retrieve the value corresponding to LoadLevelStatus. But as you said, this data is in between [ ] and it's not so easy anymore.
 
I can see in your weather.js that you load this kind of information in a list (with the command below). I guess this is a first step, but how do you retrieve a particular objects contained in this list then?  :/
WT.listLoad(obj.forecast.txt_forecast.forecastday); 


Thanks again for your help and patience. :)



Here is my JSON sample:

{ "Device_Num_3": 
{ "states": 
[
 { "id": 126, "service": "urn:upnp-org:serviceId:SwitchPower1", "variable": "Status", "value": "0" },
 { "id": 127, "service": "urn:upnp-org:serviceId:Dimming1", "variable": "LoadLevelStatus", "value": "0" },
 { "id": 128, "service": "urn:upnp-org:serviceId:Dimming1", "variable": "LoadLevelTarget", "value": "0" }, 
 { "id": 129, "service": "urn:micasaverde-com:serviceId:EnergyMetering1", "variable": "Watts", "value": "0" }, 
 { "id": 130, "service": "urn:micasaverde-com:serviceId:EnergyMetering1", "variable": "Log", "value": "0,0,0,1385195400,1" }, 
 { "id": 131, "service": "urn:micasaverde-com:serviceId:ZWaveDevice1", "variable": "Neighbors", "value": "1,3," }, 
 { "id": 132, "service": "urn:micasaverde-com:serviceId:ZWaveDevice1", "variable": "LastRouteUpdate", "value": "1385177593" }

Barry Gordon

unread,
Nov 23, 2013, 5:15:02 PM11/23/13
to comman...@googlegroups.com

You are getting the idea.

 

The JSON in your case is unique. The first object is named Device_Num_3 and is complex containing an array of objects.

 

The objects in Device_Num_3 are

"states":   an array of objects

"Jobs":  an array which is empty

"tooltip":  a single object     and

"status:  an integer with the value of -1

 

There are then 6 objects each one being a simple name value pair; LoadTime, DateVersion, . . .

 

your var time statement is correct assuming that when you parsed the JSON string you set it into a var called obj.

The setJoin also looks correct

 

Now for the states array something like

 

for(var i=0;  i<obj.Device_Num_3.states.length;  i++)

          {  if(obj. Device_Num_3.states[i].variable== "LoadLevelStatus")

                 { // do whatever You need to do here such as:

                    CF.setJoins([join:"s100", value: obj. Device_Num_3.states[i].value])

                 };

          };

 

the above is similar to what happens in loadList where the action is to put the desired value into a list item since I want to show all the forecasts in a scrolling list

 

Hope that helps

 

As you gain understanding you will begin to appreciate how powerful using JS can be.

From: comman...@googlegroups.com [mailto:comman...@googlegroups.com] On Behalf Of Guillaume Vigneron
Sent: Saturday, November 23, 2013 3:36 PM
To: comman...@googlegroups.com
Subject: Re: http xml/json feedback

 

So, I could get the json from wunderground.com, it's more clear now for me. Indeed, you are right, it seems pretty straight forward to obtain the different objects with JSON feedbacks.

--

Barry Gordon

unread,
Nov 23, 2013, 5:17:16 PM11/23/13
to comman...@googlegroups.com

And to be more efficient in a code sense:

 

CF.setJoins([{join:"s100", value: obj.Device_Num_3.LocalTime },

 

I do it with the explicit var so I can display it during debugging to check I have it correct.

 

 

From: comman...@googlegroups.com [mailto:comman...@googlegroups.com] On Behalf Of Guillaume Vigneron
Sent: Saturday, November 23, 2013 3:36 PM
To: comman...@googlegroups.com
Subject: Re: http xml/json feedback

 

So, I could get the json from wunderground.com, it's more clear now for me. Indeed, you are right, it seems pretty straight forward to obtain the different objects with JSON feedbacks.

--

Guillaume Vigneron

unread,
Nov 24, 2013, 1:58:14 AM11/24/13
to comman...@googlegroups.com
Awesome!
Thank you very much for taking on your time to explain me javascript basics, I really appreciate that.

So now I'll try from a blank GUI to use this code and, as soon as I have a page containing a slider with command and feedback working, I'll share it. I know I'm not the only "JS newbie" who would like to control his z-wave lighting system with iViewer.

Thanks again Barry :)

Guillaume Vigneron

unread,
Nov 24, 2013, 4:21:22 AM11/24/13
to comman...@googlegroups.com
I was enthusiast this morning... until I found out I was not even able to call my json file by a simple CF.request function.
Can someone help me on the main steps? For now I just try to get that "LoadLevelStatus" value in a text box using a serial join.


So here is what I think I should do, please correct me:

1.) Via an http command I request the JSON data:
http://192.168.1.90:3480/data_request?id=lu_status2&DataVersion=1&DeviceNum=3

2.) I link my json object value with the serial join 100 with the following: 
for(var i=0;  i<obj.Device_Num_3.states.length;  i++)
          {  if(obj. Device_Num_3.states[i].variable== "LoadLevelStatus")
                 { // do whatever You need to do here such as:
                    CF.setJoins([join:"s100", value: obj. Device_Num_3.states[i].value])
                 };
          };

I certainly forgot something :( 

Questions:
-can someone help me writing a very simple cf.request? I just can find complex examples.
-how can I run this request? Can we do this automatically every x seconds so I always have the actual values?
-is the step #2 enough by himself or should I include it in a function?


I am lost again, thanks by advance for your help :(

Barry Gordon

unread,
Nov 24, 2013, 6:09:44 AM11/24/13
to comman...@googlegroups.com

Before you go crazy:

 

Do you understand how to use the Chrome (or Safari, I use Chrome) browser to debug the javascript code? As a minimum you should understand how to use the CF.log and CF.objectLog functions;  and how to set your iPad to use the debugger when load iViewer.  This is all covered in the CommandFusion documents on scripting and in their Wiki.

 

The Weather Demo module in my web site has CF.log statements in the code but they are all controlled by some debugging constants (e.g. trace, debug, etc.) for example

if(WT.trace) CF.log("Text_string_to_display_in_the_debugger");

 

With regard to doing the CF.request, the getWeather function in the weather demo system is where the correct URL for the weather system is built. Very similar code in your module would be necessary to dynamically build the URL you require.  If the URL is always the same, then you just need to do:

 

CF.request("Your_URL", your_feedback_Function_name);

 

I strongly suggest you get a wunderground api, place it in the appropriate spot in the weather demo and get weather demo to work with debugging turned on. (e.g. trace:  true, debug: true, etc.) . Play with it until you really understand how it works. It is not at all complex. Do not worry about anything in the JS weather module that are internal functions.

 

Also find and use a Javascript editor that does syntax checking. I use cPoint's Antechinus editor. It is not free, but is relatively in expensive.

 

Lastly, The Javascript coding style I use makes every module except one  a large object with a simple name (in the weather demo the name is WT). One module is coded straight and generally has functions used by all the modules in a project (e.g the Common_Subroutines.js module). This allows me to use the same function names, e.g. setup, initialize, etc. in every module in the project. when referenced, these functions are referenced as object_name.function_name() e.g. WT.initialize().  This style is also covered in the CommandFusion scripting documents.

 

PS I have revised the weather demo program on my site taking out some extraneous stuff.

 

Hope That helps

 

From: comman...@googlegroups.com [mailto:comman...@googlegroups.com] On Behalf Of Guillaume Vigneron
Sent: Sunday, November 24, 2013 4:21 AM
To: comman...@googlegroups.com
Subject: Re: http xml/json feedback

 

I was enthusiast this morning... until I found out I was not even able to call my json file by a simple CF.request function.

--

Jarrod Bell

unread,
Nov 24, 2013, 6:12:00 AM11/24/13
to comman...@googlegroups.com
Cooked up a little example script for you. Note that this is entirely untested other than a quick run through JSLint.com
https://gist.github.com/jarrodbell/7625906

Example usage:
requestData("3");


Regards,

Jarrod Bell
CommandFusion
www.commandfusion.com


Guillaume Vigneron

unread,
Nov 24, 2013, 9:30:31 AM11/24/13
to comman...@googlegroups.com, jar...@commandfusion.com
Wahoo...you guys just come on time when I was about to give up! That's really nice, thanks.

Jarrod:
Big big thanks for you file, it's not only code you wrote for me, it's also full of comments, well explained, great! That definitely help me understanding the different steps involved.
Unfortunately it doesn't work straight forward, I have an error "SCRIPT: Exception: ReferenceError: Can't find variable: device" when sending the command "requestData("3");" via a simple button on the GUI. I've been on it for an hour now, I hope I can solve this :) If you want to give a try, my z-wave gateway is accessible from outside on a public IP, just let me know and I send you the address. ;)

Barry:
I appreciate a lot that you keep pushing me in the right direction. Yes, I run iViewer in debug mode, with a view on the log on my browser (Safari).
Until now I have just tried to understand the relation between your script and the json feedback from wunderground.com. I will follow your advise and run the weather GUI from my ipad and follow the events via the debug mode. (I already get the wunderground.com key as I already generated their JSON feedback).
Regarding the javascript editor, I just use "Sublime Text" which is more like an advanced text editor, I will search for a more Javascript dedicated one.

To both of you, thanks thanks thanks again! I hope this thread will also be helpful in the future for others who would like to integrate similar z-wave systems.

Barry Gordon

unread,
Nov 24, 2013, 10:18:44 AM11/24/13
to comman...@googlegroups.com

I believe the error is in the function getDeviceVariable.  There is a reference to JSON[device] but device has not been defined.

 

In the function getVariable, there is a similar usage but device is defined in the outer for statement

 

I believe the correction is to change JSON[device] to JSON[deviceName] in the two occurrences in getDeviceVariable

 

 

From: comman...@googlegroups.com [mailto:comman...@googlegroups.com] On Behalf Of Guillaume Vigneron
Sent: Sunday, November 24, 2013 9:31 AM
To: comman...@googlegroups.com
Cc: jar...@commandfusion.com
Subject: Re: http xml/json feedback

 

Wahoo...you guys just come on time when I was about to give up! That's really nice, thanks.

--

Guillaume Vigneron

unread,
Nov 24, 2013, 11:03:15 AM11/24/13
to comman...@googlegroups.com
Good catch Barry!

Attached is my GUI test, works perfectly! By the way, I'm still trying to get how each function works, which is becoming more and more easy with all these examples I have now :)

Next step is to get the slider position directly on the value received when opening the page (yeah, javascript again...but I also have some examples!) as well as a button ON/OFF with synchronised status.

To be continued...

light_json_feedback.gui.zip

Barry Gordon

unread,
Nov 24, 2013, 12:10:06 PM11/24/13
to comman...@googlegroups.com

You should start to think about how to organize your JS modules.  I use one of the Standard Javascript patterns.  A JS pattern is just a way of coding the module.  All my projects follow the same general style. The differences are mainly in when I developed them.  I organize a project in a master project folder so it has three main parts:

1- the gui file

2- a resource folder which holds all of the projects resources (Graphics generally). Often the resource folder has sub folders.

3- a Javascript folder that contains all of the Javascript files (modules)

 

For non-demo projects

There is a javascript module called Main which has various common functions, including the CF.userMain function.

There is a Common_subroutines module which holds the obvious

All other modules are coded as objects containing a master object in which are function, and data unique to that module

 

For demo projects I sometimes  combine Main,  and Common_Subroutines into the  demo javascript module

 

For example of a slider look at the Serial and IR demo on my web site. It is a much "richer" project that does IR and serial (RS232) communications using an iTach as the converter from IP. The anthem module which handles the Anthem AVP over a serial port has a slider implemented for volume control as an example.

 

From: comman...@googlegroups.com [mailto:comman...@googlegroups.com] On Behalf Of Guillaume Vigneron
Sent: Sunday, November 24, 2013 11:03 AM
To: comman...@googlegroups.com
Subject: Re: http xml/json feedback

 

Good catch Barry!

--

Barry Gordon

unread,
Nov 24, 2013, 12:13:54 PM11/24/13
to comman...@googlegroups.com

Feel free to ask questions here or using my email address (preferred) regarding how any of the functions I write works. 

 

Do you have a good Javascript reference?  I use Javascript: The Definitive Guide by David Flanagan; publisher O'Reilly

 

From: comman...@googlegroups.com [mailto:comman...@googlegroups.com] On Behalf Of Guillaume Vigneron


Sent: Sunday, November 24, 2013 11:03 AM
To: comman...@googlegroups.com

Subject: Re: http xml/json feedback

 

Good catch Barry!

--

Guillaume Vigneron

unread,
Nov 24, 2013, 12:21:51 PM11/24/13
to comman...@googlegroups.com
By reading your message I realised my last post didn't reach the group... so I will join again my GUI with the slider position and value automatically updated every 2seconds :)

That's all good for one light (device), now I have to find out how I can manage the feedback for 2 lights. For the 2seconds auto-update I just call my function again and again via the page timer function, but I can only do that for one device with this code, otherwise my ipad will get confused :) If you have any idea on how I should proceed...

Otherwise I haven't think about my js files structure yet, just trying to get things working for now and I still have a lot to learn! I will look at your javascript reference book, I don't have any. CommandFusion is just a hobby for me but it's getting more and more interesting! :)
z-wave_light_json_feedback_v2.gui.zip

Guillaume Vigneron

unread,
Nov 24, 2013, 12:44:37 PM11/24/13
to comman...@googlegroups.com
What about something like:
if myJSON["Device_Num_"+deviceNum] == myJSON["Device_Num_4"]
return CF.setJoin("s104", myJSON["Device_Num_4"].states[1].value);

I don't think the syntax would work, but maybe I could use this sort of condition... ?

Guillaume Vigneron

unread,
Nov 24, 2013, 12:47:19 PM11/24/13
to comman...@googlegroups.com
Of course in this case I would have to run the whole function once per light and apply the condition for each join...not really elegant. (anyone is following me? :D )

The right solution is probably to modify the whole script so I get the JSON feedback not only for one light but for all the devices and then get the right data out of it, looks like an interesting challenge :)

Guillaume Vigneron

unread,
Nov 24, 2013, 3:11:30 PM11/24/13
to comman...@googlegroups.com
All right! :)

Just did a new version with the following functionalities:
-dimmer value for light 1
-slider auto-updated for light 1 (feedback)
-unique button ON/OFF on light 2
-feedback on button light 2 auto-updated (button status change if light is controlled by another device)
-dimmer value for light 2

I reduce a lot the initial script sent by Jarrod. The reason is that two functions aren't used anymore. Now the feedback that I call contains data for all the devices (see URL). By the way, my code is not flexible anymore, I have to define the devices and states "position" manually (i.e. devices[1].states[1]). See below, the integrality of my javascript file:

var myJSON, baseURL = "http://192.168.1.90:3480/data_request?id=lu_status2&DataVersion=1";
 
function requestData(deviceNum) {
  CF.request(baseURL, function(status, headers, body) {
    if (status == 200) {
      
      // OK response received, now grab the JSON string from body and turn it into an object
      myJSON = JSON.parse(body);
      
      // Now assign one of the known state variables to a serial join (if it will always be at a certain index in the state & device array)
      CF.setJoin("s100", myJSON.devices[1].states[1].value);
      // Now assign one of the known state variables to a serial join (if it will always be at a certain index in the state & device array)
      CF.setJoin("s104", myJSON.devices[2].states[1].value);
      // Analog Join for slider position when another user change the light dimmer. (if it will always be at a certain index in the state & device array)
      CF.setJoin("a1000", (myJSON.devices[1].states[1].value)*655.35);
      // Analog Join for slider position when another user change the light dimmer. (if it will always be at a certain index in the state & device array)
      CF.setJoin("d10", myJSON.devices[2].states[0].value);


    }
  });
}


I would like to say a big big big thank you -again- to Jarrod and Barry who both spent a lot of time helping me during the week-end. Congratulations to you both :) 
light_json_feedback.gui_V3.zip

Guillaume Vigneron

unread,
Nov 24, 2013, 3:14:17 PM11/24/13
to comman...@googlegroups.com
Screenshots =>

IMG_0064.PNG
IMG_0063.PNG

Jarrod Bell

unread,
Nov 24, 2013, 5:10:11 PM11/24/13
to comman...@googlegroups.com
Thanks for pointing that out Barry, fixed the gist to reflect the correct variable names.


Regards,

Jarrod Bell
CommandFusion
www.commandfusion.com


Barry Gordon

unread,
Nov 24, 2013, 6:10:40 PM11/24/13
to comman...@googlegroups.com
A usual you are welcome. You have done the same for me in the past.

Sent from my iPad

Eric Wiersma

unread,
Dec 23, 2013, 12:44:18 PM12/23/13
to comman...@googlegroups.com
Guilaume,
Thanks for figuring out how to get feedback from VERA.
I took your file and got it working with my devices.
The problem is that I do not know how to get it in my own GUI.
If i coppy all the buttons and the feedback request, only the commands work.
I put your script by my files and pointed the scriptmanager to it but i do not get any feedback.

Any tips how to converge two GUI''s??

Thanks
Eric Wiersma

Iviewer V4.0.288 build 288

Op maandag 25 november 2013 00:10:40 UTC+1 schreef barrygordon:

**********************************************************************
For information, services and offers, please visit our web site: http://www.klm.com.
This e-mail and any attachment may contain confidential and privileged material intended for the addressee only.
If you are not the addressee, you are notified that no part of the e-mail or any attachment may be disclosed, copied or distributed,
and that any other action related to this e-mail or attachment is strictly prohibited, and may be unlawful.
If you have received this e-mail by error, please notify the sender immediately by return e-mail, and delete this message.

Koninklijke Luchtvaart Maatschappij NV (KLM), its subsidiaries and/or its employees shall not be liable for the incorrect or
incomplete transmission of this e-mail or any attachments, nor responsible for any delay in receipt.
Koninklijke Luchtvaart Maatschappij N.V. (also known as KLM Royal Dutch Airlines) is registered in Amstelveen, The Netherlands, 
with registered number 33014286
**********************************************************************
light_json_feedback.gui.zip

Guillaume Vigneron

unread,
Dec 23, 2013, 1:00:44 PM12/23/13
to comman...@googlegroups.com
Hi Eric,
I'm glad this example can help someone :)

I have actually improved that code since then. Be careful, this example just get feedback of devices that had a recent change, you better work on the whole feedback by replacing the URL request with: http://IP_VERA_LITE:3480/data_request?id=lu_status2
and adapt parsing (myJSON.devices[X].states[X].value) to match with your devices.

You can also query just one specific device feedback with the URLs:
=> http://IP_VERA_LITE:3480/data_request?id=variableget&DeviceNum=XX&serviceId=urn:upnp-org:serviceId:Dimming1&Variable=LoadLevelStatus
(to get the dimming level, 0 to 100)
=> http://IP_VERA_LITE:3480/data_request?id=variableget&DeviceNum=XX&serviceId=urn:upnp-org:serviceId:SwitchPower1&Variable=Status
(to get the status, 1 or 0)


If I had to integrate the code, I would probably just copy it and paste it into my actual JS file if any (be careful not to have double variable/function names as well as pointing to joins that are already in use for something else in your project).

By the way, I'm not the right person to give advise on best practices and you better wait to get a reply from someone with more experience. :)

Regards,
Guillaume

Eric Wiersma

unread,
Dec 23, 2013, 1:18:45 PM12/23/13
to comman...@googlegroups.com
Hi Guillaume,
thnks for the reply.
I have no knowledge of Java or such but just by trying to figure the good stuff you guys come up with brings me further step by step.
I will try your suggestion.
Do I need a new script or is your old one oke?

Eric

Op maandag 23 december 2013 19:00:44 UTC+1 schreef Guillaume Vigneron:

Guillaume Vigneron

unread,
Dec 23, 2013, 1:33:37 PM12/23/13
to comman...@googlegroups.com
OK, I understand, I had no knowledge of javascript 2months ago :)

Do you understand what is done in this very small example? If you enter the following URL in your browser: http://IP_VERA_LITE:3480/data_request?id=lu_status2&output_format=xml , you can see what kind of feedback iViewer receive (&output_format=xml is to transform the answer into XML format, much easier to read by human eyes than JSON).

In the code you are using, you can see that we join the different value received to serial, digital and analog joins. For example, "myJSON.devices[1].states[1].value" is the value of the second state of the second device (json indexes are 0, so devices[1] is the second, the first would be devices[0]). If you look at the feedback in your browser, I'm sure you will understand, otherwise let me know.

Guillaume Vigneron

unread,
Dec 23, 2013, 1:35:04 PM12/23/13
to comman...@googlegroups.com
And yes, you can just keep the javascript file as it is if you don't have any other code to use in your project. Don't forget the page timer that query the Vera Lite for feedback every 2seconds.

Eric Wiersma

unread,
Dec 23, 2013, 4:44:37 PM12/23/13
to comman...@googlegroups.com
I figured that out by trial and error but got it working.
The problem is now that I have one GUI with all my stuff and one working GUI with VERA feedback.
But as soon as I try to combine them I can only send commands to VERA and it seems it is not running the feedback script I got from you.

Eric
--

Eric Wiersma

unread,
Dec 23, 2013, 4:46:04 PM12/23/13
to comman...@googlegroups.com
Forgot to ask, how does this timer work.

Guillaume Vigneron

unread,
Dec 24, 2013, 2:11:51 AM12/24/13
to comman...@googlegroups.com
The feedback is is only triggered by the page timer. So, on all the pages that will display z-wave feedback in your project you need to set up this timer.
Just reproduce the page timer you can see on my project and it should work.

Eric Wiersma

unread,
Dec 25, 2013, 8:09:29 AM12/25/13
to comman...@googlegroups.com
Another step forward (and another backward :-)
it was the timer to get the script starting and give me feedback.
It was working oke for a while but I lost some feedback again after including some more z-wave devices.
At least I know where to look now.

Thanks,

Happy Holiday's

Eric

Op dinsdag 24 december 2013 08:11:51 UTC+1 schreef Guillaume Vigneron:
The feedback is is only triggered by the page timer. So, on all the pages that will display z-wave feedback in your project you need to set up this timer.
Just reproduce the page timer you can see on my project and it should work.

Guillaume Vigneron

unread,
Dec 25, 2013, 8:27:27 AM12/25/13
to comman...@googlegroups.com
Great!
Yes, this script is very, very basic and not flexible. If you add new z-wave devices, the feedback returned by the Vera will be changed and you will have to change your code (myJSON.devices[X].states[X].value). It should be fairly easy now that you understood it.

Merry Christmas!

ian

unread,
Mar 25, 2014, 4:56:54 AM3/25/14
to comman...@googlegroups.com
HI Guillaume!

Thanks for doing this. I have been trying to do this of a long time now without any success! Now i am trying to find out how i will start to understand javascript without any programing skills?
But it is hard. I have downloaded your file version-3 to take a look at and see if i understand whats going on? 
Is the file version-3 in this thread the last and working one?
Can you point me in the right direction on where to start reading to understand Javascript?
I don´t understand  myJSON.devices[1].states[1]. If i get the feedback from my vera and i have 50 devices, almost all is dimmers, it is a lot of scripts in the xml file that i got back and it is hard to read. What is myJSON.devices[  1?  ]

Hope you could help me because i want to use command fusion again and not Irule software with it´s pre-made non customized modules or vera.

Thanks again 

Christian

Barry Gordon

unread,
Mar 25, 2014, 10:52:34 AM3/25/14
to comman...@googlegroups.com

To learn Javascript there are many tutorials and step by step lessons on the WWW.  A quick search with Google or Yahoo  for Javascript tutorials should provide you what you need.

 

An excellent reference book, not a tutorial, is "Javascript, The Definitive Guide" by Flanagan.  As a reference it does not teach Javascript but provides a place to look things up.

 

From: comman...@googlegroups.com [mailto:comman...@googlegroups.com] On Behalf Of ian
Sent: Tuesday, March 25, 2014 4:57 AM
To: comman...@googlegroups.com
Subject: Re: http xml/json feedback

 

HI Guillaume!

--

You received this message because you are subscribed to the Google Groups "CommandFusion Software" group.
To unsubscribe from this group and stop receiving emails from it, send an email to commandfusio...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

ian

unread,
Mar 26, 2014, 5:13:08 PM3/26/14
to comman...@googlegroups.com
Hi Barry. Thanks. 
I manage to connect and change my lights with feedback with this script but i found a big problem and it´s the device id that is changing row in the xml feedback from vera.
myJSON.devices[1] index that this is my second device but when i after 3 hours turning on some lights that not been on  during the day ,the feedback will return some changes and now myJSON.devices[1] will have a different number. It is now myJSON.devices[2]. Has any got this working?

Barry Gordon

unread,
Mar 26, 2014, 10:44:55 PM3/26/14
to comman...@googlegroups.com
I am not familiar with the VERA protocol, but what you are describing does sound strange. Perhaps the protocol packs a feedback as a payload into an element of a JSON array and it does not matter which ELEMENT of the JSON array it places it in. If that is the case just use the value of the device identifier to identify the device and not its position in the JSON array. If  you point me to the protocol document, I will take a look at it.

Sent from my iPad

Guillaume Vigneron

unread,
Mar 27, 2014, 2:17:18 AM3/27/14
to comman...@googlegroups.com
Hi Christian,
Sorry for not replying earlier, I was out traveling... I'll get back to you today with some explanations. ;)

Regarding the device number that change, it's because the request URL query only devices that had a status changed recently. I did'nt know that when I first created this code, I have changed the URL since that. I'll give you the proper URL later today.

Regards,
Guillaume

ian

unread,
Mar 27, 2014, 8:20:15 AM3/27/14
to comman...@googlegroups.com
Thank Guillaume! And thanks Barry. Maybe all will clear with this code and some javascript when i got your last code and maybe some explanations. 
Talk soon!

best regards Christian

Guillaume Vigneron

unread,
Mar 30, 2014, 2:30:27 PM3/30/14
to comman...@googlegroups.com
Hi Christian,
First of all, sorry for the late answer...

I've just looked into my code, and here is the address you should query: http://IP_VERA:3480/data_request?id=lu_status2

This will return the status (value...etc) for every device on the Z-Wave network, whatever if they had activity recently or not. I'm not sure if there is anything else you are missing, but please give a try with this address and come back to me if any question.
I'll try to answer quicker next time, I promise :)

Regards,
Guillaume

ian

unread,
Mar 31, 2014, 2:57:13 AM3/31/14
to comman...@googlegroups.com

Hi Guillaume.

Thanks for your answer!  Hi have some questions.:)

How do i easy read the value i want from the url. I have a lot of devices and it is not nicely shown were there device id is. Do you use any program to easy better look at it. I have tried the web browser 
Chrome
Safari
Firefox.

The status value is something i trying to understand what is for. Allmost all devices is value -1 but in your code you put the value 1 Is it the on and off value? 1 or 0? Or is it the job value 1-4?

And the last question.

Do have done a thermostat that display the temp and have buttons that increment or decrement the value ( set point ) I want to make a thermostat with feedback and this is the last thing to complete for the thermostat. The hardest thing i think will be the buttons to increment and decrement the temp value.
Do you think this is done with some global tokens.?  

Again. Thank you for making this code.

Best Regards Christian

ian

unread,
Apr 1, 2014, 10:24:55 AM4/1/14
to comman...@googlegroups.com
Hi Guillaume! 

I got it working!:) Now i can display dim %/ state of buttons and sliders. But and want to display the temp from a sensor?
Do you have a example how to do that? Maybe some increment and decrement buttons for the temp?

Also, is it possible to use a Regex instead of Javascript? I am a slow learner but when you got something working with Cf with feedback you want to do more:) Javascript is like a drug!:) Can´t stop trying to understand Javascript. 

I hope when the Cf module is ready they will be a Vera module :) Then we can control a lot of other things like Philips Hue as i also have.


Best Regards Christian

Guillaume Vigneron

unread,
Apr 16, 2014, 5:20:32 AM4/16/14
to comman...@googlegroups.com
Hi Christian,
I have never tried that as my heating system is not integrated with the Vera. By the way I'm soon moving to a new house and ZWave thermostats are planned, so I'll hopefully soon post an example here ;)

Otherwise, I am not familiar at all with the build-in Regex system, I'm using Javascript in iViewer from the early beginning, sorry.

Talk to you soon on this post!

Thiago Paz

unread,
Dec 1, 2014, 7:34:33 AM12/1/14
to comman...@googlegroups.com
Hi Guillaume,

I've seen your feedback design with VeraLite, and really liked it.
I managed to get the feedback of an ON / OFF module, but when I add another module in the javascript does not work.
How can I do this?

Thanks for your help,

Thiago Paz
light_json_feedback.gui.rar

Bob Green

unread,
Dec 2, 2017, 9:08:15 AM12/2/17
to CommandFusion Software
Hi Thiago - I know this is  an old thread, but I'm trying to implement your Vera feedback and have a couple questions:

1) Were you able to get this working with other modules?  If so, how.

2) Can you please explain what the -- if (status == 200) segment means?

Thanks.
Bob Green

Barry Gordon

unread,
Dec 2, 2017, 9:35:06 AM12/2/17
to comman...@googlegroups.com

Having not seen the JS code, the status==200 is normally a check on the status returned by a CF.request.  The CF.request will do an http request to a server. the returned status argument is the status returned by the server.  There are many different status values. 200 is "okay".  The following link shows all the http status values returned:

https://developer.mozilla.org/en-US/docs/Web/HTTP/Status

 

From: comman...@googlegroups.com [mailto:comman...@googlegroups.com] On Behalf Of Bob Green
Sent: Saturday, December 02, 2017 9:08 AM
To: CommandFusion Software
Subject: Re: http xml/json feedback

 

Hi Thiago - I know this is  an old thread, but I'm trying to implement your Vera feedback and have a couple questions:

--

Bob Green

unread,
Dec 2, 2017, 10:41:42 AM12/2/17
to CommandFusion Software
Thanks Gordon....I'll have the look at the link.  Always something to learn!!!!  

Bob
Reply all
Reply to author
Forward
0 new messages