Looking for help to read status change of device.

I’m trying to write a function that detects a devices status change then does something. Such as:
If light1 turns on
then do something
if light1 turns off
then do something
if light 2 turns on…

I see the function “variable_watch” with parameters “function_name (string), service (string), variable (string or nil), device (string or number)”. So for light1 on (call it device 1), would it be:

luup.variable_watch("checkLights1","urn:upnp-org:serviceId:SwitchPower1", "Status", 1)

function checklights1 (lul_device, lul_service, lul_variable, lul_value_old, lul_value_new)
local new = lul_value_new
local old = lul_value_old

If new > old then
do what you do when light turns on
else
do what you do when light turns off
end

I would then repeat the same for light2, light3, etc.

Yep … or use the Program Logic Event Generator plugin and use the Input then Device Properties menu.

Is PLEG only for scenes or can you use it in a plugin as well? Also I am running ui4 and the “marketplace” doesn’t have everything on “apps”. Does PLEG work on ui4?

Thanks for confirming the code.

Sorry … it probably could be made too … but I have no system to test with … and it would be too difficult to test remotely.

Motivation for you to move up … I have another nice roll out for PLEG next week.

I’m running a vera1. Don’t think it is possible.