Page 1 of 1

Lua script is stop working

Posted: Monday 08 January 2018 22:36
by jandoedel99
Ihave a script ,inside Domoticz, that is ,after update Linux and update domoticz to last beta, not working anymore.

Code: Select all

[/--script_device_deltaT.lua 
--This script subtracts two sensors (aanvoer_dv and retour_dv) from eachother and puts the calculated value in a new sensor (to be configured with 'deltat_idx')
local aanvoer_dv = 'CV Aanvoer'
local retour_dv = 'CV Retour'
local deltat_idx = 51

commandArray = {}

--if devicechanged[aanvoer_dv] then

        aanvoer = otherdevices_svalues[aanvoer_dv]
        retour = otherdevices_svalues[retour_dv]
        aanvoer_temp = (aanvoer)
        retour_temp = (retour)
        commandArray['UpdateDevice'] = deltat_idx .. '|0|' .. string.format("%." .. 1 .. "f", aanvoer_temp - retour_temp)
--end

return commandArray

error in log is now±
2018-01-08 22:30:20.220 Error: EventSystem: in DeltaT: [string "..."]:16: attempt to perform arithmetic on global 'aanvoer_temp' (a nil value)

I have not change the script.

Re: Lua script is stop working

Posted: Tuesday 09 January 2018 8:25
by emme
2 notes:
aanvoer_temp = (aanvoer)
svalue uses Strings, not number... so it should be converted to
aanvoer_temp = tonumber(aanvoer)

the same for
retour_temp = (retour)
should be
retour_temp = tonumber(retour)

consider to covert to dzVents platform which is MUCH more flexible and realiabe...
I have a similar script for my central heating system in which I calculate the DeltaT between incoming water temp and outcoming water temp

your script will look like:

Code: Select all

return {
	on = {
		devices = {
			'CV Aanvoer',
			'CV Retour'
		}
	},
	execute = function(dz, devTemp)
	    local deltat_idx = 51
	    local aanTemp = dz.round(dz.devices('CV Aanvoer').temperature,2)
	    local retTemp = dz.round(dz.devices('CV Retour').temperature,2)
	    dz.devices(deltat_idx).updateTemperature(aanTemp - retTemp)
	end
}
ciao
M

Re: Lua script is stop working

Posted: Tuesday 09 January 2018 9:06
by jandoedel99
Thanks it is working.
But there is in the log:
2018-01-09 08:54:02.282 Error: dzVents: Error: ...oticz/scripts/dzVents/../../dzVents/runtime/Domoticz.lua:243: attempt to perform arithmetic on local 'x' (a table value)

I have to read me in dzVents.

Re: Lua script is stop working

Posted: Tuesday 09 January 2018 10:29
by emme
uh... my fault!!!

script corrected

(note also the setTemperature that became updateTemperature :P :P)

Re: Lua script is stop working

Posted: Tuesday 09 January 2018 14:55
by jandoedel99
Thanks again
This is great.
I try to now convert a other script to dvVent.
When i have problems i write.