why does this luup not work?

I want to use the following code but it gives an error whivch i cannot explain.

local status = luup.variable_get("urn:rts-services-com:serviceId:DayTime","Status",59)
local skipdim = luup.variable_get("urn:upnp-org:serviceId:VSwitch1","Status",68)
local away = luup.variable_get("urn:upnp-org:serviceId:VSwitch1","Status",69)
if (tonumber(status)== 1) and (tonumber(away) == 0) and (tonumber(skipdim) == 0)
then
  return true
end
return false

It errors on retrieving the DayTime virtual switch.

When i use only the check for the daytime switch it gives also an error.

I already tried and other code which i found in the tutorial in this forum but this also errors when i try to retrieve the status of day/night.

What i want to achieve is the following:

I want that the lights in my home are turned on on the following conditions:

  • motion sensor is tripped
  • away and/or skip buttons are turned OFF
  • it is evening

I don’t know if i can achieve this by simple scene/luup scripting, maybe someone has an better idea how to get this to work.

There are no errors in your code - assuming you have used the correct device numbers. If you are testing this in Test Luup code (Lua) it will flag an error when your code returns false. This can be very confusing.

I offer LuaTest as an alternative.

I assume you are triggering the scene based on motion.

I want that the lights in my home are turned on on the following conditions: - motion sensor is tripped - away and/or skip buttons are turned OFF - it is evening

You coded this as:
away AND skip buttons are turned OFF

Maybe you have a wrong deviceID.

yes triggered by motion :slight_smile: and id’s are correct.

The lua test gives an error, my vera also give a lua startup error on this code.
When i remove the code for daynight is gives no error and runs, but as soon as i use the daynight part it errors.
When i only use the daynight part is also errors and does not run…

The code should not cause any errors. Even if DayTime does not exist or the device number is wrong it would simply return nil. How are you writing it into Test Luup code (Lua)?

exactly as in my code in my post.

When i use it in a scene vera errors with a lua startup on the top of the page.

See if this is any different:

local status = luup.variable_get("urn:rts-services-com:serviceId:DayTime","Status",59) local skipdim = luup.variable_get("urn:upnp-org:serviceId:VSwitch1","Status",68) local away = luup.variable_get("urn:upnp-org:serviceId:VSwitch1","Status",69) if (tonumber(status)== 1) and (tonumber(away) == 0) and (tonumber(skipdim) == 0) then return true end return false

result: code failed…

But it see no different is this code as in mine which i posted…

[quote=“B3rt, post:8, topic:180564”]result: code failed…

But it see no different is this code as in mine which i posted…[/quote]
If you remove the last line (return false) does it still fail?

nope, then it gives no error.

But then the scene runs when it should not

When you put the code in the scene, include the return false. I only suggested removing it so that you could test the code in Test Luup code (Lua). It does not differentiate between code errors and return false. This is why I don’t use it.

It seems we have fixed the problem by correcting the wrap-around of your then.