Page 1 of 1

XML as input information for Domoticz-readout & -switching

Posted: Monday 24 February 2014 16:27
by Toulon7559
The PVLogger of my solar system has xml-output at a specific IP-address at my LAN.
Calling that IP-address with Firefox (or any browser) with command status.xml, I get as output a string of characters.
In Firefox the page-source for the latest XML-readout converts to the following example response:
<response>
<gauge_power>358</gauge_power>
<gauge_temp>0.0</gauge_temp>
<gauge_vpv>94.5</gauge_vpv>
<gauge_iac>0.0</gauge_iac>
<energy_today>5.667</energy_today>
<energy_total>1755.4</energy_total>
<hours_total>4347</hours_total>
<time_stamp>20140224 16:13</time_stamp>
</response>

For Domoticz I would like to display this information like the weather-data.
And secondly I would like to apply the value of <gauge power> as triggerpoint for switching.
Anyone with experience in such application?
Script(s) available which can do that function?

Re: XML as input information for Domoticz-readout & -switchi

Posted: Monday 24 February 2014 17:30
by elythomaslumber
That gave me the chance to play a little with XML I never did before.
Do you think that the code below could be a base for a solution?

Regarding your first question there's a possibility: http://www.domoticz.com/wiki/Domoticz_API/JSON_URL%27s
Look at the bottom for "Experts commands". I tried it it some weeks before but failed with a chrashed database. Don't know what I did wrong but never touched again :lol:

Examaple:

Code: Select all

#!/usr/bin/php
<?php

$xmlString = "<response>
<gauge_power>358</gauge_power>
<gauge_temp>0.0</gauge_temp>
<gauge_vpv>94.5</gauge_vpv>
<gauge_iac>0.0</gauge_iac>
<energy_today>5.667</energy_today>
<energy_total>1755.4</energy_total>
<hours_total>4347</hours_total>
<time_stamp>20140224 16:13</time_stamp>
</response>";

$xml = simplexml_load_string( $xmlString );  
  
  
//echo $xml->gauge_power;

$gp = $xml->gauge_power;
echo $gp;

if ( $gp > 200 ) {

$ch = curl_init("http://192.168.1.18:8080/json.htm?type=command&param=switchlight&idx=4&switchcmd=On&level=0");
curl_exec($ch);
curl_close($ch);
}

else if ( $gp <= 200 ) {

$ch = curl_init("http://192.168.1.18:8080/json.htm?type=command&param=switchlight&idx=4&switchcmd=off&level=0");
curl_exec($ch);
curl_close($ch);

}

?> 

Re: XML as input information for Domoticz-readout & -switchi

Posted: Wednesday 02 April 2014 10:04
by Toulon7559
:-( Bit puzzled.
Should not be so difficult, but I have no/little experience with XML and with Domoticz.
To me should look like:
1) read XML from IP-address
2) sort the data in the XML read-out to get the required parameter
3) display as information
4) make available as data for switching etc.

Correct approach? Or different plan-of-attack required?

Re: XML as input information for Domoticz-readout & -switchi

Posted: Wednesday 02 April 2014 13:02
by elythomaslumber
Yes, the data in XML format you received by a http request have to be "stored" in a variable like I used for this example: $xmlString

Then I used some "simplexml" commands as explained here: http://www.w3schools.com/php/php_xml_simplexml.asp

Finally with the CURL command you can switch Domoticz devices.

I don't know if you use an Raspberry Pi. If so, you need PHP5 and CURL which can be installed by:

Code: Select all

sudo service domoticz.sh stop
sudo su
cd
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install php5
sudo apt-get install php5-curl
exit
sudo service domoticz.sh start

Re: XML as input information for Domoticz-readout & -switchi

Posted: Wednesday 02 April 2014 13:08
by CopyCatz
I think the easiest way to do this is by using python. It's a lot easier than php and handles xml input in a very simplified way.

Re: XML as input information for Domoticz-readout & -switchi

Posted: Wednesday 02 April 2014 15:33
by jili
I'm not expert but in lua, you can use lxp, no?

Re: XML as input information for Domoticz-readout & -switchi

Posted: Friday 16 May 2014 22:15
by D'rMorris
A little late, bit check my post here: http://www.domoticz.com/forum/viewtopic.php?f=23&t=2505
I'm doing the same with the standby status of my Dreambox, which is also posted in XML after a curl command. You can leave out the curl of course and use xmlstarlet directly on the file.

Re: XML as input information for Domoticz-readout & -switchi

Posted: Tuesday 20 May 2014 7:09
by jili
I found solution too I use php and simplexml

Re: XML as input information for Domoticz-readout & -switchi

Posted: Monday 10 November 2014 8:09
by sabahat
I still have issues with activating RaspPi camera module. Domoticz freezes when adding the camera. Adding webcam or IP cam works perfectly

Re: XML as input information for Domoticz-readout & -switching

Posted: Sunday 01 May 2016 8:06
by Toulon7559
;-) Sometimes it just takes time before you find a working solution:
http://www.domoticz.com/forum/viewtopic ... 472#p84594

Re: XML as input information for Domoticz-readout & -switching

Posted: Sunday 23 December 2018 10:54
by Toulon7559
;-) looking for something else on another forum, I found an URL-string to directly read an XML-file with information from an SAJ-inverter:
http://<ip-address>/real_time_data.xml

The resulting XML-file looks like

Code: Select all

        <real_time_data><state>Wait</state><v-grid>229.6</v-grid><i-grid>0.07</i-grid><f-grid>49.98</f-grid><p-ac>0</p-ac><temp>18.3</temp><e-today>0.0</e-today><t-today>0.0</t-today><e-total>4576.2</e-total><CO2>4562.47</CO2><t-total>14435.6</t-total><v-pv1>275.0</v-pv1><i-pv1>0.02</i-pv1><v-pv2>-</v-pv2><i-pv2>-</i-pv2><v-bus>276.5</v-bus></real_time_data>
'Only' work left if you want that info going to Domoticz, is to make a suitable script like the one in the previous message:
initial attempt in another thread ......