Im just starting our on LUA coding. I want to measure the watts being consumed after I power up a device
If I use the following code
local watts = luup.variable_get( “urn:micasaverde-com:serviceId:EnergyMetering1”, “Watts”, device)
When I look at the variable watts it returns ‘undefined’. Do I need to wait a few seconds after power up before measuring the power consumption? If so how do I add a delay of a few seconds.
You probably have the wrong device id … or you entered it as a string … it needs to be a number.
You should get the same value you see on the Advanced Tab → Variables for that device.
Is your statement in your LUA startup code? I have noticed that when that code executes, the Vera environment is not completely set up.
What I did to solve this is to have the startup code run a “Start Up” scene (the run statement technically just schedules that scene). When the Vera/LUA engine is all ready to go, the “Start Up” scene will then get run. You could put your code in that scene.
Its part of a scene that is triggered when device ID is switched on. I agree with you that it may be too soon. This is why I thought of m adding a delay after switch on before taking the measurement of Watts.
I have got it working. I used call_delay to provide some time for the device to power up and initialise itself. Now it returns the correct watts measurement every time.
[code]local device = 5
luup.call_delay( ‘WATTS’, 60)
function WATTS()
local watts = luup.variable_get( “urn:micasaverde-com:serviceId:EnergyMetering1”, “Watts”, device)
end[/code]
I saw an extension called ‘is_ready’. Would this function wait until a device has initialised after power up before returning measurements like ‘Watts’?
If so how do I use this variable. I had trouble with it.
I tried
if (luup.is_ready(deviceID) then
-- do something
end
This didnt seem t work. Any help on the proper use of this extension please.
[quote=“aa6vh, post:7, topic:193939”]I do not know the answer to your is_ready question, but you do realize that there is a syntax error: Missing closing parenthesis.
if (luup.is_ready(deviceID)) then
-- do something
end
[/quote]
Yes, I saw that. that was an error as I typed it out and didnt cut and paste.
Does anyone know how to use the is_ready function?
Many thanks
Best Home Automation shopping experience. Shop at Ezlo!