Python SolarEdge modbus script via lan

Python and python framework

Moderator: leecollings

User avatar
jvdz
Posts: 2189
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: Python SolarEdge modbus script via lan

Post by jvdz »

I have this which does work for me: ( different first line)

Code: Select all

##!/bin/bash
sunspec_ardexa discover 192.168.0.18 1 > /var/tmp/sunspec.log 2>/var/tmp/sunspec-err.log
Jos
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
freijn
Posts: 536
Joined: Friday 23 December 2016 16:40
Target OS: Raspberry Pi / ODroid
Domoticz version: Stable
Location: Netherlands Purmerend
Contact:

Re: Python SolarEdge modbus script via lan

Post by freijn »

Many thanks guys !!!

I have update the inital post with your suggestions.

Besides the crontab..
I fire the script on the update event of my P1. In that same script I collect my Solar and then substract of add the values in order
to calculate the house power consumption.

If you are interested I can share my messy lua script..... :-)
Piacco
Posts: 69
Joined: Friday 14 November 2014 9:33
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python SolarEdge modbus script via lan

Post by Piacco »

Its working :D

Thanks everybody for your help.

The problem was a wrong path in the crontab this must be:
/usr/local/bin/sunspec_ardexa discover

Thanks
Piacco
Piacco
Posts: 69
Joined: Friday 14 November 2014 9:33
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python SolarEdge modbus script via lan

Post by Piacco »

freijn wrote: Thursday 27 February 2020 19:39 Many thanks guys !!!

I have update the inital post with your suggestions.

Besides the crontab..
I fire the script on the update event of my P1. In that same script I collect my Solar and then substract of add the values in order
to calculate the house power consumption.

If you are interested I can share my messy lua script..... :-)
I'm always interested in a nice script :D
telewy
Posts: 3
Joined: Tuesday 10 January 2017 13:52
Target OS: Linux
Domoticz version:
Location: Poland
Contact:

Re: Python SolarEdge modbus script via lan

Post by telewy »

Hi,

I have just finished and everything works nice.

My cron looks like:
*/1 * * * * /usr/local/bin/sunspec_ardexa discover x.y.z.v 1 --port 1502

Thanks guys for sharing scripts and knowledge. Great work :)

Cheers
gehoel
Posts: 9
Joined: Thursday 05 March 2020 19:45
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: Netherlands
Contact:

Re: Python SolarEdge modbus script via lan

Post by gehoel »

Hello Together,

I find this an interesting topic.
My end goal is to activate Equipment in my home when my Solar production is positive.
So that I don't have to deliver power to the grid.

I have everything working with the script.
When I try this command: sunspec_ardexa -vv discover xxx.xxx.xxx.xxx 1 is giving me al the data from my inverter.

The part I'm missing is how to get the Items in my devices in Domoticz.
Could somebody explain me.

Greetings,
Bart
freijn
Posts: 536
Joined: Friday 23 December 2016 16:40
Target OS: Raspberry Pi / ODroid
Domoticz version: Stable
Location: Netherlands Purmerend
Contact:

Re: Python SolarEdge modbus script via lan

Post by freijn »

Hey Gehoel,

Have you installed domo.ini as well ?
( please see description in first post )

Then change the line :

Watts:0 ; Watts inverter Make the 0 the number of the IDX you are using for your sensor.

Now execute :

sunspec_ardexa discover xxx.xxx.xxx.xxx 1 <<<< without the -vv

and your sensor with the defined IDX should get updated with the production watts of your Solar system.

You can put sunspec_ardexa discover xxx.xxx.xxx.xxx 1 in a crontab or do like me.. Fire it when the P1 transmits new data.

Please let me understand where you are lost..... :-)

If that is working you can start writing scripts to act on and off..

Cheers,

Frank
gehoel
Posts: 9
Joined: Thursday 05 March 2020 19:45
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: Netherlands
Contact:

Re: Python SolarEdge modbus script via lan

Post by gehoel »

Hello Frank,

I have figured it out.
The part is was missing in your explanation is that I first have to make Virtual Sensors in Domoticz.
After making an Dummy type I was able to add the sensors and then the IDX numbers from Domoticz.

greetings,
Bart
freijn
Posts: 536
Joined: Friday 23 December 2016 16:40
Target OS: Raspberry Pi / ODroid
Domoticz version: Stable
Location: Netherlands Purmerend
Contact:

Re: Python SolarEdge modbus script via lan

Post by freijn »

gehoel wrote: Thursday 05 March 2020 21:32 Hello Frank,

I have figured it out.
The part is was missing in your explanation is that I first have to make Virtual Sensors in Domoticz.
After making an Dummy type I was able to add the sensors and then the IDX numbers from Domoticz.

greetings,
Bart
Bart,

Point taken and I wrote two lines in the first post about it. Thanks for the reply !
Piacco
Posts: 69
Joined: Friday 14 November 2014 9:33
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python SolarEdge modbus script via lan

Post by Piacco »

freijn wrote: Thursday 27 February 2020 19:39 Many thanks guys !!!

I have update the inital post with your suggestions.

Besides the crontab..
I fire the script on the update event of my P1. In that same script I collect my Solar and then substract of add the values in order
to calculate the house power consumption.

If you are interested I can share my messy lua script..... :-)
Hello Frank,

I'm very interested about your P1 lua script which trigger the sunspec script, is it possible that you share it with us?

Greets,

Piacco
freijn
Posts: 536
Joined: Friday 23 December 2016 16:40
Target OS: Raspberry Pi / ODroid
Domoticz version: Stable
Location: Netherlands Purmerend
Contact:

Re: Python SolarEdge modbus script via lan

Post by freijn »

Hi Piacco

Not my cleanest script, but should you het going.

Mind the sensors I have used ( you need to change the names !! for your environment )

- powersensor = "Power" << my P1 interface sensor

- solarsensor = "SolarEdge Power Kwh" << The Solar system watt report sensor

- ttidx = otherdevices_idx['PowerConsumption'] << My house consumption sensor

When you deploy it, switch Debug="YES" to see reading results from the script in the logfile.
If all is working , switch to NO.

Needless to mention but you need Solar to see the scrip in action :-)
Let me know if you have questions or troubles....

Code: Select all

----------------------------------------------------------------------------------------------------------
-- Script parameters
----------------------------------------------------------------------------------------------------------
Debug = "NO"                    -- Turn debugging on ("YES") or off ("NO")
----------------------------------------------------------------------------------------------------------
-- Grid Power calculation    GridPower - Solar Power  and store in Sensor
----------------------------------------------------------------------------------------------------------
local solarflag
local var5
local var6
local powercount
local consume
local oldpowerconsume

commandArray = {}

powersensor = "Power"
if (devicechanged[powersensor]) then
    
    if Debug=="YES" then
        print( " ####Power debug device changed: "..devicechanged[powersensor])
    end
    #zon_success=os.execute("sudo /usr/bin/perl /home/pi/sunspec-monitor-master/domosun.pl -z -m 0 -p 502 192.168.1.140 &")
    zon_success=os.execute("sudo /usr/local/bin/sunspec_ardexa discover 192.168.1.140 1 > /dev/null 2>&1 &")
	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
        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

   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
  
  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

 ttidx = otherdevices_idx['PowerConsumption']
 commandArray['UpdateDevice'] = ttidx..'|0|'..consume
 

end 
 
return commandArray
User avatar
jvdz
Posts: 2189
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: Python SolarEdge modbus script via lan

Post by jvdz »

@freijn,

You do realize that you are calculating consume with the Solarvar1 value of the previous run and not the just shelled sunspec_ardexa command? ;)

Jos
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
gehoel
Posts: 9
Joined: Thursday 05 March 2020 19:45
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: Netherlands
Contact:

Re: Python SolarEdge modbus script via lan

Post by gehoel »

Hello,

I have got one problem.
My Watts don't show up in Domoticz.

My ini file looks like:

;The idx numbers of the sensors made in Domoticz
;if idx is set to 0 (zero) it will be ignored
[domoidx]
Amps:40 ; Amps (A) Total Amps
AphA:0 ; Amps PhaseA inverter
AphB:0 ; Amps PhaseB inverter
AphC:0 ; Amps PhaseC inverter
PPVphAB:0 ; Phase Voltage AB inverter
PPVphBC:0 ; Phase Voltage BC inverter
PPVphCA:0 ; Phase Voltage CA inverter
PhVphA:0 ; Phase Voltage AN grid
PhVphB:0 ; Phase Voltage BN grid
PhVphC:0 ; Phase Voltage CN grid
Watts:44 ; Watts inverter
Hz:0 ; Hz Grid
VA:0 ; VA
VAr:0 ; VAr
PF:0 ; Percent
WH:41 ; WattHours (WH)
DCA:0 ; DC Amps
DCV:39 ; DC Voltage
TmpSnk:43 ; Heat Sink Temperature
St:37 ; Operating State

Out come of the script sunspec_ardexa -vv discover 192.168.xx.xxx 1

Amps (A) 11.35 A
Amps PhaseA (AphA) 3.79 A
Amps PhaseB (AphB) 3.76 A
Amps PhaseC (AphC) 3.78 A
Phase Voltage AB (PPVphAB) 399.1 V
Phase Voltage BC (PPVphBC) 399.5 V
Phase Voltage CA (PPVphCA) 399.0 V
Phase Voltage AN (PhVphA) 229.7 V
Phase Voltage BN (PhVphB) 231.1 V
Phase Voltage CN (PhVphC) 230.8 V
Watts (W) 2609.0 W
Hz (Hz) 50.01 Hz
VA (VA) 2619.9 VA
VAr (VAr) -239.0 var
PF (PF) -99.57 Pct
WattHours (WH) 10581497 Wh
DC Amps (DCA) 3.542 A
DC Voltage (DCV) 747.6 V
DC Watts (DCW) 2648.7 W
Heat Sink Temperature (TmpSnk) 30.08 C
Operating State (St) MPPT
Vendor Operating State (StVnd) 0
Vendor Event Bitfield 1 (EvtVnd1) 1
Vendor Event Bitfield 4 (EvtVnd4) 0

So there is production.
But in Domoticz it looks like:
Attachments
screenshot.jpg
screenshot.jpg (132.01 KiB) Viewed 1143 times
Greetings,
Bart
User avatar
jvdz
Posts: 2189
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: Python SolarEdge modbus script via lan

Post by jvdz »

If you are using the last version of the script, which contains the changes I made to my version posted earlier, you don't need a seperate device for W as that is part of the WH device now, since that can/should display both when using the proper dummy device.
Maybe that should be documented as such somewhere.

check this link for the details: https://www.domoticz.com/forum/viewtopi ... 55#p238031

Jos
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
freijn
Posts: 536
Joined: Friday 23 December 2016 16:40
Target OS: Raspberry Pi / ODroid
Domoticz version: Stable
Location: Netherlands Purmerend
Contact:

Re: Python SolarEdge modbus script via lan

Post by freijn »

jvdz wrote: Saturday 07 March 2020 10:22 @freijn,

You do realize that you are calculating consume with the Solarvar1 value of the previous run and not the just shelled sunspec_ardexa command? ;)

Jos
Hi Jos,

Honestly, no ! never realized that. :-(

So .... workaround would be , return values of the ardexa command ? Or do you have a better suggestion?
Would a "return commandArray" in between do the job ?
freijn
Posts: 536
Joined: Friday 23 December 2016 16:40
Target OS: Raspberry Pi / ODroid
Domoticz version: Stable
Location: Netherlands Purmerend
Contact:

Re: Python SolarEdge modbus script via lan

Post by freijn »

jvdz wrote: Saturday 07 March 2020 10:45 you don't need a seperate device for W as that is part of the WH device now,

Jos
Jos, have you played with the json create sensor already ?

like : /json.htm?type=createvirtualsensor&idx=29&sensorname=Energy&sensortype=90

I am thinking , creating a python which creates all sensors required...
User avatar
jvdz
Posts: 2189
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: Python SolarEdge modbus script via lan

Post by jvdz »

There is no easy solution because this command shells another task in the OS:

Code: Select all

zon_success=os.execute("sudo /usr/local/bin/sunspec_ardexa discover 192.168.1.140 1 > /dev/null 2>&1 &")
.. and you specified " &" at the end which means that you are not waiting for that task to finish and immediately returns to the script to continue processing. The sunspec_ardexa command will take several seconds to finish, but even when that would not be the case, the otherdevices_svalues[solarsensor] table values are filled at the time this script is started by the event system so will never contain any updates even when you wait for it!

Jos
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
freijn
Posts: 536
Joined: Friday 23 December 2016 16:40
Target OS: Raspberry Pi / ODroid
Domoticz version: Stable
Location: Netherlands Purmerend
Contact:

Re: Python SolarEdge modbus script via lan

Post by freijn »

jvdz wrote: Saturday 07 March 2020 14:55 even when you wait for it!
And what about this? :

In the (python) ardexa script do a json call to the "P1 power" sernsor , grab that info, do the calculation and store it in "consume" sensor with again a json call?

Dirty but.. would that give a better result you think?
User avatar
jvdz
Posts: 2189
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: Python SolarEdge modbus script via lan

Post by jvdz »

That works too, but is still not the exact P1 value at time of calculation. ;)
I guess it all depends on the frequency both the P1 device and the Solar Production data is updated, but there will always be a (little) discrepancy in the time for the values. Just try to make it as short as possible, but it really is only a cosmetics thing as the Total of the counters will always catch up eventually.

Jos
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
freijn
Posts: 536
Joined: Friday 23 December 2016 16:40
Target OS: Raspberry Pi / ODroid
Domoticz version: Stable
Location: Netherlands Purmerend
Contact:

Re: Python SolarEdge modbus script via lan

Post by freijn »

Jos,

its all in a 2 sec timeframe but what about this :
  • P1 sends an update
    On the P1 update I do collect the solar numbers
    At the end of the solar script, a python shell is started in the background.
    Python waits 1 sec ( in the background )
    Python grabs json call's the P1 data and the Solar data
    Python updates the House consume sensor.
I know
"3 traps raket"
but would this get closer to calculate values you think?

Cheers,

Frank
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest