Hi,
I’m doing my first scene with luup code and encountered few problems. Main goal is to achieve a scene which would turn on a wall plug on certain time of the day and with certain outside temperature criteria.
[ol][li]I created a scene which runs by schedule 5min intervals[/li]
[li]added following luup code into the luup section[/li][/ol]
But still it doest work. Do i need to do some other extra steps or does my coding have some errors?
Its quite basic.
local PLUG = 3 -- The electric plug device number
local TEMPERATURE = e3 -- The temperature device number
local t = os.date('*t')
local current_second = t.hour * 3600 + t.min * 60 + t.sec -- number of seconds since midnight
local min_time_in_seconds = 6 * 3600 + 0 * 60 -- 6:00
local max_time_in_seconds = 8 * 3600 + 0 * 60 -- 8:00
-- read the outside temperature
local temp = luup.variable_get("urn:upnp-org:serviceId:TemperatureSensor1","CurrentTemperature", TEMPERATURE)
if (current_second > min_time_in_seconds) and (current_second < max_time_in_seconds) and (temp < 5) then
-- do something
luup.call_action("urn:upnp-org:serviceId:SwitchPower1", "SetTarget", {newTargetValue = "1"}, PLUG)
else
luup.call_action("urn:upnp-org:serviceId:SwitchPower1", "SetTarget", {newTargetValue = "0"}, PLUG)
end
I’m using Fibaro universal binary sensor and have attached 2 temperature sensors to it.
After adding the fibaro unit to my veralite i see these two temp measurements on my vera and by browsing their settings i can spot on the settings page ID: e3 and for the other sensor ID: e4
I should use some other ID, but I dont have an idea?
Or do you mean it should be in this form, uuid found in the temp advanced settings tab:
local TEMPERATURE = "uuid:4d494342-5342-5645-000a-00000217b0b1" -- The temperature device number
It should be the device id found under the top of the settings tab.
[quote=“garrettwp, post:4, topic:177363”]It should be the device id found under the top of the settings tab.
ID is e3 which previously was commented to be wrong ?
You are confusing node id with device id. It should be a number.
[quote=“garrettwp, post:6, topic:177363”]You are confusing node id with device id. It should be a number.
Ahaa ok, so on settings tab there is a Device #X, where x denotes the device number which i sould use in my luup code?
But anyway if i change device id accordingly and then try my code in apps->develop apps->test luup code. I receive an error msg which says: Code Failed
Yes, Device #X is the correct one to use.
Try this. Test without the comment lines – xyz
ok the code seems to work, problem is with temp sensor reading which is unstable. Is there any way to check if
luup.variable_get is successful?
I do not know what you mean by unstable …
But you can check the documentation for the function:
http://wiki.micasaverde.com/index.php/Luup_Lua_extensions#function:_variable_get
Answering to myself:
There was a problem with the temperature reading because luup.variable_get do not return numeric value…
Assign the result of luup.variable_get to a variable first, rather than putting it directly in the tonumber(), because luup.variable_get actually returns 2 values: the value of the variable, and the time when the variable was modified. The 'tonumber' is needed because all of a device's variables are stored as plain text--not numbers--so if you want to do arithmetic or numeric comparison of a variable, you need to put tonumber() around luup.variable_get.
from: http://wiki.micasaverde.com/index.php/Luup_Scenes_Events