I am trying to script my DSC alarm to come on a schedule should I forget to turn it on at night. It checks to see if some lights are on in the house first before turning on the alarm that way if I’m up and about I don’t set it off by accident.
I have tried writing it two ways and failed both. The first one when I script the alarm to turn on and the second one where the scene returns true if the conditions are met and using the advanced section to arm the alarm.Anyone see anything blatantly obvious with what I have written?
First option:
local Family_dining=luup.variable_get(“urn.upnp-org:serviceId:SwitchPower1”,“Status”,37)
local Staircase_light=luup.variable_get(“urn.upnp-org:serviceId:SwitchPower1”,“Status”,24)
local alarm=45
local DSC_sid=“urn:micasaverde-com:serviceId:DSCAlarmPartition1”
local alarmset=luup.variable_get(DSC_sid,“ArmModeNum”,alarm)
if (Family_dining==“0”) and (Staircase_light==“0”) and (alarmset==“0”) then
luup.call_action(DSC_sid,“RequestQuickArmMode”, {State=“Stay”}, alarm)
End
Second Option:
local Family_dining=luup.variable_get(“urn.upnp-org:serviceId:SwitchPower1”,“Status”,37)
local Staircase_light=luup.variable_get(“urn.upnp-org:serviceId:SwitchPower1”,“Status”,24)
local alarm=45
local DSC_sid=“urn:micasaverde-com:serviceId:DSCAlarmPartition1”
local alarmset=luup.variable_get(DSC_sid,“ArmModeNum”,alarm)
if (Family_dining==“0”) and (Staircase_light==“0”) and (alarmset==“0”) then
Return true
Else
Return False
local alarm=45
if you are setting a variable, don’t include the “local” and i’m not sure that device numbers are numbers or strings
try…
alarm=‘45’
or, even better if you just put the device number into your sets and actions
e.g.
local alarmset=luup.variable_get(DSC_sid,“ArmModeNum”,alarm)
is clearer as
local alarmset=luup.variable_get(DSC_sid,“ArmModeNum”,45)
I can’t see any glaring errors in your luup but I suspect that your problem will be with:
local DSC_sid="urn:micasaverde-com:serviceId:DSCAlarmPartition1"
local alarmset=luup.variable_get(DSC_sid,"ArmModeNum",alarm)
I don’t have a DSC plugin so I can’t check but are you sure you have the service ID and variable name correct? If not this will likely return a nil. You could add the statement:
luup.log("alarmset = " .. alarmset) after the variable_get to check the returned result. This will write into the LuaUPnP.log file. See Logs.
WAIT - I spotted the problem. Change the code to:
[code]local Family_dining=luup.variable_get(“urn:upnp-org:serviceId:SwitchPower1”,“Status”,37)
local Staircase_light=luup.variable_get(“urn:upnp-org:serviceId:SwitchPower1”,“Status”,24)
local alarm=45
local DSC_sid=“urn:micasaverde-com:serviceId:DSCAlarmPartition1”
local alarmset=luup.variable_get(DSC_sid,“ArmModeNum”,alarm)
if (Family_dining==“0”) and (Staircase_light==“0”) and (alarmset==“0”) then
luup.call_action(DSC_sid,“RequestQuickArmMode”, {State=“Stay”}, alarm)
End[/code]
You had periods after urn instead of colons in the first two luup.variable_get(…) calls.
So I tried to add some log statements to see what was going on and got the following error:
01 12/19/13 19:12:44.985 LuaInterface::CallFunction_Scene Scene 33 failed [string “function scene_17()…”]:57: attempt to concatenate local ‘Family_dining’ (a nil value) <0x2f1b5680>
On the flip side I removed some parenthesis and it seems like it is working now, new code below, even though it appears to be working I’d like to understand why the logging isn’t working and why the removal of the parenthesis worked. I doing the following command when debugging “tail -f LuaUPnP.log | grep ‘^01|^50’”
:
local Family_dining=luup.variable_get(“urn.upnp-org:serviceId:SwitchPower1”,“Status”,37)
luup.log("Family_dining = " … Family_dining)
local Staircase_light=luup.variable_get(“urn.upnp-org:serviceId:SwitchPower1”,“Status”,24)
local alarm=45
local DSC_sid=“urn:micasaverde-com:serviceId:DSCAlarmPartition1”
local alarmset=luup.variable_get(DSC_sid,“ArmModeNum”,alarm)
luup.log("alarmset = " … alarmset)
if Family_dining==“0” and Staircase_light==“0” and alarmset==“0” then
return true
else
return false
end
Okay scratch it working right, it isn’t evaluating the if statement correctly.
I spotted the error. See modified response above.
Rex,
Thanks so much, I was just about to respond back to the forum that I found it when the email came in about a response to the post. I can’t believe I typed a ‘.’ instead of a “:”. Frustrating. I like how you wrote the code with the quickarm function, I may modify my code to match yours exactly.
Thank you very much for the help!
I’m glad to hear it is working now.
Debugging luup in scenes can be very frustrating but it is possible to make it a lot easier: Ask Santa Claus to buy you a licence for ZeroBrane Studio. It would be much more useful than another shirt or pair of slippers. ;D