I am creating a scene in LUA/LUUP in order to turn off a ligth after 10 seconds.
I’m using a FIBARO Walli Outlet.
To do this, I went to Scenes → Add Scene → Manual (no Step 1) → Next Step (no Step 2) → Also, run the following Luup code: No Luup Code Defined (Step 3).
local status = luup.variable_get(“urn:upnp-org:serviceId:SwitchPower1”, “Status”,DeviceID)
if (status == “1”)then
luup.call_delay(“delayOff”,3)
end
– Main code terminates at this point
– Function to be called after delay
function delayOff()
luup.call_action(“urn:upnp-org:serviceId:SwitchPower1”,“SetTarget”,{ newTargetValue=0},DeviceID)
end"
My idea with this code is:
Call the scene to run always
Check Switch Status
If on, call the delay function
Now my problem:
The scene code only runs when I press the “run” botton in the scene menu. What i need to do or change to the scene run alone?
Set the outlet as trigger, when on → scene runs. Maybe I’m missing the point here but this can be done with no code at all as the built in scene creation has a delayed action. Scene triggers when outlet is on, add delayed action to turn the outlet off.
Hi,
I know it’s possible but I’d really like to do it in LUA/LUUP because I want to understand better the “power” of this language. My problem is actually that the scene only runs when i press the run botton…
I’m still learning too, since scenes need a trigger perhaps luup.variable_watch in startup lua is the way to go then?
I don’t have the answer, just providing hints on how I would proceed if I wanted to complicate things
@therealdb Hi! How are you? I’ve been searching around the forum and I’ve already found some very useful posts and comments from you. Do you have 5 minutes to see my problem and see in general what I might be doing wrong? Thanks a lot
Variable watch is OK if you want to do it in code. The scene is not necessary. There are plenty of examples in the forum and the wiki have a couple more. Just watch for status and if is 1, start the delay.
Hi! The code I published here works. My problem is that the scene i created only runs when I press the RUN button. I wanted it to work 24 hours a day and not just when I press the button. TY
Edit your scene:
Change from ‘Manual’ to ‘Device’
Select the trigger as the light that you are interested in, when it comes on, then it can run your Lua code
Best Home Automation shopping experience. Shop at Ezlo!