XML as input information for Domoticz-readout & -switching

Topics (not sure which fora)
when not sure where to post, post here and mods will move it to right forum.

Moderators: leecollings, remb0

Post Reply
Toulon7559
Posts: 843
Joined: Sunday 23 February 2014 17:56
Target OS: Raspberry Pi / ODroid
Domoticz version: mixed
Location: Hengelo(Ov)/NL
Contact:

XML as input information for Domoticz-readout & -switching

Post 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?
Last edited by Toulon7559 on Sunday 01 May 2016 15:20, edited 1 time in total.
Set1 = RPI-Zero+RFXCom433+S0PCM+Shield for BMP180/DS18B20/RS485+DDS238-1ZNs
Set2 = RPI-3A++RFLinkGTW+ESP8266s+PWS_WS7000
Common = KAKUs+3*PVLogger+PWS_TFA_Nexus
plus series of 'satellites' for dedicated interfacing, monitoring & control.
User avatar
elythomaslumber
Posts: 56
Joined: Friday 12 July 2013 13:29
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.1
Location: Solingen; Germany
Contact:

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

Post 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);

}

?> 
Toulon7559
Posts: 843
Joined: Sunday 23 February 2014 17:56
Target OS: Raspberry Pi / ODroid
Domoticz version: mixed
Location: Hengelo(Ov)/NL
Contact:

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

Post 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?
Set1 = RPI-Zero+RFXCom433+S0PCM+Shield for BMP180/DS18B20/RS485+DDS238-1ZNs
Set2 = RPI-3A++RFLinkGTW+ESP8266s+PWS_WS7000
Common = KAKUs+3*PVLogger+PWS_TFA_Nexus
plus series of 'satellites' for dedicated interfacing, monitoring & control.
User avatar
elythomaslumber
Posts: 56
Joined: Friday 12 July 2013 13:29
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.1
Location: Solingen; Germany
Contact:

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

Post 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
User avatar
CopyCatz
Developer
Posts: 123
Joined: Thursday 11 July 2013 17:28
Target OS: -
Domoticz version:
Location: Outer Heaven
Contact:

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

Post 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.
jili
Posts: 12
Joined: Sunday 09 February 2014 15:27
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

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

Post by jili »

I'm not expert but in lua, you can use lxp, no?
D'rMorris
Posts: 138
Joined: Thursday 01 May 2014 9:01
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Netherlands - Sittard
Contact:

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

Post 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.
jili
Posts: 12
Joined: Sunday 09 February 2014 15:27
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

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

Post by jili »

I found solution too I use php and simplexml
sabahat
Posts: 1
Joined: Monday 10 November 2014 8:05
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

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

Post by sabahat »

I still have issues with activating RaspPi camera module. Domoticz freezes when adding the camera. Adding webcam or IP cam works perfectly
Cut down your exam stress by using our latest 642-747 dump and EMC demos.We provide updated Cornell University questions with 100% pass guarantee along with Youtube training.
Toulon7559
Posts: 843
Joined: Sunday 23 February 2014 17:56
Target OS: Raspberry Pi / ODroid
Domoticz version: mixed
Location: Hengelo(Ov)/NL
Contact:

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

Post by Toulon7559 »

;-) Sometimes it just takes time before you find a working solution:
http://www.domoticz.com/forum/viewtopic ... 472#p84594
Set1 = RPI-Zero+RFXCom433+S0PCM+Shield for BMP180/DS18B20/RS485+DDS238-1ZNs
Set2 = RPI-3A++RFLinkGTW+ESP8266s+PWS_WS7000
Common = KAKUs+3*PVLogger+PWS_TFA_Nexus
plus series of 'satellites' for dedicated interfacing, monitoring & control.
Toulon7559
Posts: 843
Joined: Sunday 23 February 2014 17:56
Target OS: Raspberry Pi / ODroid
Domoticz version: mixed
Location: Hengelo(Ov)/NL
Contact:

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

Post 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 ......
Set1 = RPI-Zero+RFXCom433+S0PCM+Shield for BMP180/DS18B20/RS485+DDS238-1ZNs
Set2 = RPI-3A++RFLinkGTW+ESP8266s+PWS_WS7000
Common = KAKUs+3*PVLogger+PWS_TFA_Nexus
plus series of 'satellites' for dedicated interfacing, monitoring & control.
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests