LUA script hangs Telldus zwave V2

Moderator: Telldus

Post Reply
magellan58
Posts: 18
Joined: Fri Mar 17, 2023 9:45 am

LUA script hangs Telldus zwave V2

Post by magellan58 »

I'm trying the LUA script below, and the script itself works as expected but after a day or two it hangs the system and I need to power off the Tellstick unit.

Is it my script that is the problem or is it a bug?

Code: Select all

local deviceManager = require "telldus.DeviceManager"
local pooltemp = "US Pool" -- Name of the Pool Temp
local pooltempadjusted = "Pool justerad" -- Name of the dummy sensor (must exist!!)


function onSensorValueUpdated()

	local device = deviceManager:findByName(pooltemp)
	local my_adjusted = deviceManager:findByName(pooltempadjusted)
	if device == nil or my_adjusted == nil then
		return
    end
	
	local Temp = device:sensorValue(1,0)
	local Resultat = Temp + 0.1

	if (Resultat < 35) and (Resultat > 10) then
		my_adjusted:setSensorValue(1, Resultat, 0)
	end
end
fcorin
Posts: 19
Joined: Fri Mar 17, 2023 9:45 am

Re: LUA script hangs Telldus zwave V2

Post by fcorin »

I'm no Lua / Tellstick expert, but I think your script will run as soon as any sensor is updated, and that might cause the device to run out of resources.

Maybe try something like this:

Code: Select all

local deviceManager = require "telldus.DeviceManager"
local pooltemp = "US Pool" -- Name of the Pool Temp
local pooltempadjusted = "Pool justerad" -- Name of the dummy sensor (must exist!!)

function onSensorValueUpdated(device, valueType, value, scale)
	if device:name() == pooltemp and valueType == 1 then
		local my_adjusted = deviceManager:findByName(pooltempadjusted)
		if my_adjusted == nil then
			return
		end

		local Resultat = value + 0.1
		if (Resultat < 35) and (Resultat > 10) then
			my_adjusted:setSensorValue(1, Resultat, 0)
		end
	end
end
--
Fredrik
magellan58
Posts: 18
Joined: Fri Mar 17, 2023 9:45 am

Re: LUA script hangs Telldus zwave V2

Post by magellan58 »

Thanks, I am not sure I understand why your version should consume less resources. Won't it still execute on every sensor update?

But I could give it a try and see if it makes any difference.


/Mats
fcorin
Posts: 19
Joined: Fri Mar 17, 2023 9:45 am

Re: LUA script hangs Telldus zwave V2

Post by fcorin »

Hi,

The difference between our scripts is that my script will only query deviceManger and update the sensor value if the change is indeed related to the sensor named "US Pool".

I think your script will cause a loop.
pooltemp is updated -> you change pooltempadjusted -> that will trigger onSensorValueUpdated and the process starts again.
--
Fredrik
magellan58
Posts: 18
Joined: Fri Mar 17, 2023 9:45 am

Re: LUA script hangs Telldus zwave V2

Post by magellan58 »

Ok, yes now I understand the difference.

Thanks for your help!
Post Reply