Need help with creating a Plugwise XML file

Plugwise Forum about Plugwise devices and the Source software.
Marek
Starting Member
Starting Member
Posts: 25
Joined: Tue Sep 08, 2009 10:11 am
Location: Netherlands
Contact:

Need help with creating a Plugwise XML file

Post by Marek »

Hello all,

Im a 4th year student of communication and multimedia design at the HAN (Hogeschool van Arnhem en Nijmegen)in the Netherland.
Currently Im doing my Internship at a company called Logica. I have a assignment to design, develop and make a prototype of an interface that will make users aware of their power usages. Through the use of an avatar or digital representation that communicates with the user in an active manner (Emotions like sad, happy, encouraging ect) the user will be more aware of his energy usage. This avatar will have an positive influence on the energy consumption.

To make this system work I decided to buy a Plugwise Home Start Pakket. I received it last weekend and now I am experimenting with the web server. My goal is to create an .XML file that I can call upon in a Adobe Flash file.

Currently I am using the Example XML file that came with the software to look at some data. The only data I really need is the current power usage and the total power usage. To get this i emitted the example xml file to this:

Code: Select all

<?xml version="1.0" encoding="iso-8859-1" standalone="yes"?>

<items type="array">

<% foreach Plugwise.Rooms %>	
	<%$room = .Name %>
	<% foreach .Appliances %>	
		<%
		  if (.Module == null)
		    continue;
      /if
		  if (.Room == null)
		    echo "No Room";
      /if
      $state=.StatusImageName.Replace("_locked","");
			$state=$state.SubString($state.LastIndexOf("_")+1);
		%>
	<appliance>
		<powerstate><%=.PowerState%></powerstate>
		<powerusage><%=Math.Round(.PowerUsage*100)%></powerusage>
		<totalusage><%=Math.Round(.TotalUsage*100)%></totalusage>
	</appliance>
	<% /foreach %>
<% /foreach %>
</items>

This is working great cause when i just called upon the example.xml file i got this:
<hr noshade size="1">

Code: Select all

<items type="array">
#8722;
<appliance>
<powerstate>on</powerstate>
<powerusage>8520</powerusage>
<totalusage>12</totalusage>
</appliance>
</items>
<hr noshade size="1">

exactly the information i needed... But here i also encountered my problem..

The data doesn't seem to be realtime (in the sense that i can 'pull' it on request.. The data seems to be pushed every 2 minutes or so..

So my question:

Would it be possible to refresh the data of the current power usages everytime i call upon the xml data? Cause i want it to be realtime within my flash animation.

If so, how would i do this?





I notices that when using the source software i can press the refresh button on the bottom to get the realtime data.. Would something like this be possible in the webserver?

I hope someone can help me out ;)
LostDreamer
Member
Member
Posts: 73
Joined: Fri Apr 10, 2009 1:43 pm
Location: Netherlands
Contact:

Need help with creating a Plugwise XML file

Post by LostDreamer »

Hi Marek,

You need to use the Module object for realtime stats instead of the Appliance object.
The only problem with that is: the page will wait untill it has communicated with the plug in question: If that plug is 100m furter (communicating via 7 other plugs) it might take a long time to load the page.


UNTESTED CODE:
Should work though

Code: Select all

<?xml version="1.0" encoding="iso-8859-1" standalone="yes"?>
<items type="array">
<% foreach Plugwise.Rooms %>	
	<%$room = .Name %>
	<% foreach .Appliances %>	
		<%
		if (.Module == null)
			continue;
		/if
		if (.Room == null)
			echo "No Room";
		/if
		
		$mod = .Module
		format 'float.total' as '{0:0.00}'
		format 'Module.PowerUsage' as '{0:0.00}'
		format 'Appliance.TotalUsage' as '{0:0.00}'
		%>
	<appliance>
		<powerstate><%= Module($mod).RelayState %></powerstate>
		<powerusage><%= Module($mod).PowerUsage %></powerusage>
		<totalusage><%= .TotalUsage %></totalusage>
	</appliance>
	<% /foreach %>
<% /foreach %>
</items>

Relaystate (open / close) and powerUsage are now allways current value.


Regards,
Lostdreamer
Marek
Starting Member
Starting Member
Posts: 25
Joined: Tue Sep 08, 2009 10:11 am
Location: Netherlands
Contact:

Need help with creating a Plugwise XML file

Post by Marek »

Thank you for the quick response !!

I've just tested the code and it seems to do exactly the same..
My output:

Code: Select all

<items type="array">
#8722;
<appliance>
<powerstate>closed</powerstate>
<powerusage>87,30</powerusage>
<totalusage>0,19</totalusage>
</appliance>
</items>
When i refresh the statistics.xml at http://localhost:8080/statistics.xml the power usages doesn't change.. Only every 2 mins or so..

I am using only 1 circle+ btw and its within 2meters of my computer..


What does the RelayState indicate? (open or closed. It seems to be closed with me)

I hope you can help me out :)

Thnx again for the quick response btw!
Bwired
Administrator
Administrator
Posts: 4704
Joined: Sat Mar 25, 2006 1:07 am
Location: Netherlands
Contact:

Need help with creating a Plugwise XML file

Post by Bwired »

Try to call the XML directly 2 times after each other, what happens then?

<hr noshade size="1"><font size="1">Pieter Knuvers
http://www.bwired.nl <i>Online House in the netherlands. Domotica, Home Automation.</i></font id="size1">
Marek
Starting Member
Starting Member
Posts: 25
Joined: Tue Sep 08, 2009 10:11 am
Location: Netherlands
Contact:

Need help with creating a Plugwise XML file

Post by Marek »

currently i am looking at the .xml file in firefox / internet explorer. and refreshing it since i dont have the flash actionscript code ready yet.

I dont think it really matters in which way i call upon the .xml file right?

So when i go to http://localhost:8080/statistics.xml in firefox/IE it shows the code i linked in the above post..
When i press refresh (2,3,4,5,6,7,8,9,10, ect times) nothing really happens.. Only once so often the value will change (seems like a fixed time but im not sure)
Bwired
Administrator
Administrator
Posts: 4704
Joined: Sat Mar 25, 2006 1:07 am
Location: Netherlands
Contact:

Need help with creating a Plugwise XML file

Post by Bwired »

You have to be sure the browser is really refreshing and not show the cache. Try open and close the browser with call!
Its a long time ago I made the webserver with Plugwise, but As I remember If you call the the webserver for a status with XML, the Plugwise source software gets the status of all the circles and updates the source grid. It will not give that information back in the XML, after a second request you get the newest data loaded in the grid upon first request.
I'm not sure this construction is still in the current webserver because there have bin some updates. Plugwise is on this forum also perhaps they can answer.

<hr noshade size="1"><font size="1">Pieter Knuvers
http://www.bwired.nl <i>Online House in the netherlands. Domotica, Home Automation.</i></font id="size1">
User avatar
Rene
Global Moderator
Global Moderator
Posts: 1689
Joined: Wed Oct 08, 2008 3:54 pm
Location: Netherlands

Need help with creating a Plugwise XML file

Post by Rene »

Are your sure you are not hitting the cache of your browser? Try appending a unique string (e.g. timestamp) to the URL, like http://localhost:8080/statistics.xml?ti ... 1130143100. When using the appliance method it is correct values get refreshed every 2 minutes because the Source polls each circle every 2 minutes and the appliance method returns just the last known status. However, as LostDreamer mentioned using the module method should initiate an explicit poll of the indicated circle.

RelayState indicates the state of the relay in the circle. Closed means powered (on), open means unpowered (off).

Rene.
Marek
Starting Member
Starting Member
Posts: 25
Joined: Tue Sep 08, 2009 10:11 am
Location: Netherlands
Contact:

Need help with creating a Plugwise XML file

Post by Marek »

At first i thought it was the caching of the browser but when i use a hard reflesh (ctrl + f5) or the timestamp the value still doesnt change.. that often..

eventough when i look at it in de source software and refresh it, it keeps changing..

I've got the feeling im just overlooking something here or something :(


So when i refresh it does nothing but when i do something else for a few mins and come back and press refresh the values change..

ps, im using the code that lostdreamer provided

Code: Select all

<?xml version="1.0" encoding="iso-8859-1" standalone="yes"?>
<items type="array">
<% foreach Plugwise.Rooms %>	
	<%$room = .Name %>
	<% foreach .Appliances %>	
		<%
		if (.Module == null)
			continue;
		/if
		if (.Room == null)
			echo "No Room";
		/if
		
		$mod = .Module
		format 'float.total' as '{0:0.00}'
		format 'Module.PowerUsage' as '{0:0.00}'
		format 'Appliance.TotalUsage' as '{0:0.00}'
		%>
	<appliance>
		<powerstate><%= Module($mod).RelayState %></powerstate>
		<powerusage><%= Module($mod).PowerUsage %></powerusage>
		<totalusage><%= .TotalUsage %></totalusage>
	</appliance>
	<% /foreach %>
<% /foreach %>
</items>
Bwired
Administrator
Administrator
Posts: 4704
Joined: Sat Mar 25, 2006 1:07 am
Location: Netherlands
Contact:

Need help with creating a Plugwise XML file

Post by Bwired »

did you close the browser and then start fresh again, then you see it will work.

<hr noshade size="1"><font size="1">Pieter Knuvers
http://www.bwired.nl <i>Online House in the netherlands. Domotica, Home Automation.</i></font id="size1">
Marek
Starting Member
Starting Member
Posts: 25
Joined: Tue Sep 08, 2009 10:11 am
Location: Netherlands
Contact:

Need help with creating a Plugwise XML file

Post by Marek »

I just did and it still doesn't seem to work.. At least not how i would like it to..

So i tried something different now:
When i press the refresh button in the source software and after that press the refresh button for the .xml file it does refresh..
But without pressing the refresh button in the source software it doesn't seem to do so..

<b><s>I'm making a movie to show you guys now</s></b>

Did i need to edit the code lostdreamer provided? do i need to tell it which circle+ to poll or doest it do that automatically cause i just copied his code directly

Video:
[youtube]0iRi97FEw7A[/youtube]

Video description:
first i show the plugwise usb stick and circle+ being connected to my wifi bunny (Nabaztag)

Next i show the code that lostdreamer provided pasted into statistics3.xml in my www folder

Then i show the webserver being on within the source software

Next i press the refresh button and the values change within the source software, i then press the refresh button in Firefox and the values the xml file is displaying change as well

I turn off the wifibunny by taking out the power cable

I refresh the browser (Firefox) a few times (normal refresh and hard refresh (ctrl + f5) but nothing changes
I copy the xml location and past it into a new Internet Explorer window, it displays the old value
I refresh a couple of times, but nothing happens

I go into the source software and refresh it

After that i go back to both of the browsers and press refresh and the values changes and get updates..

In summery, it seems that the code doesnt poll the circle+ for a update and doesnt request the new vallue.. Only pressing refresh in the source software will update the vallues for me..
Bwired
Administrator
Administrator
Posts: 4704
Joined: Sat Mar 25, 2006 1:07 am
Location: Netherlands
Contact:

Need help with creating a Plugwise XML file

Post by Bwired »

I tried it out and you are right, I think Plugwise took the polling mechanism out!
I'm sure it was in there in a earlier version, first call updated the grid and the second call gave the updated information.
Guess now you have to wait until the Plugwise source software updates the grid.
Rene and Reinder can you confirm this?

<hr noshade size="1"><font size="1">Pieter Knuvers
http://www.bwired.nl <i>Online House in the netherlands. Domotica, Home Automation.</i></font id="size1">
User avatar
Rene
Global Moderator
Global Moderator
Posts: 1689
Joined: Wed Oct 08, 2008 3:54 pm
Location: Netherlands

Need help with creating a Plugwise XML file

Post by Rene »

I am sure this is how it worked in the past. Using the module method polled the circles real time. I never used it because of the performance hit.

Rene.
Marek
Starting Member
Starting Member
Posts: 25
Joined: Tue Sep 08, 2009 10:11 am
Location: Netherlands
Contact:

Need help with creating a Plugwise XML file

Post by Marek »

Thanks for checking it.. Thought i was going crazy or doing something wrong haha..

I'm contacting Plugwise about this via mail but since they stated they won't give any support regarding webserver stuff i have little hope :(
Bwired
Administrator
Administrator
Posts: 4704
Joined: Sat Mar 25, 2006 1:07 am
Location: Netherlands
Contact:

Need help with creating a Plugwise XML file

Post by Bwired »

Reinder of Plugwise is on the forum so he will answer this topics when he comes online.

<hr noshade size="1"><font size="1">Pieter Knuvers
http://www.bwired.nl <i>Online House in the netherlands. Domotica, Home Automation.</i></font id="size1">
Marek
Starting Member
Starting Member
Posts: 25
Joined: Tue Sep 08, 2009 10:11 am
Location: Netherlands
Contact:

Need help with creating a Plugwise XML file

Post by Marek »

ok, ill be waiting patiently then :)
Post Reply

Return to “Plugwise Forum”