Import data from Fronius Solar api
Moderator: leecollings
-
- Posts: 64
- Joined: Wednesday 11 May 2016 16:11
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Import data from Fronius Solar api
Is there a script that allows to import in domoticz the data of production via solar API?
Re: Import data from Fronius Solar api
did you try the search? Like search for "Fronius"? You know the upper right corner?
http://domoticz.com/forum/viewtopic.php ... it=Fronius
http://domoticz.com/forum/viewtopic.php ... it=Fronius
-
- Posts: 64
- Joined: Wednesday 11 May 2016 16:11
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Import data from Fronius Solar api
I read it, but......trixwood wrote:did you try the search? Like search for "Fronius"? You know the upper right corner?
http://domoticz.com/forum/viewtopic.php ... it=Fronius
1) I don't want to install emoncms, feed data to this and then pass them to domoticz. I'd like to transfer them in real time directly from the inverter to domotic via solar API call. I am actually downloading data from the inverter (using the Fronius push service) to PVoutput which feeds domoticz. The problem is that the push service sends data every five minutes, so I can't have the production data in real time into domoticz.
2) if I launch a http request like this"http://192.168.x.xxx./solar_api/v1/GetI ... verterData" I get a json file with all the readings in real time. II think it is possible to feed a virtual sensor with this data, but how?
- Egregius
- Posts: 2592
- Joined: Thursday 09 April 2015 12:19
- Target OS: Linux
- Domoticz version: v2024.7
- Location: Beitem, BE
- Contact:
Re: Import data from Fronius Solar api
Your inverter has a json api interface?
Run a script that pulls that json, decode it and push it to domoticz to a virtual solar device.
Is you post a json example I can create a php script for you.
I do something similar but my data comes from a csv that's updated every minute. Once the value is in Domoticz I use it to decide if lights need to switch on and stuff like that.
Run a script that pulls that json, decode it and push it to domoticz to a virtual solar device.
Is you post a json example I can create a php script for you.
I do something similar but my data comes from a csv that's updated every minute. Once the value is in Domoticz I use it to decide if lights need to switch on and stuff like that.
-
- Posts: 64
- Joined: Wednesday 11 May 2016 16:11
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Import data from Fronius Solar api
Yes, my fronius inverter supports json Api interface.Egregius wrote:Your inverter has a json api interface?
Run a script that pulls that json, decode it and push it to domoticz to a virtual solar device.
Is you post a json example I can create a php script for you.
I do something similar but my data comes from a csv that's updated every minute. Once the value is in Domoticz I use it to decide if lights need to switch on and stuff like that.
Tomorrow, when the inverter is active, i'll post the json reply from the http request.
Thanx
-
- Posts: 64
- Joined: Wednesday 11 May 2016 16:11
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Import data from Fronius Solar api
Below the reply from the api call:Egregius wrote:Your inverter has a json api interface?
Run a script that pulls that json, decode it and push it to domoticz to a virtual solar device.
Is you post a json example I can create a php script for you.
I do something similar but my data comes from a csv that's updated every minute. Once the value is in Domoticz I use it to decide if lights need to switch on and stuff like that.
http://192.168.X.XXX/solar_api/v1/GetIn ... verterData
PAC is the value of AC power generated in real time
Code: Select all
{
"Head" : {
"RequestArguments" : {
"DataCollection" : "CommonInverterData",
"DeviceClass" : "Inverter",
"DeviceId" : "1",
"Scope" : "Device"
},
"Status" : {
"Code" : 0,
"Reason" : "",
"UserMessage" : ""
},
"Timestamp" : "2016-07-24T18:22:14+02:00"
},
"Body" : {
"Data" : {
"DAY_ENERGY" : {
"Value" : 17710,
"Unit" : "Wh"
},
"FAC" : {
"Value" : 50,
"Unit" : "Hz"
},
"IAC" : {
"Value" : 2.56,
"Unit" : "A"
},
"IDC" : {
"Value" : 1.8,
"Unit" : "A"
},
"PAC" : {
"Value" : 570,
"Unit" : "W"
},
"TOTAL_ENERGY" : {
"Value" : 507147.03,
"Unit" : "Wh"
},
"UAC" : {
"Value" : 231.5,
"Unit" : "V"
},
"UDC" : {
"Value" : 345.9,
"Unit" : "V"
},
"YEAR_ENERGY" : {
"Value" : 507147.72,
"Unit" : "Wh"
},
"DeviceStatus" : {
"StatusCode" : 7,
"MgmtTimerRemainingTime" : -1,
"ErrorCode" : 0,
"LEDColor" : 2,
"LEDState" : 0,
"StateToReset" : false
}
}
}
}
- Westcott
- Posts: 423
- Joined: Tuesday 09 December 2014 17:04
- Target OS: Raspberry Pi / ODroid
- Domoticz version: Beta
- Location: UK - Glos
- Contact:
Re: Import data from Fronius Solar api
There are many examples on this forum showing how to read JSON data directly with Lua, and update virtual devices.
Zwave - Sigma Z+ stick, Fibaro, Horstmann, Neo Coolcam, EUROtronic
RFlink - IR detectors and temperatures
Wifi - YeeLights, ESP32s, Anoop sockets
Zigbee - lots with zigbee2mqtt and ZbBridge
RFlink - IR detectors and temperatures
Wifi - YeeLights, ESP32s, Anoop sockets
Zigbee - lots with zigbee2mqtt and ZbBridge
- Egregius
- Posts: 2592
- Joined: Thursday 09 April 2015 12:19
- Target OS: Linux
- Domoticz version: v2024.7
- Location: Beitem, BE
- Contact:
Re: Import data from Fronius Solar api
create a file /home/pi/solar.php
make it executable:
chmod +x /home/pi/solar.php
add the script to cron (crontab -e)
* 7-23 * * * /home/pi/solar.php
That's every minute between from 7 till 23.
Code: Select all
#!/usr/bin/php
<?php
$data = json_decode(file_get_contents('http://192.168.x.xxx/solar_api/v1/GetInverterRealtimeData.cgi?Scope=Device&DeviceID=1&DataCollection=CommonInverterData'),true);
if(isset($data['Body']['Data']['PAC']['Value'])) {
file_get_contents('http://127.0.0.1:8084/json.htm?type=command¶m=udevice&idx=412&nvalue=0&svalue='.$data['Body']['Data']['PAC']['Value']);
}
chmod +x /home/pi/solar.php
add the script to cron (crontab -e)
* 7-23 * * * /home/pi/solar.php
That's every minute between from 7 till 23.
-
- Posts: 64
- Joined: Wednesday 11 May 2016 16:11
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Import data from Fronius Solar api
i can't execute the script. I create the php file and changed the idx number of my sensor, the ip number and port of domoticz, added the scripts to crontab and maked executable with chmod, but nothingEgregius wrote:create a file /home/pi/solar.phpmake it executable:Code: Select all
#!/usr/bin/php <?php $data = json_decode(file_get_contents('http://192.168.x.xxx/solar_api/v1/GetInverterRealtimeData.cgi?Scope=Device&DeviceID=1&DataCollection=CommonInverterData'),true); if(isset($data['Body']['Data']['PAC']['Value'])) { file_get_contents('http://127.0.0.1:8084/json.htm?type=command¶m=udevice&idx=412&nvalue=0&svalue='.$data['Body']['Data']['PAC']['Value']); }
chmod +x /home/pi/solar.php
add the script to cron (crontab -e)
* 7-23 * * * /home/pi/solar.php
That's every minute between from 7 till 23.
The attributes of php file are correct?
Code: Select all
-rwxr-xr-x 1 pi pi 395 Jul 26 19:14 solar.php
.
Code: Select all
#!/usr/bin/php
<?php
$data = json_decode(file_get_contents('http://192.168.1.103/solar_api/v1/GetInverterRealtimeData.cgi?Scope=Device&DeviceID=1&DataCollection=CommonInverterData'),true);
if(isset($data['Body']['Data']['PAC']['Value'])) {
file_get_contents('http://192.168.x.xxx:8080/json.htm?type=command¶m=udevice&idx=58&nvalue=0&svalue='.$data['Body']['Data']['PAC']['Value']);
}
- Egregius
- Posts: 2592
- Joined: Thursday 09 April 2015 12:19
- Target OS: Linux
- Domoticz version: v2024.7
- Location: Beitem, BE
- Contact:
Re: Import data from Fronius Solar api
Add a line like this to see if php is ok:
echo 'test';
And also add echo in front of the file_get_contents of the udevice command to see the reply of domoticz.
Otherwise there's no output.
echo 'test';
And also add echo in front of the file_get_contents of the udevice command to see the reply of domoticz.
Otherwise there's no output.
-
- Posts: 64
- Joined: Wednesday 11 May 2016 16:11
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Import data from Fronius Solar api
the first echo test is ok but the second echo on the line of "file_get_contents" is negative...



- Egregius
- Posts: 2592
- Joined: Thursday 09 April 2015 12:19
- Target OS: Linux
- Domoticz version: v2024.7
- Location: Beitem, BE
- Contact:
Re: Import data from Fronius Solar api
Can you post the output of this:
Code: Select all
#!/usr/bin/php
<?php
echo 'test 1';
$data = json_decode(file_get_contents('http://192.168.1.103/solar_api/v1/GetInverterRealtimeData.cgi?Scope=Device&DeviceID=1&DataCollection=CommonInverterData'),true);
print_r($data);
if(isset($data['Body']['Data']['PAC']['Value'])) {
echo 'test 2';
echo 'PAC='.$data['Body']['Data']['PAC']['Value'];
file_get_contents('http://192.168.x.xxx:8080/json.htm?type=command¶m=udevice&idx=58&nvalue=0&svalue='.$data['Body']['Data']['PAC']['Value']);
}
-
- Posts: 64
- Joined: Wednesday 11 May 2016 16:11
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Import data from Fronius Solar api
yess, we are, now the sensor read the output.
1 read only, when i launched the script in putty. I added the php file in crontab, but it doesn't seems to work
Is it possible to add the DAY ENERGY and the TOTAL ENERGY in the script? Thanx in advance

1 read only, when i launched the script in putty. I added the php file in crontab, but it doesn't seems to work

Is it possible to add the DAY ENERGY and the TOTAL ENERGY in the script? Thanx in advance
Code: Select all
test 1Array
(
[Head] => Array
(
[RequestArguments] => Array
(
[DataCollection] => CommonInverterData
[DeviceClass] => Inverter
[DeviceId] => 1
[Scope] => Device
)
[Status] => Array
(
[Code] => 0
[Reason] =>
[UserMessage] =>
)
[Timestamp] => 2016-07-27T19:16:46+02:00
)
[Body] => Array
(
[Data] => Array
(
[DAY_ENERGY] => Array
(
[Value] => 18862
[Unit] => Wh
)
[FAC] => Array
(
[Value] => 49.98
[Unit] => Hz
)
[IAC] => Array
(
[Value] => 1.03
[Unit] => A
)
[IDC] => Array
(
[Value] => 0.67
[Unit] => A
)
[PAC] => Array
(
[Value] => 196
[Unit] => W
)
[TOTAL_ENERGY] => Array
(
[Value] => 572775
[Unit] => Wh
)
[UAC] => Array
(
[Value] => 219.1
[Unit] => V
)
[UDC] => Array
(
[Value] => 351.4
[Unit] => V
)
[YEAR_ENERGY] => Array
(
[Value] => 572775.44
[Unit] => Wh
)
[DeviceStatus] => Array
(
[StatusCode] => 7
[MgmtTimerRemainingTime] => -1
[ErrorCode] => 0
[LEDColor] => 2
[LEDState] => 0
[StateToReset] =>
)
)
)
)
- Egregius
- Posts: 2592
- Joined: Thursday 09 April 2015 12:19
- Target OS: Linux
- Domoticz version: v2024.7
- Location: Beitem, BE
- Contact:
Re: Import data from Fronius Solar api
It isn't very hard to add more values, just walk thru the array:
I always put a microsleep of 1/4 sec between commands, just to not stress the system to much.
I also added a logfile (make sure /var/log is writable for the user that runs the script) to check if it runs in cron.
Code: Select all
#!/usr/bin/php
<?php
$data = json_decode(file_get_contents('http://192.168.1.103/solar_api/v1/GetInverterRealtimeData.cgi?Scope=Device&DeviceID=1&DataCollection=CommonInverterData'),true);
print_r($data);
if(isset($data['Body']['Data']['PAC']['Value'])) {
$result = file_get_contents('http://192.168.x.xxx:8080/json.htm?type=command¶m=udevice&idx=58&nvalue=0&svalue='.$data['Body']['Data']['PAC']['Value']);
logwrite($result);
usleep(250000);
$result = file_get_contents('http://192.168.x.xxx:8080/json.htm?type=command¶m=udevice&idx=59&nvalue=0&svalue='.$data['Body']['Data']['DAY_ENERGY']['Value']);
logwrite($result);
usleep(250000);
$result = file_get_contents('http://192.168.x.xxx:8080/json.htm?type=command¶m=udevice&idx=60&nvalue=0&svalue='.$data['Body']['Data']['TOTAL_ENERGY']['Value']);
logwrite($result);
}
function logwrite($msg) {
$time = microtime(true);
$dFormat = "Y-m-d H:i:s";
$mSecs = $time - floor($time);
$mSecs = substr(number_format($mSecs,3),1);
$fp = fopen(/var/log/fronius.log,"a+");
fwrite($fp, sprintf("%s%s %s %s\n", date($dFormat), $mSecs, $msg));
fclose($fp);
}
I also added a logfile (make sure /var/log is writable for the user that runs the script) to check if it runs in cron.
-
- Posts: 64
- Joined: Wednesday 11 May 2016 16:11
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Import data from Fronius Solar api
I always put a microsleep of 1/4 sec between commands, just to not stress the system to much.
I also added a logfile (make sure /var/log is writable for the user that runs the script) to check if it runs in cron.[/quote]
I changed the owner (pi) to the log folder and add the permission to be writable (700) at the owner. Is it correct?
but when i launch the php file it says
HP Parse error: syntax error, unexpected '/' in /home/pi/solar.php on line 21
I also added a logfile (make sure /var/log is writable for the user that runs the script) to check if it runs in cron.[/quote]
I changed the owner (pi) to the log folder and add the permission to be writable (700) at the owner. Is it correct?
but when i launch the php file it says
HP Parse error: syntax error, unexpected '/' in /home/pi/solar.php on line 21
-
- Posts: 64
- Joined: Wednesday 11 May 2016 16:11
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Import data from Fronius Solar api
I always put a microsleep of 1/4 sec between commands, just to not stress the system to much.
I also added a logfile (make sure /var/log is writable for the user that runs the script) to check if it runs in cron.[/quote]
I changed the owner (pi) to the log folder and add the permission to be writable (700) at the owner. Is it correct?
but when i launch the php file it says
HP Parse error: syntax error, unexpected '/' in /home/pi/solar.php on line 21
I also added a logfile (make sure /var/log is writable for the user that runs the script) to check if it runs in cron.[/quote]
I changed the owner (pi) to the log folder and add the permission to be writable (700) at the owner. Is it correct?
Code: Select all
drwx------ 10 pi pi 4096 Jul 28 00:56 log
HP Parse error: syntax error, unexpected '/' in /home/pi/solar.php on line 21
- Egregius
- Posts: 2592
- Joined: Thursday 09 April 2015 12:19
- Target OS: Linux
- Domoticz version: v2024.7
- Location: Beitem, BE
- Contact:
Re: Import data from Fronius Solar api
Oh, forgot to quote the logfile.
$fp = fopen(/var/log/fronius.log,"a+");
Must be
$fp = fopen('/var/log/fronius.log',"a+");
$fp = fopen(/var/log/fronius.log,"a+");
Must be
$fp = fopen('/var/log/fronius.log',"a+");
-
- Posts: 64
- Joined: Wednesday 11 May 2016 16:11
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Import data from Fronius Solar api
the script works on all 3 sensor.Egregius wrote:Oh, forgot to quote the logfile.
$fp = fopen(/var/log/fronius.log,"a+");
Must be
$fp = fopen('/var/log/fronius.log',"a+");
I have this warnirng the the end of the script
Code: Select all
PHP Warning: sprintf(): Too few arguments in /home/pi/solar.php on line 22
PHP Warning: sprintf(): Too few arguments in /home/pi/solar.php on line 22
PHP Warning: sprintf(): Too few arguments in /home/pi/solar.php on line 22
the crontab seems correct....
Code: Select all
# For example, you can run a backup of all your user accounts
# at 5 a.m every week with:
# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
#
# For more information see the manual pages of crontab(5) and cron(8)
#
# m h dom mon dow command
* 7-24 * * * /home/pi/solar.php
- Egregius
- Posts: 2592
- Joined: Thursday 09 April 2015 12:19
- Target OS: Linux
- Domoticz version: v2024.7
- Location: Beitem, BE
- Contact:
Re: Import data from Fronius Solar api
Didn't test the code, copied from my script and stripped the unneeded stuff, sorry for the errors. There's a %s to much in the sprintf line.
I always run scripts as root (sudo crontab -e)
Never used a user crontab, don't even know if that's executed without being logged in.
Also, maybe test with chmod 755 solar.php
Was there a logfile after running manually?
Code: Select all
#!/usr/bin/php
<?php
$data = json_decode(file_get_contents('http://192.168.1.103/solar_api/v1/GetInverterRealtimeData.cgi?Scope=Device&DeviceID=1&DataCollection=CommonInverterData'),true);
print_r($data);
if(isset($data['Body']['Data']['PAC']['Value'])) {
$result = file_get_contents('http://192.168.x.xxx:8080/json.htm?type=command¶m=udevice&idx=58&nvalue=0&svalue='.$data['Body']['Data']['PAC']['Value']);
logwrite($result);
usleep(250000);
$result = file_get_contents('http://192.168.x.xxx:8080/json.htm?type=command¶m=udevice&idx=59&nvalue=0&svalue='.$data['Body']['Data']['DAY_ENERGY']['Value']);
logwrite($result);
usleep(250000);
$result = file_get_contents('http://192.168.x.xxx:8080/json.htm?type=command¶m=udevice&idx=60&nvalue=0&svalue='.$data['Body']['Data']['TOTAL_ENERGY']['Value']);
logwrite($result);
}
function logwrite($msg) {
$time = microtime(true);
$dFormat = "Y-m-d H:i:s";
$mSecs = $time - floor($time);
$mSecs = substr(number_format($mSecs,3),1);
$fp = fopen(/var/log/fronius.log,"a+");
fwrite($fp, sprintf("%s%s %s\n", date($dFormat), $mSecs, $msg));
fclose($fp);
}
Never used a user crontab, don't even know if that's executed without being logged in.
Also, maybe test with chmod 755 solar.php
Was there a logfile after running manually?
-
- Posts: 64
- Joined: Wednesday 11 May 2016 16:11
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Import data from Fronius Solar api
Now the script works well, thanx.
I ask you for an advice on another php script already running.
The script below, reads from a meter (eastron sdm 220 c) under rs485 modbus.
All the readings works well.
I'd like to import the reading of the energy imported (-i).
I entered in line n. 5 -i for reading, and at the bottom of the file the reference to the idx n.44 for the reading of imported energy. When I restart the script I find inverted the two readings ( exported on 44 and imported on 43 ) Why ?

I ask you for an advice on another php script already running.
The script below, reads from a meter (eastron sdm 220 c) under rs485 modbus.
All the readings works well.
I'd like to import the reading of the energy imported (-i).
I entered in line n. 5 -i for reading, and at the bottom of the file the reference to the idx n.44 for the reading of imported energy. When I restart the script I find inverted the two readings ( exported on 44 and imported on 43 ) Why ?
Code: Select all
#!/usr/bin/php
<?php
$data = array();
inizio:
$x = exec("/usr/local/bin/sdm120c -v -c -p -g -f -e -i -t -q -w3 -z5 /dev/ttyUSB0");
$data = preg_split('/[[:space:]]+/', $x);
if ($data[8] = 'OK') {
$tensione = $data[0];
$corrente = $data[1];
$potenza = $data[2];
$cosfi = $data[3];
//$frequenza_2 = $data[4];
$immessa = $data[5];
$prelevata = $data[6];
$energia = $data[7];
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://192.168.X.XXX:8080/json.htm?type=command¶m=udevice&idx=1&nvalue=0&svalue=$tensione");
$oem = curl_exec($ch);
curl_close($ch);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://192.168.X.XXX:8080/json.htm?type=command¶m=udevice&idx=2&nvalue=0&svalue=$corrente");
$oem = curl_exec($ch);
curl_close($ch);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://192.168.X.XXX:8080/json.htm?type=command¶m=udevice&idx=3&nvalue=0&svalue=$potenza;$energia");
$oem = curl_exec($ch);
curl_close($ch);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://192.168.X.XXX:8080/json.htm?type=command¶m=udevice&idx=4&nvalue=0&svalue=$cosfi");
$oem = curl_exec($ch);
curl_close($ch);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://192.168.X.XXX:8080/json.htm?type=command¶m=udevice&idx=43&nvalue=0&svalue=$immessa");
$oem = curl_exec($ch);
curl_close($ch);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://192.168.X.XXX:8080/json.htm?type=command¶m=udevice&idx=44&nvalue=0&svalue=$prelevata");
$oem = curl_exec($ch);
curl_close($ch);
//sleep(2);
goto inizio;
?>
Who is online
Users browsing this forum: No registered users and 1 guest