Page 5 of 6

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

Posted: Sunday 13 October 2019 14:03
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.

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

Posted: Friday 08 November 2019 9:57
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

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

Posted: Friday 15 November 2019 8:46
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?

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

Posted: Friday 15 November 2019 12:03
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.

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

Posted: Monday 18 November 2019 19:44
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

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

Posted: Wednesday 27 November 2019 19:59
by bldewit
Same here, nov.13.....

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

Posted: Tuesday 03 December 2019 11:05
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

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

Posted: Tuesday 11 February 2020 22:59
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

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

Posted: Thursday 20 February 2020 22:51
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.

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

Posted: Saturday 22 February 2020 16:49
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.

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

Posted: Monday 24 February 2020 9:27
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.

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

Posted: Monday 24 February 2020 9:50
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.

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

Posted: Monday 24 February 2020 12:17
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.

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

Posted: Friday 28 February 2020 9:16
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?

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

Posted: Sunday 01 March 2020 1:20
by CrazyFrog
yes you can, but with an update it is set back to 10 seconds

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

Posted: Tuesday 03 March 2020 8:47
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

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

Posted: Wednesday 04 March 2020 10:53
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 2930 times

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

Posted: Tuesday 31 March 2020 21:35
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

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

Posted: Thursday 09 April 2020 12:58
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!

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

Posted: Thursday 30 April 2020 14:43
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