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

Moderator: leecollings

Peter2807
Posts: 8
Joined: Tuesday 30 July 2019 23:01
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

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

Post by Peter2807 »

Thanks hoping to get this to work though (steep learning curve for me), got the first 120 lines working now, don't ask me how. but am now stuck at 121 in function getSessionID
Error: EventSystem: in anything: [string "-- Created by Raymond Wiertz..."]:121: bad argument #1 to 'sub' (string expected, got nil)

Errors are quite vague in my opinion, as in not clear as what to do to fix it.
Peter2807
Posts: 8
Joined: Tuesday 30 July 2019 23:01
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

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

Post by Peter2807 »

Peter2807 wrote: Wednesday 31 July 2019 16:00 Thanks hoping to get this to work though (steep learning curve for me), got the first 120 lines working now, don't ask me how. but am now stuck at 121 in function getSessionID
Error: EventSystem: in anything: [string "-- Created by Raymond Wiertz..."]:121: bad argument #1 to 'sub' (string expected, got nil)

Errors are quite vague in my opinion, as in not clear as what to do to fix it.
Lines 116 and 117 where commented out for some reason. no more errors but no data showing either. will continue to troubleshoot.
Peter2807
Posts: 8
Joined: Tuesday 30 July 2019 23:01
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

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

Post by Peter2807 »

Sincze, what pre-requisites besides php 7 are needed when running this script on a Synology? I''m getting a few warnings:

PHP Warning: Constants may only evaluate to scalar values in /volume1/@appstore/domoticz/var/scripts/pass2php/Goodwe.php on line 56

Warning: Constants may only evaluate to scalar values in /volume1/@appstore/domoticz/var/scripts/pass2php/Goodwe.php on line 56
PHP Warning: Constants may only evaluate to scalar values in /volume1/@appstore/domoticz/var/scripts/pass2php/Goodwe.php on line 63

Warning: Constants may only evaluate to scalar values in /volume1/@appstore/domoticz/var/scripts/pass2php/Goodwe.php on line 63
PHP Notice: Use of undefined constant LOGINHEADER - assumed 'LOGINHEADER' in /volume1/@appstore/domoticz/var/scripts/pass2php/Goodwe.php on line 84

Notice: Use of undefined constant LOGINHEADER - assumed 'LOGINHEADER' in /volume1/@appstore/domoticz/var/scripts/pass2php/Goodwe.php on line 84
PHP Warning: curl_setopt(): You must pass either an object or an array with the CURLOPT_HTTPHEADER argument in /volume1/@appstore/domoticz/var/scripts/pass2php/Goodwe.php on line 84

Warning: curl_setopt(): You must pass either an object or an array with the CURLOPT_HTTPHEADER argument in /volume1/@appstore/domoticz/var/scripts/pass2php/Goodwe.php on line 84
dospider
Posts: 15
Joined: Monday 04 August 2014 18:43
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Netherlands
Contact:

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

Post by dospider »

Scripts is woking fine for a while. Then i had some troubles with my router. That is fixed, but i think i have since that time an error:
Error: EventSystem: in Goodwe portal: [string "-- Note: The GoodWe data is refreshed every 6..."]:116: attempt to perform arithmetic on a nil value
on line 116 the code is dayTotal = tonumber(eDay)*1000


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

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

Anyone an idea why i get this message.

voltage and current are updated.
User avatar
sincze
Posts: 1299
Joined: Monday 02 June 2014 22:46
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.4
Location: Netherlands / Breda Area
Contact:

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

Post by sincze »

Peter2807 wrote: Wednesday 31 July 2019 23:42 Sincze, what pre-requisites besides php 7 are needed when running this script on a Synology? I''m getting a few warnings:
Hi Peter.

Please try latest version here: https://github.com/sincze/Domoticz/blob ... Goodwe.php
Checked on my DS412 ;-)
Pass2php
LAN: RFLink, P1, OTGW, MySensors
USB: RFXCom, ZWave, Sonoff 3
MQTT: ZIgbee2MQTT,
ZWAVE: Zwave-JS-UI
WIFI: Mi-light, Tasmota, Xiaomi Shelly
Solar: Omnik, PVOutput
Video: Kodi, Harmony HUB, Chromecast
Sensors: You name it I got 1.
Peter2807
Posts: 8
Joined: Tuesday 30 July 2019 23:01
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

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

Post by Peter2807 »

sincze wrote: Thursday 01 August 2019 18:21
Peter2807 wrote: Wednesday 31 July 2019 23:42 Sincze, what pre-requisites besides php 7 are needed when running this script on a Synology? I''m getting a few warnings:
Hi Peter.

Please try latest version here: https://github.com/sincze/Domoticz/blob ... Goodwe.php
Checked on my DS412 ;-)
Sincze, I downloaded and modified the script, deleted old sensors and created new ones just to be sure. No errors or warnings when executing the script however no data seems to be coming in, also nothing in the log indicating anything is running besides what was already running. Will investigate over the weekend. Thanks for now.
User avatar
sincze
Posts: 1299
Joined: Monday 02 June 2014 22:46
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.4
Location: Netherlands / Breda Area
Contact:

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

Post by sincze »

Please turn Debug On. :) Do it will show you the results in between is the cookie created?
Does it say cookie writable?
If not... You will see no data indeed and no errors.
Pass2php
LAN: RFLink, P1, OTGW, MySensors
USB: RFXCom, ZWave, Sonoff 3
MQTT: ZIgbee2MQTT,
ZWAVE: Zwave-JS-UI
WIFI: Mi-light, Tasmota, Xiaomi Shelly
Solar: Omnik, PVOutput
Video: Kodi, Harmony HUB, Chromecast
Sensors: You name it I got 1.
Peter2807
Posts: 8
Joined: Tuesday 30 July 2019 23:01
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

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

Post by Peter2807 »

sincze wrote: Friday 02 August 2019 8:00 Please turn Debug On. :) Do it will show you the results in between is the cookie created?
Does it say cookie writable?
If not... You will see no data indeed and no errors.
Cookie is writable, and changes every few minutes (new timestamp and inside a see a new session-ID)
Now trying to figure out how and where to turn on debugging

Been looking at the Pass2PhP sub-forum also, sofar not helpful looking in the wrong topics most likely.
User avatar
sincze
Posts: 1299
Joined: Monday 02 June 2014 22:46
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.4
Location: Netherlands / Breda Area
Contact:

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

Post by sincze »

It is the variable "debug" on top of the script.
So cookie is created. That is good.
Now look at the Domoticz logging for the debug lines.
We can add additional ones in the script is needed.
But first check what Domoticz log says.
Pass2php
LAN: RFLink, P1, OTGW, MySensors
USB: RFXCom, ZWave, Sonoff 3
MQTT: ZIgbee2MQTT,
ZWAVE: Zwave-JS-UI
WIFI: Mi-light, Tasmota, Xiaomi Shelly
Solar: Omnik, PVOutput
Video: Kodi, Harmony HUB, Chromecast
Sensors: You name it I got 1.
Peter2807
Posts: 8
Joined: Tuesday 30 July 2019 23:01
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

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

Post by Peter2807 »

Sincze,
For as far as I can see the script is running all the way to the end (without errors), I put some typo's in it to see what happened and sure I got syntax errors. It looks like it's working the only problem is I don't see any data being displayed.

It would be nice to see what the script is doing and where it's keeping the temporary data.

