Sofar inverter - simple integration

Others (MiLight, Hue, Toon etc...)

Moderator: leecollings

Post Reply
witekp
Posts: 4
Joined: Saturday 24 September 2022 23:33
Target OS: Linux
Domoticz version:
Contact:

Sofar inverter - simple integration

Post by witekp »

A few days ago I decided to add the SOFAR inverter to the domoticz. I wrote a working script. Maybe it will be useful to someone. In addition to integrating the inverter, the script takes care of the problem of a possible domoticz error (after a power loss). In addition, it checks sunrises so as not to overload the processor. Lnes for downloading data from SOFAR is very short. Its method can be used for many other inverters.
Attachments
sofar.tgz
(1.65 KiB) Downloaded 314 times
User avatar
waltervl
Posts: 5397
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: Sofar inverter - simple integration

Post by waltervl »

Thanks for this perl script.
Perhaps you can add some extra instructions how to run this on the domoticz server. I suppose you start the script every x minutes with crontab?
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
witekp
Posts: 4
Joined: Saturday 24 September 2022 23:33
Target OS: Linux
Domoticz version:
Contact:

Re: Sofar inverter - simple integration

Post by witekp »

So I put the supplement.
Configuration consists of the following steps:

A) preparation of domoticz
- create Dummy equipment (e.g. SOFAR)
- create two virtual devices: STATUS - Text type, SOFAR - power and energy type
- read their idx's
B) Alternatively, install the missing perl libraries:

Code: Select all

LWP :: UserAgent; MIME :: Base64; JSON; Sys :: Syslog
(I don't know what distribution you have, so use google yourself to see the package name in your distribution)
C) I further assume that the domoticz directory is in your home directory (your name is john).

Code: Select all

cd ~/domoticz/scripts/
wget -O ./sofar.tgz "https://www.domoticz.com/forum/download/file.php?id=28722&sid=89c20055f3da17746a1c136b6d8025da"
tar -xzf ./sofar.tgz
chmod u+x ./sofar.pl
D) Edit the sofar.pl file, set the parameters in the #CONF area
E) Check just by running the script:

Code: Select all

./sofar.pl
Devices in domoticz should seting up.
F. Place the script in CRON:

Code: Select all

sudo crontab -e -u john
Add line (running script every 10 minutes):

Code: Select all

*/10 * * * * /usr/bin/perl /home/john/domoticz/scripts/sofar.pl >> /home/john/sofar.log
Finally, I suggest that you set in the script: $checksun = 1;
Logs appear in /var/log/syslog.
MartjeB
Posts: 7
Joined: Thursday 21 March 2024 9:57
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024
Contact:

Re: Sofar inverter - simple integration

Post by MartjeB »

Thanks for the script, but I'm stuck in preparation:

A) preparation of domoticz
- create Dummy equipment (e.g. SOFAR)
- create two virtual devices: STATUS - Text type, SOFAR - power and energy type
- read their idx's


In hardware I can select dymmy-virtual sensors.
create sensortype TEXT, I can select.
But power&energy ? is not in the list.
I chose sensortype Electric (instant + counter) but no luck.


For the text type virtual device I get an error after I run the script:
Error while getting data from SOFAR.
User avatar
waltervl
Posts: 5397
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: Sofar inverter - simple integration

Post by waltervl »

MartjeB wrote: Friday 12 July 2024 13:18
Error while getting data from SOFAR.
When I look into the perl script this error occures when the script cannot connect to your SOFAR inverter.

Check this part of the script:

Code: Select all

#SOFARCONF:
my $username='usersofar'; #Your username in SOFAR default admin
my $password='passsofar'; #Your password in SOFAR
my $inverter='192.168.1.88'; # Change to your inverter's IP/hostname
##############END OF CONFIG##################################
What happens if you run the command below manually in a terminal (and changing $username, $password and $inverter IP to the real values...)

Code: Select all

curl -s --user $username:$password http://$inverter/status.html
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
MartjeB
Posts: 7
Joined: Thursday 21 March 2024 9:57
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024
Contact:

Re: Sofar inverter - simple integration

Post by MartjeB »

The connection was blocked by my modem:
<HTML><HEAD><TITLE>401 Unauthorized</TITLE></HEAD>
<BODY BGCOLOR="#cc9999"><H4>401 Unauthorized</H4>
Authorization required.
</BODY></HTML>

After unblocking internet use of the inverter (in the fritzbox) I receive a line of data, but domoticz device is not updated after testing the script by:
./sofar.pl

I doubt my inverter answers the data needed.
I see some device info (SSID, LAN IP) but no inverter data.

part of the output:
addCfg('sta_ssid',-secret?-');
addCfg('ap_ssid',-secret?-');
addCfg('lan_ip',-secret?');
addCfg('sta_enable',-secret?-,'1');
var st_con1=""; var st_con2=""; var st_con3=""; function status(re) { var st_en=window.parent.reTip("3"); var st_dis=window.parent.reTip("4");
MartjeB
Posts: 7
Joined: Thursday 21 March 2024 9:57
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024
Contact:

Re: Sofar inverter - simple integration

Post by MartjeB »

if I login into the webif of the sofar inverter, the status menu is shown with only the device information.
I need to click the connected inverter icon to see data of the inverter itself.

In this way the script can't collect the right data I assume?
Attachments
sofar.jpg
sofar.jpg (45.18 KiB) Viewed 1409 times
MartjeB
Posts: 7
Joined: Thursday 21 March 2024 9:57
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024
Contact:

Re: Sofar inverter - simple integration

Post by MartjeB »

http://192.168.x.x/js/status.js

gives more data with a line:
myDeviceArray[0]="SA1xxxxxxx ,V500,,SA1ES116,6 00,20,231,75230,,0,"

Changing the script does not help domoticz showing anything.

Seems the dummy domoticz devices are of a wrong type...
User avatar
waltervl
Posts: 5397
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: Sofar inverter - simple integration

Post by waltervl »

MartjeB wrote: Saturday 13 July 2024 18:36 http://192.168.x.x/js/status.js

gives more data with a line:
myDeviceArray[0]="SA1xxxxxxx ,V500,,SA1ES116,6 00,20,231,75230,,0,"

Changing the script does not help domoticz showing anything.

Seems the dummy domoticz devices are of a wrong type...
This looks similar to the omnik inverter I have. So perhaps try this python plugin: https://github.com/sincze/Domoticz-Omni ... Web-Plugin
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
MartjeB
Posts: 7
Joined: Thursday 21 March 2024 9:57
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024
Contact:

Re: Sofar inverter - simple integration

Post by MartjeB »

I just did and it gives me data.

total today in not correct and total yield is 1000 times to high

I also had an error in domoticz:
2024-07-13 19:51:00.980 Error: GetJSonDevices: exception occurred : 'stoll'
might be caused by first selecting webdata in stead of mydevicearray
Attachments
read.jpg
read.jpg (9.97 KiB) Viewed 1387 times
solar.jpg
solar.jpg (46.32 KiB) Viewed 1387 times
User avatar
waltervl
Posts: 5397
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: Sofar inverter - simple integration

Post by waltervl »

Value is Ok. 7523.000 = 7523
Domoticz always show these values with 3 digits.
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests