GoodWe Solar: get data from the new semsportal (lua script)

Moderator: leecollings

pvdgulik
Posts: 21
Joined: Friday 28 December 2018 20:23
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.1
Contact:

Re: GoodWe Solar: get data from the new semsportal (lua script)

Post by pvdgulik »

I added in the calculation script the following, which takes the W from the

After reading out the powergeneration out of the device in:
PowerGeneration, EnergyGeneration = otherdevices_svalues[GenerationDeviceName]:match("([^;]+);([^;]+)")
Add:
PowerGeneration=PowerGeneration:sub(0,-2)
This resolved the problem for me.
uermend
Posts: 5
Joined: Monday 11 February 2019 11:10
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10055
Contact:

Re: GoodWe Solar: get data from the new semsportal (lua script)

Post by uermend »

hi,

I have updated the script to get output power, temperature of the inverter, output voltage, output current etc.
------------------------------------------------------------------------------------------------
output_power = getValue(splitString, "output_power")
last_refresh_time = getValue(splitString, "last_refresh_time")
eDay = getValue(splitString, "eDay")
work_mode = getValue(splitString, "work_mode")
temperature = getValue(splitString, "tempperature")
stroom = getValue(splitString, "output_current")
spanning = getValue(splitString, "output_voltage")

print("last_refresh_time :" .. last_refresh_time)
print("output_power :" .. output_power)
print("eDay :" .. eDay)
print("work_mode :" .. work_mode)
print("temperature :" .. temperature)
print("stroom :" ..stroom)
print("spanning :" ..spanning)


current = tonumber(stripchars(output_power, "pv:(W)"))
dayTotal = tonumber(stripchars(eDay, "sum:"))*1000
temp = tonumber(temperature)

UpdateDevice(sensorSolarPanels, current..";"..dayTotal)
------------------------------------------------------------------------------------------------
I see these vallues in the log but I do not get them into Domoticz.

I think I have to change the UpdateDevice commands and cannot get it working.

can someone help me with this?

Regards,

Sander

I'm running Domoticz V4.10055 in a docker image on Raspi3
sandeman684
Posts: 14
Joined: Sunday 08 January 2017 10:37
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: GoodWe Solar: get data from the new semsportal (lua script)

Post by sandeman684 »

It seems GoodWe has (again) changed something but, at least for me, the script is no longer working. Instead of the JSON data, I now get the HTML of the login page. Anybody any ideas on how to fix this?
User avatar
supergroover
Posts: 23
Joined: Friday 12 July 2013 19:37
Target OS: Linux
Domoticz version: Beta
Location: The Netherlands
Contact:

Re: GoodWe Solar: get data from the new semsportal (lua script)

Post by supergroover »

sandeman684 wrote: Friday 15 November 2019 8:46 It seems GoodWe has (again) changed something but, at least for me, the script is no longer working. Instead of the JSON data, I now get the HTML of the login page. Anybody any ideas on how to fix this?
I'm using the PHP version from @sinze and this no longer works for me either.
Rensticar
Posts: 2
Joined: Wednesday 30 November 2016 18:52
Target OS: Raspberry Pi / ODroid
Domoticz version: Stable
Location: NL
Contact:

Re: GoodWe Solar: get data from the new semsportal (lua script)

Post by Rensticar »

sandeman684 wrote: Friday 15 November 2019 8:46 It seems GoodWe has (again) changed something but, at least for me, the script is no longer working. Instead of the JSON data, I now get the HTML of the login page. Anybody any ideas on how to fix this?
Same problem since wednesday 13 november 2:45
bldewit
Posts: 59
Joined: Tuesday 09 May 2017 23:31
Target OS: Raspberry Pi / ODroid
Domoticz version: Stable
Location: NL
Contact:

Re: GoodWe Solar: get data from the new semsportal (lua script)

Post by bldewit »

Same here, nov.13.....
-‐----------------------------------------------------------
Running on rPi 3b (main) and rPi 2b (somfy), both RFLink
IthoRemote, Xiaomi Gateway, KAKU
sjoemie1985
Posts: 27
Joined: Thursday 26 September 2019 10:18
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: GoodWe Solar: get data from the new semsportal (lua script)

Post by sjoemie1985 »

i have also some problem i think.
i see the following error in my domoticz system, any one who knows how to solve it.
or has this also to do with the problems you all got?

2019-12-03 10:49:44.809 Error: (Semsportal): Async Secure Read Exception: 1, stream truncated
CrazyFrog
Posts: 21
Joined: Sunday 21 April 2019 13:39
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: GoodWe Solar: get data from the new semsportal (lua script)

Post by CrazyFrog »

Sorry I've been very busy for a while.

I picked up this issue again today and expect next week
post a new working script here.

At this moment I already have extract the data from the site, now I just have to strip it and pass it on to domoticz.

Just be patient
CrazyFrog
Posts: 21
Joined: Sunday 21 April 2019 13:39
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: GoodWe Solar: get data from the new semsportal (lua script)

Post by CrazyFrog »

sandeman684, supergroover, Rensticar, bldewit, sjoemie1985

hereby a new script.

Code: Select all

-- Created by Raymond Wiertz
-- DateTime: 2020-02-13

-- Tracking your token
-- To find out your token, you must execute the CURL command below from the command line.
-- curl -d 'account=[LOGINNAME]&pwd=[PASSWORD]&code=' https://www.semsportal.com/Home/Login;

local UserName = ""
local Password = ""
local token = ""

local refresh_time = 180 -- secondens
local sensorSolarPanels = "solar panels" -- name of your 

-- get login token
local loginCommand = string.format("curl --silent --output /dev/null --cookie-jar - -c cookie.txt -d 'account=%s&pwd=%s&code=' https://www.semsportal.com/Home/Login",UserName,Password)
-- get data from site
local getDataCommand = string.format("curl -b cookie.txt -d 'str={\"api\":\"v1/PowerStation/GetMonitorDetailByPowerstationId\",\"param\":{\"powerStationId\":\"%s\"}}&s=v1/PowerStation/GetMonitorDetailByPowerstationId' 'https://www.semsportal.com//GopsApi/Post?s=v1/PowerStation/GetMonitorDetailByPowerstationId'",token)

commandArray = {}
i=1

function isempty(s)
  return s == nil or s == ''
end

function getExecuteCommand(command)
  local f = assert(io.popen(command, 'r'))
  s = assert(f:read('*a'))
  f:close()
  return s
end

function stripchars(str, chrs)
    local s = str:gsub("["..chrs:gsub("%W","%%%1").."]", '')
    return s
end

function getValue(value, searchString)
   local response = ""

   searchString = string.format("%q", searchString)
   dummy, startPos = string.find(value, searchString )
   if not(startPos == nil) then
      dummy, startPos = string.find(value, searchString )
      dummy, endPos = string.find(value, ",", startPos)
      response = string.sub(value, startPos, endPos-1)
      response = string.gsub(response, ":", "")
      response = string.gsub(response, "\"", "")
      response = string.gsub(response, " ", "")
   end

   return response
end


function timedifference(s)
    year    = string.sub(s, 1, 4)
    month   = string.sub(s, 6, 7)
    day     = string.sub(s, 9, 10)
    hour    = string.sub(s, 12, 13)
    minutes = string.sub(s, 15, 16)
    seconds = string.sub(s, 18, 19)

    t1 = os.time()
    t2 = os.time{year=year, month=month, day=day, hour=hour, min=minutes,sec=seconds}
    difference = os.difftime (t1, t2)
    return difference
end


function UpdateDevice(device, data)
    idx = otherdevices_idx[device]
    if (idx == nil) then
        print('** Unknown device'..device)
    else
        commandArray[i] = {['UpdateDevice'] = idx..'|0|'..data}
        i = i+1
    end
end

difference = timedifference(otherdevices_lastupdate[sensorSolarPanels])

if (difference > refresh_time) then

    getExecuteCommand(loginCommand)
    local data = getExecuteCommand(getDataCommand)

--print(data)

    if (isempty(data) == false) then
        output_power = getValue(data, "output_power")
        last_refresh_time = getValue(data, "last_refresh_time")
        eDay = getValue(data, "eDay")

        print("last_refresh_time :" .. last_refresh_time)
        print("output_power :" .. output_power)
        print("eDay :" .. eDay)

        current = tonumber(stripchars(output_power, "kwhKWH"))
        dayTotal = tonumber(eDay)*1000

        UpdateDevice(sensorSolarPanels, current..";"..dayTotal)
    end
end

return commandArray

hopefully the script will continue to work in the near future.

Have fun with it.
Last edited by CrazyFrog on Monday 24 February 2020 12:15, edited 1 time in total.
sandeman684
Posts: 14
Joined: Sunday 08 January 2017 10:37
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: GoodWe Solar: get data from the new semsportal (lua script)

Post by sandeman684 »

CrazyFrog wrote: Thursday 20 February 2020 22:51 sandeman684, supergroover, Rensticar, bldewit, sjoemie1985

hereby a new script.

hopefully the script will continue to work in the near future.

Have fun with it.
Thanks a lot.
I had to add i=1 to get it working, but now it works fine.
CrazyFrog
Posts: 21
Joined: Sunday 21 April 2019 13:39
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: GoodWe Solar: get data from the new semsportal (lua script)

Post by CrazyFrog »

sandeman684 wrote: Saturday 22 February 2020 16:49
CrazyFrog wrote: Thursday 20 February 2020 22:51 sandeman684, supergroover, Rensticar, bldewit, sjoemie1985

hereby a new script.

hopefully the script will continue to work in the near future.

Have fun with it.
Thanks a lot.
I had to add i=1 to get it working, but now it works fine.

Hello sandeman684

why did you have to put this variable, the code does not use this variable?
Could you indicate where you have placed this declaration so that other users can take it over when referenced.

Thank you in advance for the information.
sandeman684
Posts: 14
Joined: Sunday 08 January 2017 10:37
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: GoodWe Solar: get data from the new semsportal (lua script)

Post by sandeman684 »

CrazyFrog wrote: Monday 24 February 2020 9:27
sandeman684 wrote: Saturday 22 February 2020 16:49 I had to add i=1 to get it working, but now it works fine.
why did you have to put this variable, the code does not use this variable?
Could you indicate where you have placed this declaration so that other users can take it over when referenced.

Thank you in advance for the information.
I got an error at the following line:

Code: Select all

commandArray[i] = {['UpdateDevice'] = idx..'|0|'..data}
Adding i=1 here:

Code: Select all

commandArray = {}
i=1
solved this.
CrazyFrog
Posts: 21
Joined: Sunday 21 April 2019 13:39
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: GoodWe Solar: get data from the new semsportal (lua script)

Post by CrazyFrog »

sandeman684 wrote: Monday 24 February 2020 9:50
CrazyFrog wrote: Monday 24 February 2020 9:27
sandeman684 wrote: Saturday 22 February 2020 16:49 I had to add i=1 to get it working, but now it works fine.
why did you have to put this variable, the code does not use this variable?
Could you indicate where you have placed this declaration so that other users can take it over when referenced.

Thank you in advance for the information.
I got an error at the following line:

Code: Select all

commandArray[i] = {['UpdateDevice'] = idx..'|0|'..data}
Adding i=1 here:

Code: Select all

commandArray = {}
i=1
solved this.
:D tx.

oops forgotten with copy-past :?
I have update the code above.
Gruzi
Posts: 5
Joined: Friday 28 February 2020 9:06
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: GoodWe Solar: get data from the new semsportal (lua script)

Post by Gruzi »

Thanks for the script CrazyFrog, if functions well overhere!

However, it causes an error in my log file about one time per hour:

2020-02-28 07:35:10.354 Error: EventSystem: Warning!, lua script SolarPanels has been running for more than 10 seconds

Is there a way to increase the timer for script?
CrazyFrog
Posts: 21
Joined: Sunday 21 April 2019 13:39
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: GoodWe Solar: get data from the new semsportal (lua script)

Post by CrazyFrog »

yes you can, but with an update it is set back to 10 seconds
sandeman684
Posts: 14
Joined: Sunday 08 January 2017 10:37
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: GoodWe Solar: get data from the new semsportal (lua script)

Post by sandeman684 »

It seems there is still an issue with the daily production. Very often a value is used for two consecutive days, as you can see in the image. The correct values should be:
Tue 7.2
Wed 2.4
Thu 1.7
Fri 6.2
Sat 5.6
Sun 6.4
Mon 2.7
Tue 0.3
So, often the value of the previous day is used, but not always.
EDIT: it seems like the previous day is used when its value is larger than the current day value.
Image
Attachments
last-week.png
last-week.png (57.46 KiB) Viewed 2939 times
Gruzi
Posts: 5
Joined: Friday 28 February 2020 9:06
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: GoodWe Solar: get data from the new semsportal (lua script)

Post by Gruzi »

Same behaviour here.

Values should be (checked on Sems portal) :
Wed - 5.8
Thu - 2.4
Fri - 8.6
Sat - 9
Sun - 13.2
Mon - 4.5
Tue - 20.5

It is also remarkable that today Wed is already filled in with 20.5

panel.jpg
panel.jpg (32.03 KiB) Viewed 2925 times
Gruzi
Posts: 5
Joined: Friday 28 February 2020 9:06
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: GoodWe Solar: get data from the new semsportal (lua script)

Post by Gruzi »

@CrazyFrog @Sandeman684

I investigated further and I think that the problem Sandeman684 and I have is not caused by the script from Crazyfrog.
The script is giving Domoticz the right values for Power and Energy (I created logfiles over the day) but Domoticz doesn't process them well.
This seems a more common problem from the sensor Electric (Instant and Counter) and I found another post on the forum where I have reported this.

See my post:
https://www.domoticz.com/forum/viewtopi ... 73#p241673
Trigun
Posts: 390
Joined: Wednesday 30 November 2016 11:58
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10717
Contact:

Re: GoodWe Solar: get data from the new semsportal (lua script)

Post by Trigun »

Hi Sincze,

I used your PHP script but I am getting a fatal Curl error which leaves the output.errors blank and also No feedback in the domoticz log.

this is the output:

Code: Select all

PHP Fatal error:  Uncaught Error: Call to undefined function curl_init() in /home/pi/domoticz/scripts/pass2php/goodwe-inverter.php:66
Stack trace:
#0 /home/pi/domoticz/scripts/pass2php/goodwe-inverter.php(40): retrieve_goodwe_data('test')
#1 {main}
  thrown in /home/pi/domoticz/scripts/pass2php/goodwe-inverter.php on line 66

Fatal error: Uncaught Error: Call to undefined function curl_init() in /home/pi/domoticz/scripts/pass2php/goodwe-inverter.php:66
Stack trace:
#0 /home/pi/domoticz/scripts/pass2php/goodwe-inverter.php(40): retrieve_goodwe_data('test')
#1 {main}
  thrown in /home/pi/domoticz/scripts/pass2php/goodwe-inverter.php on line 66/code]
  
  just the be sure:
  entering my username and password, is the actual Semsportal login, correct?
  
 thnx in advance!
hvolkers
Posts: 1
Joined: Saturday 14 March 2020 22:12
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: GoodWe Solar: get data from the new semsportal (lua script)

Post by hvolkers »

hi

i tried to use the LUA scripts (2 versions) but both do not work

first of all the request to get the TOKEN must be wrong as I got back "0" as an answer on two different accounts within the Semsportal

where is the token used for?

the LUA script is giving errors while checking under raspbian os

Lua 5.1.5 Copyright (C) 1994-2012 Lua.org, PUC-Rio
lua: script_device_SEMS Portal.lua:82: attempt to index global 'otherdevices_lastupdate' (a nil value)
stack traceback:
script_device_SEMS Portal.lua:82: in main chunk
[C]: ?

who is able to help me out?

kind regards

Henri
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest