Lua version problem domoticz

Moderator: leecollings

sjoemie1985
Posts: 27
Joined: Thursday 26 September 2019 10:18
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Lua version problem domoticz

Post by sjoemie1985 »

Good afternoon,

i am using domoticz on a raspberry pi 4 with rasbian 10 (buster) installed/ upgraded on it.

my domoticz is giving a lua version problem in the logging.
see the following code
i tried installing lua and reinstalling it but somehow he can't find the location of those files.
it looks like that domoticz want to use version 5.3 while my raspberry pi sees version 5.2 as default or so.

Can someone help me out?

Code: Select all

2020-03-23 16:50:30.006 Error: EventSystem: in /home/pi/domoticz/scripts/lua/script_device_calculate_consumption.lua: ...ticz/scripts/lua/script_device_calculate_consumption.lua:21: module 'socket.http' not found:
2020-03-23 16:50:30.006 no field package.preload['socket.http']
2020-03-23 16:50:30.006 no file '/usr/local/share/lua/5.3/socket/http.lua'
2020-03-23 16:50:30.006 no file '/usr/local/share/lua/5.3/socket/http/init.lua'
2020-03-23 16:50:30.006 no file '/usr/local/lib/lua/5.3/socket/http.lua'
2020-03-23 16:50:30.006 no file '/usr/local/lib/lua/5.3/socket/http/init.lua'
2020-03-23 16:50:30.006 no file './socket/http.lua'
2020-03-23 16:50:30.006 no file './socket/http/init.lua'
2020-03-23 16:50:30.006 no file '/usr/local/lib/lua/5.3/socket/http.so'
2020-03-23 16:50:30.006 no file '/usr/local/lib/lua/5.3/loadall.so'
2020-03-23 16:50:30.006 no file './socket/http.so'
2020-03-23 16:50:30.006 no file '/usr/local/lib/lua/5.3/socket.so'
2020-03-23 16:50:30.006 no file '/usr/local/lib/lua/5.3/loadall.so'
2020-03-23 16:50:30.006 no file './socket.so'
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Lua version problem domoticz

Post by waaren »

sjoemie1985 wrote: Monday 23 March 2020 16:54 my domoticz is giving a lua version problem in the logging.
it looks like that domoticz want to use version 5.3 while my raspberry pi sees version 5.2 as default or so.
Can you try
sudo apt-get install lua5.3 liblua5.3
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
sjoemie1985
Posts: 27
Joined: Thursday 26 September 2019 10:18
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Lua version problem domoticz

Post by sjoemie1985 »

waaren wrote: Monday 23 March 2020 17:02
sjoemie1985 wrote: Monday 23 March 2020 16:54 my domoticz is giving a lua version problem in the logging.
it looks like that domoticz want to use version 5.3 while my raspberry pi sees version 5.2 as default or so.
Can you try
sudo apt-get install lua5.3 liblua5.3
done that and gives thist result

Code: Select all

Reading package lists... Done
Building dependency tree
Reading state information... Done
Note, selecting 'liblua5.3-dev' for regex 'liblua5.3'
Note, selecting 'liblua5.3-0-dbg' for regex 'liblua5.3'
Note, selecting 'liblua5.3-0' for regex 'liblua5.3'
liblua5.3-0 is already the newest version (5.3.3-1.1).
liblua5.3-0-dbg is already the newest version (5.3.3-1.1).
liblua5.3-dev is already the newest version (5.3.3-1.1).
lua5.3 is already the newest version (5.3.3-1.1).
0 upgraded, 0 newly installed, 0 to remove and 27 not upgraded.
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Lua version problem domoticz

Post by waaren »

sjoemie1985 wrote: Monday 23 March 2020 17:13 lua5.3 is already the newest version (5.3.3-1.1).
What do you see when you give

Code: Select all

sudo update-alternatives --config lua-interpreter
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
sjoemie1985
Posts: 27
Joined: Thursday 26 September 2019 10:18
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Lua version problem domoticz

Post by sjoemie1985 »

waaren wrote: Monday 23 March 2020 17:25
sjoemie1985 wrote: Monday 23 March 2020 17:13 lua5.3 is already the newest version (5.3.3-1.1).
What do you see when you give

Code: Select all

sudo update-alternatives --config lua-interpreter
than i see this:

Code: Select all

There are 3 choices for the alternative lua-interpreter (providing /usr/bin/lua).

  Selection    Path             Priority   Status
------------------------------------------------------------
* 0            /usr/bin/lua5.2   120       auto mode
  1            /usr/bin/lua5.1   110       manual mode
  2            /usr/bin/lua5.2   120       manual mode
  3            /usr/bin/lua5.3   120       manual mode

Press <enter> to keep the current choice[*], or type selection number:

User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Lua version problem domoticz

Post by waaren »

sjoemie1985 wrote: Tuesday 24 March 2020 9:35

Code: Select all

There are 3 choices for the alternative lua-interpreter (providing /usr/bin/lua).

  Selection    Path             Priority   Status
------------------------------------------------------------
* 0            /usr/bin/lua5.2   120       auto mode
  1            /usr/bin/lua5.1   110       manual mode
  2            /usr/bin/lua5.2   120       manual mode
  3            /usr/bin/lua5.3   120       manual mode

Press <enter> to keep the current choice[*], or type selection number:

Now do the same and choose option 3
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
sjoemie1985
Posts: 27
Joined: Thursday 26 September 2019 10:18
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Lua version problem domoticz

Post by sjoemie1985 »

waaren wrote: Tuesday 24 March 2020 9:44
sjoemie1985 wrote: Tuesday 24 March 2020 9:35

Code: Select all

There are 3 choices for the alternative lua-interpreter (providing /usr/bin/lua).

  Selection    Path             Priority   Status
------------------------------------------------------------
* 0            /usr/bin/lua5.2   120       auto mode
  1            /usr/bin/lua5.1   110       manual mode
  2            /usr/bin/lua5.2   120       manual mode
  3            /usr/bin/lua5.3   120       manual mode

Press <enter> to keep the current choice[*], or type selection number:

Now do the same and choose option 3
done that and now the star is at option 3
but in the domoticz log i still see this :(

Code: Select all

2020-03-24 12:46:24.359 Error: EventSystem: in /home/pi/domoticz/scripts/lua/script_device_calculate_consumption.lua: ...ticz/scripts/lua/script_device_calculate_consumption.lua:21: module 'socket.http' not found:
2020-03-24 12:46:24.359 no field package.preload['socket.http']
2020-03-24 12:46:24.359 no file '/usr/local/share/lua/5.3/socket/http.lua'
2020-03-24 12:46:24.359 no file '/usr/local/share/lua/5.3/socket/http/init.lua'
2020-03-24 12:46:24.359 no file '/usr/local/lib/lua/5.3/socket/http.lua'
2020-03-24 12:46:24.359 no file '/usr/local/lib/lua/5.3/socket/http/init.lua'
2020-03-24 12:46:24.359 no file './socket/http.lua'
2020-03-24 12:46:24.359 no file './socket/http/init.lua'
2020-03-24 12:46:24.359 no file '/usr/local/lib/lua/5.3/socket/http.so'
2020-03-24 12:46:24.359 no file '/usr/local/lib/lua/5.3/loadall.so'
2020-03-24 12:46:24.359 no file './socket/http.so'
2020-03-24 12:46:24.359 no file '/usr/local/lib/lua/5.3/socket.so'
2020-03-24 12:46:24.359 no file '/usr/local/lib/lua/5.3/loadall.so'
2020-03-24 12:46:24.359 no file './socket.so'
when trying to find files with lua5.3 is only see this

Image
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Lua version problem domoticz

Post by waaren »

sjoemie1985 wrote: Tuesday 24 March 2020 12:47 done that and now the star is at option 3
but in the domoticz log i still see this :(
Can you share the script ?
and what do you see when you give

Code: Select all

sudo find / -name socket.* | grep lua
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
sjoemie1985
Posts: 27
Joined: Thursday 26 September 2019 10:18
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Lua version problem domoticz

Post by sjoemie1985 »

waaren wrote: Tuesday 24 March 2020 12:50
sjoemie1985 wrote: Tuesday 24 March 2020 12:47 done that and now the star is at option 3
but in the domoticz log i still see this :(
Can you share the script ?
and what do you see when you give

Code: Select all

sudo find / -name socket.* | grep lua

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 = "Power" 		-- Device name of the Generated energy
local EnergyDeviceName = "Power" 		-- Name of the energy device that shows imported and exported energy
local ConsumptionIDX = 61  			-- 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
----------------------------------------------------------------------------------------------------------
if (EnergyImportLow==nil) then
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")

end
----------------------------------------------------------------------------------------------------------
-- 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
Image
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Lua version problem domoticz

Post by waaren »

sjoemie1985 wrote: Tuesday 24 March 2020 13:15

Code: Select all

-- /home/pi/domoticz/scripts/lua/script_device_calculate_consumption.lua
----------------------------------------------------------------------------------------------------------
-- Require parameters
----------------------------------------------------------------------------------------------------------
local http = require("socket.http")
You can change this to

Code: Select all

----------------------------------------------------------------------------------------------------------
-- Require parameters
----------------------------------------------------------------------------------------------------------
-- local http = require("socket.http")
it is not used in the script :)
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
User avatar
hansonexperience
Posts: 12
Joined: Thursday 19 October 2017 14:24
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.1
Location: the Netherlands
Contact:

Re: Lua version problem domoticz

Post by hansonexperience »

I have the same problem and error messages after upgrading to the new version.
I have:

-- Require parameters
----------------------------------------------------------------------------------------------------------
local http = require("socket.http")
Solar: pvoutput, solarman, JFY inverter, enelogic, slimmemeterportal, Greenchoice
Weather: Davis VUE ISS, meteobridge wunderground, Asus WL -330N3G, leuven template
Website: http://www.hansonexperience.com / http://www.mooiweerboxtel.nl
User avatar
hansonexperience
Posts: 12
Joined: Thursday 19 October 2017 14:24
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.1
Location: the Netherlands
Contact:

Re: Lua version problem domoticz

Post by hansonexperience »

I skipped the ---local http = require("socket.http") line and I thought it was working now. I did not get the error of the socket
But I have this error now:

EventSystem: in /home/pi/domoticz/scripts/lua/script_time_upload_to_PVoutput.lua: .../domoticz/scripts/lua/script_time_upload_to_PVoutput.lua:39: attempt to index a nil value (global 'http')

How can I solve that?
Solar: pvoutput, solarman, JFY inverter, enelogic, slimmemeterportal, Greenchoice
Weather: Davis VUE ISS, meteobridge wunderground, Asus WL -330N3G, leuven template
Website: http://www.hansonexperience.com / http://www.mooiweerboxtel.nl
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Lua version problem domoticz

Post by waaren »

hansonexperience wrote: Tuesday 24 March 2020 19:06 I skipped the ---local http = require("socket.http") line and I thought it was working now. I did not get the error of the socket
But I have this error now:

EventSystem: in /home/pi/domoticz/scripts/lua/script_time_upload_to_PVoutput.lua: .../domoticz/scripts/lua/script_time_upload_to_PVoutput.lua:39: attempt to index a nil value (global 'http')

How can I solve that?
If you compile locally you can cmake with

Code: Select all

cmake -DCMAKE_BUILD_TYPE=Release CMakeLists.txt -DUSE_OPENSSL_STATIC="NO" -DUSE_BUILTIN_LUA="NO"
Forcing the Lua engine in domoticz to use external libraries

If you use the pre build binaries then I suggest to move to the dzVents version of the PVoutput script.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
User avatar
hansonexperience
Posts: 12
Joined: Thursday 19 October 2017 14:24
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.1
Location: the Netherlands
Contact:

Re: Lua version problem domoticz

Post by hansonexperience »

waaren wrote: Wednesday 25 March 2020 9:21
hansonexperience wrote: Tuesday 24 March 2020 19:06 I skipped the ---local http = require("socket.http") line and I thought it was working now. I did not get the error of the socket
But I have this error now:

EventSystem: in /home/pi/domoticz/scripts/lua/script_time_upload_to_PVoutput.lua: .../domoticz/scripts/lua/script_time_upload_to_PVoutput.lua:39: attempt to index a nil value (global 'http')

How can I solve that?
If you compile locally you can cmake with

Code: Select all

cmake -DCMAKE_BUILD_TYPE=Release CMakeLists.txt -DUSE_OPENSSL_STATIC="NO" -DUSE_BUILTIN_LUA="NO"
Forcing the Lua engine in domoticz to use external libraries

If you use the pre build binaries then I suggest to move to the dzVents version of the PVoutput script.
Thx for your reply. I am a kind of newbie, how can I check if I complile locallly or use the pre build binaries?
Solar: pvoutput, solarman, JFY inverter, enelogic, slimmemeterportal, Greenchoice
Weather: Davis VUE ISS, meteobridge wunderground, Asus WL -330N3G, leuven template
Website: http://www.hansonexperience.com / http://www.mooiweerboxtel.nl
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Lua version problem domoticz

Post by waaren »

hansonexperience wrote: Wednesday 25 March 2020 11:45 Thx for your reply. I am a kind of newbie, how can I check if I complile locallly or use the pre build binaries?
If you don't' know, you are using pre builds
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
sjoemie1985
Posts: 27
Joined: Thursday 26 September 2019 10:18
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Lua version problem domoticz

Post by sjoemie1985 »

waaren wrote: Tuesday 24 March 2020 16:57
sjoemie1985 wrote: Tuesday 24 March 2020 13:15

Code: Select all

-- /home/pi/domoticz/scripts/lua/script_device_calculate_consumption.lua
----------------------------------------------------------------------------------------------------------
-- Require parameters
----------------------------------------------------------------------------------------------------------
local http = require("socket.http")
You can change this to

Code: Select all

----------------------------------------------------------------------------------------------------------
-- Require parameters
----------------------------------------------------------------------------------------------------------
-- local http = require("socket.http")
it is not used in the script :)
thanks i indeed tried that and that helped solving it for that script.

but i have an other script where it is used i think. in my domomticz log i see the same error as at the other script. :(

any idea? or is it also an unnecessary part of the 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 = "THB" -- Name of the temperature device that shows outside temperature

----------------------------------------------------------------------------------------------------------
-- PVoutput parameters
----------------------------------------------------------------------------------------------------------
local PVoutputApi = "xxxxxxx"		-- Your PVoutput api key
local PVoutputSystemID = "xxxxx" 					-- 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"
		-- PowerConsumption
		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
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Lua version problem domoticz

Post by waaren »

sjoemie1985 wrote: Thursday 26 March 2020 9:55 I have an other script where it is used i think. in my domomticz log i see the same error as at the other script. :(
any idea? or is it also an unnecessary part of the script.
No it is used in this script.
The issue is reported in github but I don't know when / if it can be solved. If you cannot compile locally I suggest to move to the dzVents version of this PVoutput script.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
sjoemie1985
Posts: 27
Joined: Thursday 26 September 2019 10:18
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Lua version problem domoticz

Post by sjoemie1985 »

waaren wrote: Thursday 26 March 2020 11:20
sjoemie1985 wrote: Thursday 26 March 2020 9:55 I have an other script where it is used i think. in my domomticz log i see the same error as at the other script. :(
any idea? or is it also an unnecessary part of the script.
No it is used in this script.
The issue is reported in github but I don't know when / if it can be solved. If you cannot compile locally I suggest to move to the dzVents version of this PVoutput script.
okay thanks for the help sofar :)
sjoemie1985
Posts: 27
Joined: Thursday 26 September 2019 10:18
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Lua version problem domoticz

Post by sjoemie1985 »

i am now using the pvout with an dzVents script and looks to work pretty good.

but i get one little error

Code: Select all

2020-03-27 15:18:22.666 Error: dzVents: Error: (3.0.1) Eigen verbruik: An error occurred when calling event handler script_time_upload_to_PVoutput
2020-03-27 15:18:22.666 Error: dzVents: Error: (3.0.1) Eigen verbruik: ...ripts/dzVents/scripts/script_time_upload_to_PVoutput.lua:38: attempt to perform arithmetic on a string value (local 'PowerGeneration')

this is my script:
could it be the marker name?
some one that knows the solution about what is going wrong?

Code: Select all

return {

    on = {
        devices = { 
                    21, -- Slimme meter youless (youless or P1)
                    61, -- Zonnepanelen
					}
         },
    logging = {
        level = domoticz.LOG_INFO,
--        level = domoticz.LOG_ERROR,
        marker = "Eigen verbruik"
               },    
    
    execute = function(domoticz, item)
        
        local Smartmeter = domoticz.devices(21)   -- Slimme meter (youless or P1)
        local Generation = domoticz.devices(30)   -- Zonnepanelen
        local Consumption = domoticz.devices(61)  -- Eigen verbruik / calculated value / dummy Elekta kWh + counter
        
        -- Smartmeter
        local EnergyImportLow = Smartmeter.rawData[1]
        local EnergyImportHigh = Smartmeter.rawData[2]
        local EnergyExportLow = Smartmeter.rawData[3]
        local EnergyExportHigh = Smartmeter.rawData[4]
        local PowerImport = Smartmeter.rawData[5]
        local PowerExport = Smartmeter.rawData[6]
        
        -- Generation
        local EnergyGeneration = Generation.rawData[2]
        local PowerGeneration = Generation.rawData[1]

        --Calculate
        local EnergyImport = EnergyImportLow + EnergyImportHigh
        local EnergyExport = EnergyExportLow + EnergyExportHigh
        
        local EnergyConsumption = EnergyGeneration + EnergyImport - EnergyExport
        local PowerConsumption = PowerGeneration + PowerImport - PowerExport

        domoticz.log('EnergyImportLow ' .. EnergyImportLow .. ' Wh ', domoticz.LOG_INFO)
        domoticz.log('EnergyImportHigh ' .. EnergyImportHigh .. ' Wh ', domoticz.LOG_INFO)
        domoticz.log('EnergyExportLow ' .. EnergyExportLow .. ' Wh ', domoticz.LOG_INFO)
        domoticz.log('EnergyExportHigh ' .. EnergyExportHigh .. ' Wh ', domoticz.LOG_INFO)

        domoticz.log('PowerImport ' .. PowerImport .. ' W ', domoticz.LOG_INFO)
        domoticz.log('PowerExport ' .. PowerExport .. ' W ', domoticz.LOG_INFO)
        domoticz.log('EnergyGeneration ' .. EnergyGeneration .. ' Wh ', domoticz.LOG_INFO)
        domoticz.log('PowerGeneration ' .. PowerGeneration .. ' W ', domoticz.LOG_INFO)

        domoticz.log('EnergyConsumption ' .. EnergyConsumption .. ' Wh ', domoticz.LOG_INFO)
        domoticz.log('PowerConsumption: ' .. PowerConsumption .. ' W ', domoticz.LOG_INFO)
        
        domoticz.openURL('http://127.0.0.1:8080/json.htm?type=command&param=udevice&idx=21'..'&nvalue=0&svalue='..PowerConsumption..';'..EnergyConsumption)  
        --vul zelf hier idx in van dummy Consumption (83) en domoticz port (8095)
        
    end
    
}
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Lua version problem domoticz

Post by waaren »

sjoemie1985 wrote: Friday 27 March 2020 15:22 but i get one little error
could it be the marker name?
No, the error tells you are trying to calculate with a string. You first have to convert the string to a number.
You can also use the dzVents attribute names where known / available. See below.

Code: Select all

return {

    on = {
        devices = { 
                    21, -- Slimme meter youless (youless or P1)
                    61, -- Zonnepanelen
					}
         },
    logging = {
        level = domoticz.LOG_INFO,
--        level = domoticz.LOG_ERROR,
        marker = "Eigen verbruik"
               },    
    
    execute = function(domoticz, item)
        
        local Smartmeter = domoticz.devices(21)   -- Slimme meter (youless or P1)
        local Generation = domoticz.devices(30)   -- Zonnepanelen
        local Consumption = domoticz.devices(61)  -- Eigen verbruik / calculated value / dummy Elekta kWh + counter
        
		-- Smartmeter
        local EnergyImportLow = Smartmeter.usage2
        local EnergyImportHigh = Smartmeter.usage1
        local EnergyExportLow = Smartmeter.return2
        local EnergyExportHigh = Smartmeter.return1
        local PowerImport = Smartmeter.usage
        local PowerExport = Smartmeter.usageDelivered
        
        -- Generation
        local EnergyGeneration = tonumber(Generation.rawData[2])
        local PowerGeneration = tonumber(Generation.rawData[1])

        --Calculate
        local EnergyImport = EnergyImportLow + EnergyImportHigh
        local EnergyExport = EnergyExportLow + EnergyExportHigh
        
        local EnergyConsumption = EnergyGeneration + EnergyImport - EnergyExport
        local PowerConsumption = PowerGeneration + PowerImport - PowerExport

        domoticz.log('EnergyImportLow ' .. EnergyImportLow .. ' Wh ', domoticz.LOG_INFO)
        domoticz.log('EnergyImportHigh ' .. EnergyImportHigh .. ' Wh ', domoticz.LOG_INFO)
        domoticz.log('EnergyExportLow ' .. EnergyExportLow .. ' Wh ', domoticz.LOG_INFO)
        domoticz.log('EnergyExportHigh ' .. EnergyExportHigh .. ' Wh ', domoticz.LOG_INFO)

        domoticz.log('PowerImport ' .. PowerImport .. ' W ', domoticz.LOG_INFO)
        domoticz.log('PowerExport ' .. PowerExport .. ' W ', domoticz.LOG_INFO)
        domoticz.log('EnergyGeneration ' .. EnergyGeneration .. ' Wh ', domoticz.LOG_INFO)
        domoticz.log('PowerGeneration ' .. PowerGeneration .. ' W ', domoticz.LOG_INFO)

        domoticz.log('EnergyConsumption ' .. EnergyConsumption .. ' Wh ', domoticz.LOG_INFO)
        domoticz.log('PowerConsumption: ' .. PowerConsumption .. ' W ', domoticz.LOG_INFO)
        
        domoticz.openURL('http://127.0.0.1:8080/json.htm?type=command&param=udevice&idx=21'..'&nvalue=0&svalue='..PowerConsumption..';'..EnergyConsumption)  
        --vul zelf hier idx in van dummy Consumption (83) en domoticz port (8095)
        
    end
    
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 1 guest