Page 4 of 7

Re: SolarEdge via LAN interface

Posted: Friday 06 September 2019 19:08
by Jackb
To make the script work you have to install several PERL modules:

Net::Server
Role::Tiny
Try::Tiny
Device::Modbus::TCP::Client
LWP::Simple

To do this type:
$ sudo perl -MCPAN -e shell

And then
cpan[1]> install <module name>

Repeat this for all the other modules
The last one (LWP::Simple) takes some more time. Be patient.
cpan [6]> exit

The script should work now. I downloaded it and called it: SolarEdge.pl
Try:

$ perl SolarEdge.pl
A help text should be displayed.

For Domoticz you have to create several dummy devices. For more info see the script.

Re: SolarEdge via LAN interface

Posted: Wednesday 11 September 2019 20:40
by ahjwinth
I have tried the above instructions to install the SolarEdge via Lan but I can't get this to work. Do I also need the Sunspec-monitor from github installed?

Re: SolarEdge via LAN interface

Posted: Wednesday 11 September 2019 22:44
by freijn
What bit is not working??

Re: SolarEdge via LAN interface

Posted: Saturday 14 September 2019 20:20
by ahjwinth
I have followed the steps in the post above and install the dependency's. But do I need to use the script, and how do I need to install this script (i'm noob)
Or do I use the in Domoticz under Hardware the " solaredge via Lan interface"

Re: SolarEdge via LAN interface

Posted: Sunday 15 September 2019 19:06
by Jackb
You do not need to Add Hardware in Domoticz.

First you have to enable de TCPModbus interface on your SolarEdge inverter. How to do that depends on the type of SolarEdge inverter you have.

Then you need to download the script and rename it to SolarEdge.pl

Then type: perl SolarEdge.pl If correct you will see a help text, about parameters you need to connect to your inverter.
If you can connect to your inverter and get values out of it, then open the script and follow the instructions.
Then following the instructions, create the dummy devices and add their IDX numbers in the script.

Then run the script again adding the -z parameter. The dummy devices in Domoticz should now contain values.
If that is working then you can schedule the script using Crontab or from within Domoticz using Events.

If you do not understand the above instructions, then you should famliarize yourself some more with Domoticz and scripts. Searching this forum will help you a lot.

Re: SolarEdge via LAN interface

Posted: Monday 16 September 2019 21:18
by ahjwinth
Jackb wrote: Sunday 15 September 2019 19:06 You do not need to Add Hardware in Domoticz.

First you have to enable de TCPModbus interface on your SolarEdge inverter. How to do that depends on the type of SolarEdge inverter you have.

Then you need to download the script and rename is to SolarEdge.pl

Then type: perl SolarEdge.pl If correct you will see a help text, about parameters you need to connect to your inverter.
If you can connect to your inverter and get values out of it the open the script and follow the instructions.
Then following the instructions, create the dummy devices and add their IDX numbers in the script.

Then run the script again adding the -z parameter. The dummy devices in Domoticz should now contain values.
If that is working then you can schedule the script using Crontab or from within Domoticz using Events.

If you do not understand the above instructions, then you should famliarize yourself some more with Domoticz and scripts. Searching this forum will help you a lot.
Thanks Jackb I got the connection with the Solar edge working and all values in Domoticz. Now waiting until the sun starts shining again so I get some production data in Domoticz.

Re: SolarEdge via LAN interface

Posted: Tuesday 17 September 2019 19:22
by Jackb
Great! :)

Re: SolarEdge via LAN interface

Posted: Monday 07 October 2019 22:44
by marin849
Thanks!!!
Just tried the script, works great.

Re: SolarEdge via LAN interface

Posted: Wednesday 09 October 2019 18:04
by mjier
Thank you all for the instructions and script!
I am an absolute beginner with modbus and perl scripts, but the system was working quickly.
Is there a reason why you should run the script with crontab? In my system the script is executed with DzEvents, using the command os.execute('perl etc etc'). The domoticz sensors update every 10 seconds.

Greetings,
Eric

Re: SolarEdge via LAN interface

Posted: Wednesday 09 October 2019 19:30
by McMelloW
mjier wrote: Wednesday 09 October 2019 18:04 Is there a reason why you should run the script with crontab? In my system the script is executed with DzEvents, using the command os.execute('perl etc etc'). The domoticz sensors update every 10 seconds.
No need at all. See my code below, it is just in my dzVents script on my timing and use it every minute.

Code: Select all

	on = {
		timer = { 'every minute between 15 minutes before sunrise and 15 minutes after sunset' } 
	},
	
	execute = function(domoticz, device)
	    
    	domoticz.utils.osExecute('perl /home/pi/Public/sunspec-mon -n -m o 192.168.999.999 > /tmp/SEoutput.txt')
 

Re: SolarEdge via LAN interface

Posted: Wednesday 09 October 2019 22:06
by freijn
There is a reason.

if something happens on the network and the script is not able to reach the SolarEdge the script might take longer.
This longer will hold-up all scripts executed after.
It does appear in the log's like "bla bla script takes longer than expected to finish"

Result might be that the next script does miss an important status from a sensor.. !! MIGHT !!

Starting it via cron makes sure its exe'ed independent of the events being exe under domoticz.
The events are a chain of scripts exe sequentially.

Question:
Do you have a smart meter P1 ? I trigger the solar script when the new P1 values have arrived.
At that moment I run the Solar script and at the end I do a P1 + or - Solar = House power consumed.
More fun !

Hope the above makes sense to you...

Frank

Re: SolarEdge via LAN interface

Posted: Thursday 10 October 2019 16:22
by Jackb
freijn wrote: Wednesday 09 October 2019 22:06 There is a reason.

if something happens on the network and the script is not able to reach the SolarEdge the script might take longer.
This longer will hold-up all scripts executed after.
It does appear in the log's like "bla bla script takes longer than expected to finish"

Result might be that the next script does miss an important status from a sensor.. !! MIGHT !!

Starting it via cron makes sure its exe'ed independent of the events being exe under domoticz.
The events are a chain of scripts exe sequentially.

Question:
Do you have a smart meter P1 ? I trigger the solar script when the new P1 values have arrived.
At that moment I run the Solar script and at the end I do a P1 + or - Solar = House power consumed.
More fun !

Hope the above makes sense to you...

Frank
That is exactly the reason I use crontab to run the script.

Re: SolarEdge via LAN interface

Posted: Thursday 10 October 2019 21:11
by McMelloW
freijn wrote: Wednesday 09 October 2019 22:06 There is a reason.

if something happens on the network and the script is not able to reach the SolarEdge the script might take longer.
This longer will hold-up all scripts executed after.
It does appear in the log's like "bla bla script takes longer than expected to finish"
Frank & Jackb

Thanks for your addition.
In my system I have had only once this error message. After I change something in the script, it never appeared again.
My script is running fine so far.

Re: SolarEdge via LAN interface

Posted: Thursday 10 October 2019 21:33
by mjier
freijn wrote: Wednesday 09 October 2019 22:06 There is a reason.

if something happens on the network and the script is not able to reach the SolarEdge the script might take longer.
This longer will hold-up all scripts executed after.
It does appear in the log's like "bla bla script takes longer than expected to finish"

Result might be that the next script does miss an important status from a sensor.. !! MIGHT !!

Starting it via cron makes sure its exe'ed independent of the events being exe under domoticz.
The events are a chain of scripts exe sequentially.

Question:
Do you have a smart meter P1 ? I trigger the solar script when the new P1 values have arrived.
At that moment I run the Solar script and at the end I do a P1 + or - Solar = House power consumed.
More fun !

Hope the above makes sense to you...

Frank
Yes I have a P1 meter connected. So I can see the delivery and my production. Thanks for the suggestion, I think I have to learn some more about scripting and DZ-events.
There is always More to Explore!

Eric
ps, Thanks McMellow for your script.

Re: SolarEdge via LAN interface

Posted: Friday 11 October 2019 17:45
by freijn
Eric,

if you are interested I can share my consume calculations script ( triggered by the P1)

Re: SolarEdge via LAN interface

Posted: Friday 11 October 2019 20:56
by mjier
That would be nice Frank!
I feel a bit like Alice, and it would help me to explore the rabbithole.

