Page 1 of 2

TSU9600 Tips & Tricks

Posted: Sun Dec 30, 2007 12:24 am
by Digit
Today was Pronto-day. Learned a lot, and some of those things can be useful, so i thought let's make a topic of this.

First of all, i just *had* to get rid of those scripts full of indexOf(), substrings etc. just to parse data coming from my HA app.
So i thought i'd give XML a try. This is so easy...

First i configured my HA app, which has a built-in HTTP-server, to supply the Pronto with XML. Prontoscript does the rest...
Here's a sample of XML i use (without the HTTP headers):

Code: Select all

<body>
  <content>
    <item>
      <ID>K01</ID>
      <Value>0</Value>
    </item>
    <item>
      <ID>K02</ID>
      <Value>0</Value>
    </item>
    <item>
      <ID>K03</ID>
      <Value>0</Value>
    </item>
    <item>
      <ID>K04</ID>
      <Value>0</Value>
    </item>
  </content>
</body>
Now, before you can parse the response (=HTTP headers + XML) in the Pronto you have to do this:

Code: Select all

// get rid of HTTP headers.
result = result.substring(result.indexOf("<body>"));
// create an XML object.
var xx = new XML(result);
With these 2 lines, you can directly address the data you need:
xx.content.item[0].ID.text() will result in 'K01'
xx.content.item[2].ID.text() will result in 'K03'
xx.content.item[0].Value.text() will result in '0'

In my case, i use this to retrieve the status of the lights in the livingroom. Depending on their status, different icons are shown on the Pronto.
It goes something like this:

Code: Select all

// get the ID.
var s = xx.content.item[i].ID.text();

// get the button.
var w = widget(s.toString());

// determine the status: ON or OFF.
status = xx.content.item[i].Value.indexOf("1") < 0 ?"OFF":"ON";

// set the button label
w.label = status;

// get the right image depending on the status.
var v = CF.widget("LED_"+status, "RESOURCES");

// if found, transfer image to the button.
if(v) 
{
  w.setImage( v.getImage() );
} 
So, with only a very small amount of code i can have the pages on my Pronto display whatever can be retrieved from my HA app: light status, temperatures, you name it... ain't that nice?[8D][8D]

TSU9600 Tips & Tricks

Posted: Sun Dec 30, 2007 12:29 am
by Snelvuur
Someone has been busy ;) i do agree, if you know enough you can make anything you want. Barry on remotecentral pointed me to a book, but it does not sell in netherlands afaik. Still.. i need to do some exams for something else first (work related) which is pretty dull. I should put these examples on the wiki perhaps. To learn as examples, since i think there are not enough. Is that an idea?

// Erik (binkey.nl)

TSU9600 Tips & Tricks

Posted: Sun Dec 30, 2007 12:39 am
by Digit
Erik,

Good idea, that will make life a bit easier, forum search is not that handy...

Robert.

PS.
What book are you referring to? About Javascript? Flanagan? I mostly use http://developer.mozilla.org/en/docs/Co ... _1.5_Guide for that.
Saves you the money for a book...and till now, this guide was helpful enough.

TSU9600 Tips & Tricks

Posted: Sun Dec 30, 2007 1:14 am
by Bwired
Hi Robert,
Looks very nice, couple of questions.
What if the pronto is not on? or is it always in standbye and can therefor receive your xml's
If it was not ON then you have to pull the current status?
How is it handled by the Pronto, fast without noticing, has the status screen to be on top or is it still being upgraded even when your doing other things with the pronto.

You can see that I Still did not receive my Pronto, hopefully Monday
Thanks.Pieter

BTW created a new forum for the Pronto TSU9600

TSU9600 Tips & Tricks

Posted: Sun Dec 30, 2007 1:33 am
by Digit
The Pronto is always on, but you can set a wireless timeout ranging from 15 min. to 24 hours. But it's not a question of receiving xml's, it's about requesting xml: the Pronto does the request (it's just a HTTP GET), my HA app sends the response.

Image

Here you see that every page on the Pronto can have it's own script, executed periodically or only once when a page is shown.

When a page is not active on the Pronto, the associated script will not run and hence status information will not be retrieved. But it doesn't have to be, cause the page is not shown...

In my case, when i enter the page with the 4 buttons for the lighting in the livingroom, the status on the page is retrieved and the page is updated within .5 seconds. For now i let the "status update"-script run every 10 seconds.

TSU9600 Tips & Tricks

Posted: Sun Dec 30, 2007 1:41 am
by Bwired
OK got it. I think we will make some great scripts :-)

TSU9600 Tips & Tricks

Posted: Sun Dec 30, 2007 2:01 am
by Digit
Great scripts.. yeah..

I'm already thinking about designing completely dynamically built pages.
I mean, whenever i add another light switch somewhere, i want everything to be adjusted as dynamically as possible. Define the new switch in your HA app and the rest follows without any work to be done. The website is built that way, so the same goes for the Pronto.

Image

For example, the labels above like 'Dressoir' and 'Laptop' are static right now; the number of buttons is also static. This is all design-time work. That shouldn't have to be like that. And it will not be! [8D]

TSU9600 Tips & Tricks

Posted: Sun Dec 30, 2007 2:11 am
by Bwired
Agree make it generic, make a property in your HA system if the device should be Pronto enabled and with a Generic script it will be adjusted on the fly. If this is possible the scripting is strong enough.

TSU9600 Tips & Tricks

Posted: Sun Dec 30, 2007 12:21 pm
by Snelvuur
@Digit: looks nice, this was also something i found to be usefull. My only issue is with using the extender i have to push a button first.. then it will react to me. As if its on standby. First click it on or something, and then it works. Seems to be only when using the extender.

// Erik (binkey.nl)

TSU9600 Tips & Tricks

Posted: Mon Dec 31, 2007 12:49 pm
by TANE
Robert,
Design you have made looks great..:)

TSU9600 Tips & Tricks

Posted: Mon Dec 31, 2007 8:36 pm
by Digit
I didn't want an ON and OFF button just to switch 1 device, and got my idea from a Instrumentation toolkit from IOComp i worked with before; they have nice-looking controls. Screencapture and PSP do the rest ;-)

TSU9600 Tips & Tricks

Posted: Tue Jan 01, 2008 2:17 pm
by TANE
Can you build something with the device name also in the button?

TSU9600 Tips & Tricks

Posted: Tue Jan 01, 2008 4:26 pm
by Digit
The "ON" and "OFF" is done by setting the label of the button, the green is done by using different bitmaps. So the answer is yes, you can put any text you like in the button, as long as it fits. Just walk through the code and you can see how it's done. Even 2 lines (device name and status) should be possible by adding CR+LF in the label.

TSU9600 Tips & Tricks

Posted: Tue Jan 01, 2008 11:19 pm
by TANE
Robert,
can you please send me the xcf file?

TSU9600 Tips & Tricks

Posted: Wed Jan 02, 2008 12:19 am
by Snelvuur
send me one too then ;-)

// Erik (binkey.nl)