LUA script fungerer ikke lenger

Moderator: Telldus

Post Reply
bergetun
Posts: 23
Joined: Thu Jan 18, 2018 11:08 am

LUA script fungerer ikke lenger

Post by bergetun » Sun Nov 10, 2019 6:50 pm

Ingen av mine LUA script fungerer lenger. DE har tidligere fungert uten problemer, men nå får jeg masse rare feilmeldinger.

Her er ett eksempel på et script som ikke lenger fungerer.

Code: Select all

SCALE_POWER_VOLT = 4
VALUE_TYPE_POWER = 256
TYPE_TEMPERATURE = 1
POWER = 256 

local myDevice = "Volt"
local deviceManager = require "telldus.DeviceManager"
local sensor = deviceManager:findByName(myDevice)

function onSensorValueUpdated(device, valueType, value, scale)
   if device:id() == sensor:id() and valueType == TYPE_TEMPERATURE 
   then		
        sensor:setSensorValue(256, value, 4)
   end
end


Får feilmelding:

Console
Could not execute function onSensorValueUpdated: [string "<python>"]:11: attempt to index upvalue 'sensor' (a nil value)

Could not execute function onSensorValueUpdated: [string "<python>"]:11: attempt to index upvalue 'sensor' (a nil value)

Could not execute function onSensorValueUpdated: [string "<python>"]:11: attempt to index upvalue 'sensor' (a nil value)

micke.prag
Site Admin
Posts: 2234
Joined: Thu Jan 18, 2018 11:08 am
Location: Lund
Contact:

Re: LUA script fungerer ikke lenger

Post by micke.prag » Tue Nov 12, 2019 1:15 pm

Do not fetch the sensor in the global scope but in your function instead.

Code: Select all

SCALE_POWER_VOLT = 4
VALUE_TYPE_POWER = 256
TYPE_TEMPERATURE = 1
POWER = 256 

local myDevice = "Volt"

function onSensorValueUpdated(device, valueType, value, scale)
   local deviceManager = require "telldus.DeviceManager"
   local sensor = deviceManager:findByName(myDevice)
   if device:id() == sensor:id() and valueType == TYPE_TEMPERATURE 
   then		
        sensor:setSensorValue(256, value, 4)
   end
end

Micke Prag
Software
Telldus Technologies

Post Reply