Thanks in advance,
Eric

Re: SolarEdge via LAN interface

Posted: Friday 11 October 2019 22:34
by freijn
Eric

The lua code I execute when the device update happens. In this case the P1 sensor is the trigger.
You have to create a custom power sensor 'PowerConsumption' where calculated value is shown.
P1 triggers the script. Script grabs solar values. Depending of amount of Sun we are delivering to grid or getting from grid
so : solar - P1 = consume or solar + P1 = consume.
The calculated value is then written to the aditional energy sensor.

Please mind, Script was not written with the intention to share so a bit messy....sorry
I hope it has enough comments to get you started. You need to rename the sensors to match your environment.
If nothing works, use the debug switch to understand the output and results.

Hope there is enough Sun this weekend to get you testing :-)

Any questions, please let me know.

Code: Select all


----------------------------------------------------------------------------------------------------------
Debug = "NO"                    -- Turn debugging on ("YES") or off ("NO")
----------------------------------------------------------------------------------------------------------
-- Grid Power calculation    GridPower +/- Solar Power  
----------------------------------------------------------------------------------------------------------
local solarflag
local var5
local var6
local powercount
local consume
local oldpowerconsume

commandArray = {}

-- The P1 sensor name
powersensor = "Power"
if (devicechanged[powersensor]) then
-- grab the latest solar values   
    zon_success=os.execute('perl /home/pi/sunspec-monitor-master/domosun.pl -z -m 0 -p 502 192.168.1.140 &')
    if Debug=="YES" then
        print( " ####Power debug device changed: "..devicechanged[powersensor])
    end
    commandArray['Variable:TEST']=tostring(devicechanged[powersensor])
    var1,var2,var3,var4,var5,var6 = string.match(otherdevices_svalues['Power'], "(%d+%.*%d*);(%d+%.*%d*);(%d+%.*%d*);(%d+%.*%d*);(%d+%.*%d*);(%d+%.*%d*)")
    if Debug=="YES" then
        print( " ####Power debug var5: "..var5)
        print( " ####Power debug var6: "..var6)
    end
    solarflag="0"  
    if (var5 == "0") then 
    -- solar is feeding the grid
        powercount = tonumber(var6)
        solarflag="1"
    else
    -- not enough solar power , so taken from grid
        powercount = tonumber(var5)
    end
    if Debug=="YES" then
        print( " ####Powercount after solarflag: "..powercount)
        print( " ####solarflag: "..solarflag)
    end
    commandArray['Variable:GridPowerVar']= tostring (powercount)
    commandArray['Variable:SolarPowerFlag']= solarflag

    -- store value in variable for later use in other scpt 
    --commandArray['Variable:GridPowerVar']= tostring(powercount)

-- testing stuff
--commandArray['Variable:SolarPowerVar']= tostring (1100)
--solarflag =1 


   -- get solar power from var and make number
  --commandArray['Variable:SolarPowerVar']= "12"
  
  -- print ( "solarwaarde "..commandArray['Variable:SolarPowerVar'])
   -- for i, v in pairs(otherdevices) do print(i, v) end
   
   --solarsensor = "SolarEdge kWh"
   solarsensor = "SolarEdge Power Kwh"
   Solarvar1, var2 = string.match(otherdevices_svalues[solarsensor], "(%d+%.*%d*);(%d+%.*%d*)")
   Sol = tostring (Solarvar1)
  
  -- solarcount = commandArray['Variable:SolarPowerVar']
  if Debug=="YES" then
    print("####solarcount read from Var : "..Sol)
  end
  
  -- depending on Solar power we are running from Solar only or need grid power
  if ( solarflag == "1") then  
    consume = Solarvar1 - powercount
  else    
    consume = Solarvar1 + powercount
  end 

 if Debug=="YES" then
    print( " ####solarcount : "..Solarvar1)
    print( " ####powercount : "..powercount)
    print( " ####solarflag  : "..solarflag)
    print( " ####consume : "..consume)
 end

 -- the new sensor to show house consumption  
 ttidx = otherdevices_idx['PowerConsumption']
 commandArray['UpdateDevice'] = ttidx..'|0|'..consume
 

-- Log power usage into file
--year 	= tonumber(os.date("%Y"));
--month 	= tonumber(os.date("%m"));
--day 	= tonumber(os.date("%d"));
--hour 	= tonumber(os.date("%H"));
--min 	= tonumber(os.date("%M"));


--powerdiff = (tonumber(uservariables['oldpowerconsume'])) - consume
-- print( " ####oldpowerconsume : "..oldpowerconsume)
--if powerdiff > 3 or powerdiff < -3 then
 -- write consumer output file
--   file = io.open("consumedpower.txt", "a") 
   -- Opens a file named sensor.txt(stored under Domoticz folder) 
   -- in append mode
    --write to opened file
--    file:write(os.date()..";"..consume..";"..powerdiff.."\n")
--    file:close() --closes the open file
--end

  commandArray['Variable:oldpowerconsume'] = tostring(consume)


end 
return commandArray

Re: SolarEdge via LAN interface

Posted: Tuesday 15 October 2019 16:19
by Micha123
I found sunspec_ardexa


It ia a python script and is working much faster then the pearl script


https://pypi.org/project/sunspec-ardexa/

And you dont need to install much librarys for it

$ sunspec_ardexa discover 192.168.102.41 1


Output is


Name: common Sunspec Id: 1 Label: Common
Manufacturer (Mn) SolarEdge
Model (Md) SE4000
Version (Vr) 0003.2221
Serial Number (SN) 73133F27
Device Address (DA) 1

Name: inverter Sunspec Id: 101 Label: Inverter (Single Phase)
Amps (A) 1.74 A
Amps PhaseA (AphA) 1.74 A
Phase Voltage AB (PPVphAB) 236.0 V
Watts (W) 383.1 W
Hz (Hz) 50.02 Hz
VA (VA) 412.5 VA
VAr (VAr) 152.88 var
PF (PF) 92.87 Pct
WattHours (WH) 9371992 Wh
DC Amps (DCA) 1.0329 A
DC Voltage (DCV) 376.5 V
DC Watts (DCW) 388.9 W
Heat Sink Temperature (TmpSnk) 41.79 C
Operating State (St) MPPT
Vendor Operating State (StVnd) 0
Vendor Event Bitfield 1 (EvtVnd1) 1
Vendor Event Bitfield 4 (EvtVnd4) 0

Re: SolarEdge via LAN interface

Posted: Wednesday 16 October 2019 19:42
by McMelloW
@micha123

Thanks for the tip. It looks great and it is much easier and faster to install then the perl script. It works OK with a TCP LAN configuration
Here is the output of my first test.

Code: Select all

Name:  common   Sunspec Id:  1  Label:  Common
        Manufacturer (Mn)                                  SolarEdge
        Model (Md)                                             SE3500
        Version (Vr)                                        0003.2186
        Serial Number (SN)                                   1234ABCDE
        Device Address (DA)                                         1

Name:  inverter         Sunspec Id:  101        Label:  Inverter (Single Phase)
        Amps (A)                                                  0.0 A
        Amps PhaseA (AphA)                                        0.0 A
        Phase Voltage AB (PPVphAB)                              232.7 V
        Watts (W)                                                   0 W
        Hz (Hz)                                                 49.98 Hz
        VA (VA)                                                     0 VA
        VAr (VAr)                                                   0 var
        PF (PF)                                                 100.0 Pct
        WattHours (WH)                                        7020349 Wh
        DC Amps (DCA)                                               0 A
        DC Voltage (DCV)                                          0.5 V
        DC Watts (DCW)                                              0 W
        Heat Sink Temperature (TmpSnk)                          32.26 C
        Operating State (St)                                 Sleeping
        Vendor Operating State (StVnd)                              0
        Vendor Event Bitfield 1 (EvtVnd1)                           1
        Vendor Event Bitfield 4 (EvtVnd4)                           0


Re: SolarEdge via LAN interface

Posted: Thursday 17 October 2019 13:28
by freijn
Very interesting indeed. Will try to install as well and perhaps optimize the script in order to sent the sensor info to Domoticz.

Thanks!