This is the log (removed some duplicate lines.)
  • 2019-08-02 19:26:27.061 Status: Domoticz V4.10717 (c)2012-2019 GizMoCuz
    2019-08-02 19:26:27.061 Status: Build Hash: b38b49e-modified, Date: 2019-05-09 13:04:08
    2019-08-02 19:26:27.061 Status: Startup Path: /usr/local/domoticz/
    2019-08-02 19:26:27.122 Status: PluginSystem: Started, Python version '3.5.1'.
    2019-08-02 19:26:27.127 Status: WebServer(HTTP) started on address: :: with port 8084
    2019-08-02 19:26:27.130 Status: WebServer(SSL) started on address: :: with port 8443
    2019-08-02 19:26:27.132 Status: TCPServer: shared server started...
    2019-08-02 19:26:27.132 Status: RxQueue: queue worker started...
    2019-08-02 19:26:29.133 Status: P1 Smart Meter: Using serial port: /dev/ttyUSB0
    2019-08-02 19:26:29.145 Status: P1 Smart Meter: Worker started...
    2019-08-02 19:26:29.145 Status: Panasonic Plugin: Started
    2019-08-02 19:26:29.145 Status: EventSystem: reset all events...
    2019-08-02 19:26:29.146 Status: EventSystem: reset all device statuses...
    2019-08-02 19:26:29.191 Status: Python EventSystem: Initalizing event module.
    2019-08-02 19:26:29.191 Status: EventSystem: Started
    2019-08-02 19:26:29.191 Status: EventSystem: Queue thread started...
    2019-08-02 19:26:29.245 Status: Panasonic Plugin: (Woonkamer) Starting thread.
    2019-08-02 19:26:29.246 Status: Panasonic Plugin: (Woonkamer) started.
    2019-08-02 19:26:29.575 Status: PluginSystem: Entering work loop.
    2019-08-02 19:26:37.284 Status: P1 Smart Meter: Meter reports as DSMR 4.2
    2019-08-02 19:26:37.694 Status: P1 Smart Meter: Found gas meter on M-Bus channel 1
    2019-08-02 20:00:00.337 Status: Starting automatic database backup procedure...
    2019-08-02 20:00:00.517 Status: Ending automatic database backup procedure...
    2019-08-02 23:00:00.954 Status: Starting automatic database backup procedure...
    2019-08-02 23:00:01.142 Status: Ending automatic database backup procedure...
    2019-08-03 00:00:00.926 Status: EventSystem: reset all events...
    2019-08-03 00:00:00.937 Status: Starting automatic database backup procedure...
    2019-08-03 00:00:01.521 Status: Ending automatic database backup procedure...
    2019-08-03 01:00:00.378 Status: Starting automatic database backup procedure...
    2019-08-03 12:36:22.906 Status: Incoming connection from: 192.168.1.101
    2019-08-03 12:43:39.129 Status: EventSystem: reset all device statuses...
    2019-08-03 13:00:00.674 Status: Starting automatic database backup procedure...
    2019-08-03 13:00:00.889 Status: Ending automatic database backup procedure...
    2019-08-03 13:12:48.422 Status: EventSystem: reset all device statuses...
    2019-08-03 13:14:25.005 Status: EventSystem: reset all device statuses...
    2019-08-03 13:20:47.969 (Slimme meter) P1 Smart Meter (Power)
    2019-08-03 13:20:47.969 (Slimme meter) Usage (Usage L1)
    2019-08-03 13:20:47.969 (Slimme meter) Usage (Delivery L1)
    2019-08-03 13:20:57.989 (Slimme meter) P1 Smart Meter (Power)
User avatar
sincze
Posts: 1299
Joined: Monday 02 June 2014 22:46
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.4
Location: Netherlands / Breda Area
Contact:

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

Post by sincze »

Do you have a username and password on your Domoticz ?
Did you double check the port 8084 on Synology Vs 8080 on a pi?
Are you allowed to make curl calls to Domoticz without username and password.

Change lg debug statements to echo and you should see it on your screen instead of Domoticz log
Pass2php
LAN: RFLink, P1, OTGW, MySensors
USB: RFXCom, ZWave, Sonoff 3
MQTT: ZIgbee2MQTT,
ZWAVE: Zwave-JS-UI
WIFI: Mi-light, Tasmota, Xiaomi Shelly
Solar: Omnik, PVOutput
Video: Kodi, Harmony HUB, Chromecast
Sensors: You name it I got 1.
Peter2807
Posts: 8
Joined: Tuesday 30 July 2019 23:01
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

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

Post by Peter2807 »

Changing lg to echo got me this:
Goodwe JSON results Found! Goodwe: 433 W, today: 2.6 kWh, Inverter total: 10352 kwH for domoticz: 433;10352000 (udevice) | 16 => 0,433;10352000
So it looks as the script is working, still no nice graph in Domoticz

Port 8080 is what needed to be changed to 8084, so finally I'm seeing something on my screen (to bad not much sun today)

Next thing on the nice to have list is a way to import all the old data (4 years) to be displayed. I know the data is available just not how to get it.

Sincze bedankt. (ie thanks for those not speaking dutch)
Attachments
generated-last-24-hours.jpeg
generated-last-24-hours.jpeg (43.1 KiB) Viewed 3143 times
User avatar
sincze
Posts: 1299
Joined: Monday 02 June 2014 22:46
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.4
Location: Netherlands / Breda Area
Contact:

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

Post by sincze »

Peter2807 wrote: Saturday 03 August 2019 15:26 Changing lg to echo got me this:
Goodwe JSON results Found! Goodwe: 433 W, today: 2.6 kWh, Inverter total: 10352 kwH for domoticz: 433;10352000 (udevice) | 16 => 0,433;10352000
So it looks as the script is working, still no nice graph in Domoticz

Port 8080 is what needed to be changed to 8084, so finally I'm seeing something on my screen (to bad not much sun today)

Next thing on the nice to have list is a way to import all the old data (4 years) to be displayed. I know the data is available just not how to get it.

Sincze bedankt. (ie thanks for those not speaking dutch)
Excellent what 1 port change can do :)
Change echo back to lg and it will show the log in Domoticz.
Bedankt voor het testen van het script :)
Pass2php
LAN: RFLink, P1, OTGW, MySensors
USB: RFXCom, ZWave, Sonoff 3
MQTT: ZIgbee2MQTT,
ZWAVE: Zwave-JS-UI
WIFI: Mi-light, Tasmota, Xiaomi Shelly
Solar: Omnik, PVOutput
Video: Kodi, Harmony HUB, Chromecast
Sensors: You name it I got 1.
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 »

Kencirot wrote: Wednesday 05 June 2019 14:56 I experience the same issue as Marktap. The daily total of previous day is being used untill the currect day is higher for me.

I also notice when there is no power output I still get the last remain known output showing up (e.g 36Watts from 22:00h onwards till the morning).
Is there a way to set it to "0" when the solar system is offline?

solar.PNG
I am having the same problem, where on Monday the total yield of Sunday is being used. Must be an issue surrounding the day number where on day 7 (or 0, I am not sure about that) a counter is not reset. This problem does not occur however when using the detour via PVOutput.org.
A workaround could be a reset of eDay the first time on Monday using os.time() and timedifference just before updating dayTotal, line 186. My lua knowledge is not good enough to implement this myself. Any coding suggestions anyone?
-‐----------------------------------------------------------
Running on rPi 3b (main) and rPi 2b (somfy), both RFLink
IthoRemote, Xiaomi Gateway, KAKU
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 »

bldewit wrote: Monday 05 August 2019 9:04
Kencirot wrote: Wednesday 05 June 2019 14:56 I experience the same issue as Marktap. The daily total of previous day is being used untill the currect day is higher for me.

I also notice when there is no power output I still get the last remain known output showing up (e.g 36Watts from 22:00h onwards till the morning).
Is there a way to set it to "0" when the solar system is offline?

solar.PNG
I am having the same problem, where on Monday the total yield of Sunday is being used. Must be an issue surrounding the day number where on day 7 (or 0, I am not sure about that) a counter is not reset. This problem does not occur however when using the detour via PVOutput.org.
A workaround could be a reset of eDay the first time on Monday using os.time() and timedifference just before updating dayTotal, line 186. My lua knowledge is not good enough to implement this myself. Any coding suggestions anyone?
Seems to be a little different after all. Now it is tuesday and my dayTotal-value for tuesday has already been set, with the value that was reached on monday! Could there be a timing issue? Would forcing the script to run at 0:00hrs fix the issue?
-‐----------------------------------------------------------
Running on rPi 3b (main) and rPi 2b (somfy), both RFLink
IthoRemote, Xiaomi Gateway, KAKU
User avatar
sincze
Posts: 1299
Joined: Monday 02 June 2014 22:46
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.4
Location: Netherlands / Breda Area
Contact:

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

Post by sincze »

bldewit wrote: Tuesday 06 August 2019 6:57 Seems to be a little different after all. Now it is tuesday and my dayTotal-value for tuesday has already been set, with the value that was reached on monday! Could there be a timing issue? Would forcing the script to run at 0:00hrs fix the issue?
Are you sending E_Current;E_daily (total generated today) to your sensor or the E_Current;E_Total (total generated since install) from the inverter?

If it is the first it is known, the sensor only accepts an incremental counter. Resetting it daily to 0 will not do the trick.
Pass2php
LAN: RFLink, P1, OTGW, MySensors
USB: RFXCom, ZWave, Sonoff 3
MQTT: ZIgbee2MQTT,
ZWAVE: Zwave-JS-UI
WIFI: Mi-light, Tasmota, Xiaomi Shelly
Solar: Omnik, PVOutput
Video: Kodi, Harmony HUB, Chromecast
Sensors: You name it I got 1.
User avatar
sincze
Posts: 1299
Joined: Monday 02 June 2014 22:46
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.4
Location: Netherlands / Breda Area
Contact:

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

Post by sincze »

For peopele still experiencing LUA issues.

New Python Semsportal plugin introduced here: https://github.com/dylian94/domoticz-GoodWeSEMS :D
Goodwe.JPG
Goodwe.JPG (46.33 KiB) Viewed 3067 times
Pass2php
LAN: RFLink, P1, OTGW, MySensors
USB: RFXCom, ZWave, Sonoff 3
MQTT: ZIgbee2MQTT,
ZWAVE: Zwave-JS-UI
WIFI: Mi-light, Tasmota, Xiaomi Shelly
Solar: Omnik, PVOutput
Video: Kodi, Harmony HUB, Chromecast
Sensors: You name it I got 1.
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 »

Good morning,

i have some problems with uploading the right data to pvoutput.org the enrgy used and power Used are continues on 0 in stead of data.
so what am is doing wrong?
i am using the following 2 scripts.

i have also the sems portal plugin in my domoticz.

Device Calculation script.

Code: Select all

-- /home/pi/domoticz/scripts/lua/script_device_calculate_consumption.lua
-- This script collects the values below from Domoticz
--   * The Power and energy values (import and export) from a smartmeter 
--   * The Power and energy values from a Solar power inverter
-- It then calculates the consumed power and energy from the values above with the formula's
--   * EnergyConsumption = EnergyGeneration + EnergyImport - EnergyExport
--   * PowerConsumption = PowerGeneration + PowerImport - PowerExport
-- It then updates a virtual device which displays the consumed power and energy in Domoticz

----------------------------------------------------------------------------------------------------------
-- Domoticz IDX and names of the needed devices
----------------------------------------------------------------------------------------------------------
local GenerationDeviceName = "CurrentOutput" 		-- Device name of the Generated energy
local EnergyDeviceName = "Power" 		-- Name of the energy device that shows imported and exported energy
local ConsumptionIDX = 31  			-- IDX of the energy device that shows calculated Consumption
local ConsumptionDeviceName = "ConsumptionDevice" 		-- Name of the energy device that shows calculated Consumption

----------------------------------------------------------------------------------------------------------
-- Require parameters
----------------------------------------------------------------------------------------------------------
local http = require("socket.http")

----------------------------------------------------------------------------------------------------------
-- Script parameters
----------------------------------------------------------------------------------------------------------
EnergyImportLow = 0	-- in Watt hours
EnergyImportHigh = 0	-- in Watt hours
EnergyExportLow = 0	-- in Watt hours
EnergyExportHigh = 0	-- in Watt hours
EnergyGeneration = 0 	-- in Watt hours
PowerGeneration = 0 	-- in Watts
EnergyImport = 0	-- in Watt hours
PowerImport = 0		-- in Watts
EnergyConsumption = 0 	-- in Watt hours
PowerConsumption = 0 	-- in Watts
Debug = "YES" 		-- Turn debugging on ("YES") or off ("NO")

----------------------------------------------------------------------------------------------------------
-- Lua Functions
----------------------------------------------------------------------------------------------------------
function update(device, id, power, energy, index)
	commandArray[index] = {['UpdateDevice'] = id .. "|0|" .. power .. ";" .. energy}
end 

----------------------------------------------------------------------------------------------------------
-- CommandArray
----------------------------------------------------------------------------------------------------------
commandArray = {}
	-- Generated
	PowerGeneration, EnergyGeneration = otherdevices_svalues[GenerationDeviceName]:match("([^;]+);([^;]+)")
	if Debug=="YES" then
		print("  ----- PowerGeneration = " .. PowerGeneration .. " W");
		print("  ----- EnergyGeneration = " .. EnergyGeneration .. " Wh");
	end

	EnergyImportLow, EnergyImportHigh, EnergyExportLow, EnergyExportHigh, PowerImport, PowerExport = otherdevices_svalues[EnergyDeviceName]:match("([^;]+);([^;]+);([^;]+);([^;]+);([^;]+);([^;]+)")
	EnergyImport = EnergyImportLow + EnergyImportHigh
	EnergyExport = EnergyExportLow + EnergyExportHigh
	if Debug=="YES" then
		print("  ----- PowerImport = " .. PowerImport .. " W");
		print("  ----- EnergyImportLow = " .. EnergyImportLow .. " Wh");
		print("  ----- EnergyImportHigh = " .. EnergyImportHigh .. " Wh");
		print("  ----- EnergyImport = " .. EnergyImport .. " Wh");
		print("  ----- PowerExport = " .. PowerExport .. " W");
		print("  ----- EnergyExportLow = " .. EnergyExportLow .. " Wh");
		print("  ----- EnergyExportHigh = " .. EnergyExportHigh .. " Wh");
		print("  ----- EnergyExport = " .. EnergyExport .. " Wh");
	end

	-- Calculate consumption
	PowerConsumption = PowerGeneration + PowerImport - PowerExport
	if Debug=="YES" then
		print("  ----- PowerConsumption = " .. PowerConsumption .. " W");
	end
	EnergyConsumption = EnergyGeneration + EnergyImport - EnergyExport
	if Debug=="YES" then
		print("  ----- EnergyConsumption = " .. EnergyConsumption .. " Wh");
	end

	-- Update comsumption device in Domoticz
	if devicechanged[EnergyDeviceName] then
		update(ConsumptionDeviceName, ConsumptionIDX, PowerConsumption, EnergyConsumption, 1)
	end
	
return commandArray

TIME SCRIPT

Code: Select all

-- /home/pi/domoticz/scripts/lua/script_time_upload_to_PVoutput.lua
-- This script collects the values below from Domoticz
--   * The Power generation, energy generation and voltage from a Solar power inverter
--   * The temperature from a outside temperature sensor
--   * The Power consumption and energy consumption which is calculated in another Lua script 
-- And uploads all of the values to a PVoutput account.
--
-- For more information about PVoutput, see their user documentation on http://www.pvoutput.org/help.html

----------------------------------------------------------------------------------------------------------
-- Domoticz IDX of devices
----------------------------------------------------------------------------------------------------------
local GenerationDeviceName = "PowerOutput"	-- Device name of the Generated energy
local ConsumptionDeviceName = "ConsumptionDevice" 	-- Name of the energy device that shows calculated Consumption
local VoltageDeviceName = "VoltageOutput"	-- Name of the voltage device that shows voltage of the inverter
local TemperatureDeviceName = "Temperatuur" -- Name of the temperature device that shows outside temperature

