Scene with two trigger

Hi all,

I want to Put on the light for 30 second when Outisde light <80 Lux and Security sensor is tripped
So I create a scene with this lua code, but nothing append…

So I need your help (it’s my first scene with lua and activating a device)
Is this code correct ? And how schould I build my scene ?

local luxgrenier = luup.variable_get(“urn:micasaverde-com:serviceId:LightSensor1”,“CurrentLevel”,39)
local tripped_bedroom = luup.variable_get(“urn:micasaverde-com:serviceId:SecuritySensor1”, “Tripped”, 42)
local allow = true
return (((tripped_bedroom == “1”) and (luxgrenier < “80”)) == allow)

Thanks for your help !

what triggers the scene?
the code will not run if the scene is not triggered
Try triggering with one device and have the code check the other.

There is a great vera plugin called reactor that will do all this for you and is more reliable than scenes, which often fail due to luup reloads.

1 Like

I use the security sensor to trigger the scene
But after that I don’t now exacly how it works…is the lua code exectued before the action ?

Or should I also do the action by lua code ? (in thaht case, on don’t know how to wait 30 second before the nexte action)

when you select your triggers there is a button that looks like an L this opens the widow above, any code here is run before other scene lua code, and actions last, if the code returns false the scene will stop.
http://wiki.micasaverde.com/index.php/Luup_Scenes_Events

1 Like

I second @ElCid reactor suggestion, youll tackle this problem in 20 seconds with reactor vs Lua

3 Likes

Hi @cwoessner,

Try using the sensor tripped as the trigger for your scene, and then put only the test for lux < 80 in the Scene Lua. The Lua code of a scene is only executed when the scene triggers.

Cheers Rene

I try this but it doesn’t work…

local luxgrenier = luup.variable_get(“urn:micasaverde-com:serviceId:LightSensor1”,“CurrentLevel”,39)
local allow = true
return ( luxgrenier < “80” == allow)

With this code, light goes on whether we are or not under 80

You are comparing strings
return tonumber(luxgrenier) < 80 ? true : false
https://www.lua.org/pil/3.2.html
http://lua-users.org/wiki/TernaryOperator

While you’re at it, take a look at this post

Thanks to all, now with your help, everything for fine. And yes Allow is a part of code i found on this forum. I will also have a look on Reactor which seems to be an intrestting plugin (even if I don’t want to be to much depend on plugin…because with the time, plugin became obsolete if the author stop to update them… See my post about RGB plugin who didn’t work with new Fibaro without changes on the code)

And to finish, I really appreciate this forum as threre is lot of people who help to fight problem!

1 Like

Reactor will not go obsolete as it does not depend on an external api or on some devices firmware. It’s one plugin that replaces the vera scenes, and is far better at handling luup reloads. You will not regret using it.

It also run under openLuup, so will have a life beyond Vera (I think/hope that the author @rigpapa will agree!)

1 Like