Using Lua code in a scene to enable/disable a timer in another scene

@Ap15e, question is it possible to create a StateDevice that only has a light bulb (no On/Off Switch icon)? So that it can only be turned On/Of via Scenes or devices?

FYI to all
If you are using the DSC alarm plugin you have a virtual switch built into every zone…the Arm /Disarm is there but not used…it can be set to on or off in your Luup Code. It has the LED button display as well.
Regards
Tim Alls

I’m trying to do something similar to the original posts - I created a device based on Motion1. But it complains “failed to deliver message” when I try to arm/disarm. What code is needed to make it work?

In my case I have actual motion sensors that are “Tripped” data fed in externally via HTTP requests.

@Ap15e, question is it possible to create a StateDevice that only has a light bulb (no On/Off Switch icon)? So that it can only be turned On/Of via Scenes or devices?

Should be possible; any volunteer?

I’ve been thinking about it and talked about it with @JOD. Don’t know when thinking may turn into action. :-\

I just wanted to let you know this worked GREAT. I don’t know what I’m going to with my virtual devices yet, but I do have a similar scenario for guest quarters HVAC… thanks for the info!

Using Guard’s code, I’m trying to dump some Luup code into each of my timed scenes to prevent them from running when my virtual devices “GuestMode” OR “AwayMode” are ON using the following code:

[code]local AwayMode=6
local GuestMode=7

local AwayMode = luup.variable_get(“urn:upnp-org:serviceId:SwitchPower1”, “Status”, AwayMode)
local GuestMode = luup.variable_get(“urn:upnp-org:serviceId:SwitchPower1”, “Status”, GuestMode)

if (AwayMode == “0”) then
return false
else if (GuestMode == “0”) then
return false
end
return true[/code]

What’s the error in my syntax here?

It sounds like you’d want to return [tt]false[/tt] (i.e. abort the scene) when the [tt]Status[/tt] of either virtual device equals 1 (i.e. the device is on).

Also, for clarity, I’d rename the variables in the first 2 lines to [tt]AwayModeDevice[/tt] etc. Snippet:

local AwayModeDevice=6
local GuestModeDevice=7

local AwayMode = luup.variable_get("urn:upnp-org:serviceId:SwitchPower1", "Status", AwayModeDevice)
local GuestMode = luup.variable_get("urn:upnp-org:serviceId:SwitchPower1", "Status", GuestModeDevice)

Yes, that’s true… so I’ve tried this, but it doesn’t work either:

[code]local AwayModeDevice=6
local GuestModeDevice=7

local AwayMode = luup.variable_get(“urn:upnp-org:serviceId:SwitchPower1”, “Status”, AwayModeDevice)
local GuestMode = luup.variable_get(“urn:upnp-org:serviceId:SwitchPower1”, “Status”, GuestModeDevice)

if (AwayMode == “1”) then
return false
else if (GuestMode == “1”) then
return false
end
return true[/code]

???

[tt]else if[/tt] → [tt]elseif[/tt]

Or an alternative:

if (AwayMode == "1") or (GuestMode == "1") then
    return false
else
    return true
end

Worked great… final code:

[code]local AwayModeDevice=6
local GuestModeDevice=7

local AwayMode = luup.variable_get(“urn:upnp-org:serviceId:SwitchPower1”, “Status”, AwayModeDevice)
local GuestMode = luup.variable_get(“urn:upnp-org:serviceId:SwitchPower1”, “Status”, GuestModeDevice)

if (AwayMode == “1”) or (GuestMode == “1”) then
return false
else
return true
end[/code]

:smiley:

OK… while the code works (“message sent” in testing), for whatever reason, my timers will not trigger the scenes with the code in the Luup tab! I’m at a loss. Up to this point, everything was making sense (things were working before I messed with code, or the code was broken and I knew it). Now the code works, but the scenes aren’t triggered by my timers.

If you remove the code, do they trigger the scenes?
Are you sure the [tt]AwayModeDevice[/tt] and [tt]GuestModeDevice[/tt] are both off (‘0’)?

Yes, and yes. Or, at least, the scenes triggered just fine before I entered the code.

I’m going to remove the code from each scene to see if my afternoon timer works… pasting here to hang onto it for later:

[code]local AwayModeDevice=6
local GuestModeDevice=7

local AwayMode = luup.variable_get(“urn:upnp-org:serviceId:SwitchPower1”, “Status”, AwayModeDevice)
local GuestMode = luup.variable_get(“urn:upnp-org:serviceId:SwitchPower1”, “Status”, GuestModeDevice)

if (AwayMode == “1”) or (GuestMode == “1”) then
return false
else
return true
end[/code]

“AwayMode” and “GuestMode” are both off. I just tested the code above and it came back “message sent successful”. I’ll set my timer for 12:05 and see what happens.

The timer DID NOT EXECUTE the scene, even with no code in the Luup tab. Argh. I’ve deleted the timer & created a new one for 12:50.

I found the trouble. It wasn’t with the code, it wasn’t with the timer… it was the command.

The CA8900 thermostat doesn’t have an “AUTO”. If I send it an “AUTO” command (instead of COOL or HEAT), it doesn’t do anything. The scene only executes the thermostat setpoint if I also send it a “COOL” or a “HEAT”. That’s crap. That means I’ll need to change it twice a year (at least), unless I come up with a way to check the ambient temperature to determine whether to send a COOL or a HEAT.

In another discussion string on this forum, we developed a lua script for a scene to turn off my AC if any door or window sensor was tripped for more than 1 minute. Currently, this scene runs every 5 min. I would like to run this script only when my home is occupied. I have another scene which sets my OCCDevice’s (virtual state device) status to “1” when my home is occupied. Do I just insert the lua script segment below at the top of the other script, which controls my AC? If the beginning of the modified AC script returns false, will the script abort?

local OCCDevice = 45
local OCCStatus = luup.variable_get(“urn:micasaverde-com:serviceId:SecuritySensor1”,“Armed”,OCCDevice)
if (OCCStatus == “0”) then
return false
end
return true

The script ends on the first return command. So if you return false, the rest of the script won’t be executed.

[quote=“DeltaNu1142, post:36, topic:165164”]I found the trouble. It wasn’t with the code, it wasn’t with the timer… it was the command.
The CA8900 thermostat doesn’t have an “AUTO”. If I send it an “AUTO” command (instead of COOL or HEAT), it doesn’t do anything. The scene only executes the thermostat setpoint if I also send it a “COOL” or a “HEAT”. That’s crap. That means I’ll need to change it twice a year (at least), unless I come up with a way to check the ambient temperature to determine whether to send a COOL or a HEAT.[/quote]
In the interest of closing this question, please see the code in this thread. It will do what I’ve highlighted in bold above.

In helping me solve a problem with my scenes not running, MCVFlorin corrected my script so that now it works properly:

local OCCStatus = luup.variable_get(“urn:upnp-org:serviceId:VSwitch1”, “Status”, OCCDevice) or “0”
if (OCCStatus == “0”) then
return false
else
return true
end

Thanks
MCVFlorin!!!