----------------------------------------------------------------------------------------------------------
-- PVoutput parameters
----------------------------------------------------------------------------------------------------------
local PVoutputApi = "c550e7568ba649922fd015828f********"		-- Your PVoutput api key
local PVoutputSystemID = "699" 					-- Your PVoutput System ID
local PVoutputPostInterval = 5  					-- The number of minutes between posts to PVoutput (normal is 5 but when in donation mode it's max 1)
local PVoutputURL = '://pvoutput.org/service/r2/addstatus.jsp?key='	-- The URL to the PVoutput Service

----------------------------------------------------------------------------------------------------------
-- Require parameters
----------------------------------------------------------------------------------------------------------
local http = require("socket.http")

----------------------------------------------------------------------------------------------------------
-- Script parameters
----------------------------------------------------------------------------------------------------------
EnergyGeneration = 0 	-- v1 in Watt hours
PowerGeneration = 0 	-- v2 in Watts
EnergyConsumption = 0 	-- v3 in Watt hours
PowerConsumption = 0 	-- v4 in Watts
CurrentTemp = 0 	-- v5 in celcius
Voltage = 0 		-- v6 in volts
c1 = 1 			-- c1 = 0 when v1 is today's energy. c1 = 1 when v1 is lifetime energy.
Debug = "YES" 		-- Turn debugging on ("YES") or off ("NO")

----------------------------------------------------------------------------------------------------------
-- Lua Functions
----------------------------------------------------------------------------------------------------------
function UploadToPVoutput(self)
	b, c, h = http.request("http" .. PVoutputURL .. PVoutputApi .. "&sid=".. PVoutputSystemID .. "&d=" .. os.date("%Y%m%d") .. "&t=" .. os.date("%H:%M") .. 

	"&v1=" .. EnergyGeneration .. "&v2=" .. PowerGeneration .. "&v3=" .. EnergyConsumption .. "&v4=" .. PowerConsumption .. "&v5=" .. CurrentTemp .. "&v6=" .. Voltage .. "&c1=" .. c1 )
	if b=="OK 200: Added Status" then
		print(" -- Current status successfully uploaded to PVoutput.org")
	else
		print(" -- " ..b)
	end
	
	print("  --Energy generation (v1) = ".. EnergyGeneration .. " Wh")
	print("  --Power generation (v2) = " .. PowerGeneration .. " W")
	print("  --Energy consumption (v3) = " .. EnergyConsumption .. " Wh")
	print("  --Power consumption (v4) = " .. PowerConsumption .. " W")
	print("  --Current temperature (v5) = " .. CurrentTemp .. " C")
	print("  --Voltage (v6) = " .. Voltage .. "V")
	print("  --Cumulative Flag (c1) = " .. c1 .. "")
end

function update(device, id, power, energy, index)
	commandArray[index] = {['UpdateDevice'] = id .. "|0|" .. power .. ";" .. energy}
end 

----------------------------------------------------------------------------------------------------------
-- CommandArray
----------------------------------------------------------------------------------------------------------
commandArray = {}

	time = os.date("*t")
	if PVoutputPostInterval > 1 then
		TimeToGo = PVoutputPostInterval - (time.min % PVoutputPostInterval)
		print('Time to go before upload to PVoutput: ' ..TimeToGo.. " minutes")
	end
	
	if((time.min % PVoutputPostInterval)==0)then
		-- Generated
		PowerGeneration, EnergyGeneration = otherdevices_svalues[GenerationDeviceName]:match("([^;]+);([^;]+)")
		if Debug=="YES" then
			print(" ---- The total generated energy is " .. EnergyGeneration .. " Wh");
			print(" ---- The current generated power is " .. PowerGeneration .. " W");
		end

		-- Voltage
		Voltage = otherdevices_svalues[VoltageDeviceName] :match("([^;]+)")
		if Debug=="YES" then
			print(" ---- The voltage of the inverter is " .. Voltage .. " V");
		end
		
		-- Temperature
		CurrentTemp = otherdevices_svalues[TemperatureDeviceName]:match("([^;]+)")
		if Debug=="YES" then
			print(" ---- The outside temperature is " .. CurrentTemp .. " C.");
		end
		--EnergyGeneration = "0"
		--PowerGeneration = "0"
		-- Consumption
		EnergyConsumption, PowerConsumption = otherdevices_svalues[ConsumptionDeviceName]:match("([^;]+);([^;]+)")
		if Debug=="YES" then
			print(" ---- The total consumed energy is " .. EnergyConsumption .. " Wh");
			print(" ---- The current consumed power is " .. PowerConsumption .. " W");
		end
		-- Upload data to PVoutput	
		UploadToPVoutput()
	end

return commandArray
I get also the following error in domoticz log
...ticz/scripts/lua/script_device_calculate_consumption.lua:71: attempt to perform arithmetic on global 'PowerGeneration' (a string value)
2019-09-26 10:39:45.976 Error: EventSystem: in /home/pi/domoticz/scripts/lua/script_device_calculate_consumption.lua: ...ticz/scripts/lua/script_device_calculate_consumption.lua:71: attempt to perform arithmetic on global 'PowerGeneration' (a string value)
2019-09-26 10:39:45.995 Error: EventSystem: in /home/pi/domoticz/scripts/lua/script_device_calculate_consumption.lua: ...ticz/scripts/lua/script_device_calculate_consumption.lua:71: attempt to perform arithmetic on global 'PowerGeneration' (a string value)

i also think something is wrong with the energy import high and low.
because the low is higher than the importhigh
2019-09-26 10:44:18.992 Status: LUA: ----- EnergyGeneration = 339500.0 Wh
2019-09-26 10:44:18.992 Status: LUA: ----- PowerImport = 64 W
2019-09-26 10:44:18.992 Status: LUA: ----- EnergyImportLow = 51778 Wh
2019-09-26 10:44:18.992 Status: LUA: ----- EnergyImportHigh = 26840 Wh
2019-09-26 10:44:18.992 Status: LUA: ----- EnergyImport = 78618 Wh
2019-09-26 10:44:18.992 Status: LUA: ----- PowerExport = 0 W
2019-09-26 10:44:18.992 Status: LUA: ----- EnergyExportLow = 39607 Wh
2019-09-26 10:44:18.992 Status: LUA: ----- EnergyExportHigh = 75129 Wh

Image


so what script do i have to use to get the right data to pvoutput.org and what am i doing wrong?
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 do have the same problem: ...ticz/scripts/lua/script_device_calculate_consumption.lua:71: attempt to perform arithmetic on global 'PowerGeneration' (a string value)

The problem is not the energy import high and low. because the low is higher than the importhigh. High means in this context high tarif and low tarif.

The problem is something with the global "PowerGenaration" For debugging I edited the script with the following rules before the error:

if Debug=="YES" then
print(" ---------------------------------------------------- ");
print(" ----- PowerConsumption = " .. PowerConsumption .. " W");
print(" ----- PowerGeneration = " .. PowerGeneration .. " W");
print(" ----- PowerImport = " .. PowerImport .. " W");
print(" ----- PowerExport = " .. PowerExport .. " W");
print(" -------------------------------------------");
end
PowerConsumption = PowerGeneration + PowerImport - PowerExport

With the result in the log:

2019-10-06 13:21:48.784 Status: LUA: ----------------------------------------------------
2019-10-06 13:21:48.784 Status: LUA: ----- PowerConsumption = 0 W
2019-10-06 13:21:48.784 Status: LUA: ----- PowerGeneration = 198W W
2019-10-06 13:21:48.784 Status: LUA: ----- PowerImport = 100 W
2019-10-06 13:21:48.784 Status: LUA: ----- PowerExport = 0 W
2019-10-06 13:21:48.784 Status: LUA: -------------------------------------------
2019-10-06 13:21:48.631 Error: EventSystem: in /home/pi/domoticz/scripts/lua/script_device_calculate_consumption.lua: ...ticz/scripts/lua/script_device_calculate_consumption.lua:82: attempt to perform arithmetic on global 'PowerGeneration' (a string value)

So the question is why does it not calculate Powerconsumption to 198+100-0 = 298

Anyone?

Thank you,

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

A good look at my results in the log and I found this:

2019-10-06 13:21:48.784 Status: LUA: ----- PowerGeneration = 198W W

That's the problem I think. Now, find out what is the cause...

@sjoemie1985 : I think tou have the same problem. Just add the following two lines just before "PowerConsumption = PowerGeneration + PowerImport - PowerExport" in the script and check the result in your log.

print(" ----- PowerConsumption = " .. PowerConsumption .. " W");
print(" ----- PowerGeneration = " .. PowerGeneration .. " W");
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest