After reading out the powergeneration out of the device in:
Add:PowerGeneration, EnergyGeneration = otherdevices_svalues[GenerationDeviceName]:match("([^;]+);([^;]+)")
This resolved the problem for me.PowerGeneration=PowerGeneration:sub(0,-2)
Moderator: leecollings
Add:PowerGeneration, EnergyGeneration = otherdevices_svalues[GenerationDeviceName]:match("([^;]+);([^;]+)")
This resolved the problem for me.PowerGeneration=PowerGeneration:sub(0,-2)
I'm using the PHP version from @sinze and this no longer works for me either.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:45sandeman684 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?
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
sandeman684 wrote: ↑Saturday 22 February 2020 16:49Thanks a lot.
I had to add i=1 to get it working, but now it works fine.
I got an error at the following line:CrazyFrog wrote: ↑Monday 24 February 2020 9:27why did you have to put this variable, the code does not use this variable?sandeman684 wrote: ↑Saturday 22 February 2020 16:49 I had to add i=1 to get it working, but now it works fine.
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.
Code: Select all
commandArray[i] = {['UpdateDevice'] = idx..'|0|'..data}
Code: Select all
commandArray = {}
i=1
tx.sandeman684 wrote: ↑Monday 24 February 2020 9:50I got an error at the following line:CrazyFrog wrote: ↑Monday 24 February 2020 9:27why did you have to put this variable, the code does not use this variable?sandeman684 wrote: ↑Saturday 22 February 2020 16:49 I had to add i=1 to get it working, but now it works fine.
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.Adding i=1 here:Code: Select all
commandArray[i] = {['UpdateDevice'] = idx..'|0|'..data}
solved this.Code: Select all
commandArray = {} i=1
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!
Users browsing this forum: No registered users and 1 guest