We have moved at community.getvera.com

Author Topic: Disable a scene for next 24 hours  (Read 2153 times)

Offline HouseBot

  • Full Member
  • ***
  • Posts: 210
  • Karma: +1/-1
Disable a scene for next 24 hours
« on: October 26, 2011, 02:43:23 pm »
How can I create a scene or the luup code so that when I run the scene in the morning it will disable one scene scheduled later that day (but only once, not forever)?

Offline mcvflorin

  • Administrator
  • Hero Member
  • *****
  • Posts: 1755
  • Karma: +11/-3
Re: Disable a scene for next 24 hours
« Reply #1 on: October 28, 2011, 12:10:49 pm »
Put this code in the scene that disables the other scene:

Code: [Select]
local disableSceneFlag = luup.variable_get ("urn:micasaverde-com:serviceId:DisableSceneFlag1", "DisableSceneFlag", 0) or ""
if (disableSceneFlag == "") then
    luup.variable_set ("urn:micasaverde-com:serviceId:DisableSceneFlag1", "disableSceneFlag", "1", 0)
end

And this code in the scene that must be disabled once:

Code: [Select]
local disableSceneFlag = luup.variable_get ("urn:micasaverde-com:serviceId:DisableSceneFlag1", "DisableSceneFlag", 0)
if (disableSceneFlag == "1") then
    luup.variable_set ("urn:micasaverde-com:serviceId:DisableSceneFlag1", "disableSceneFlag", "0", 0)
    return false
end

return true

This whole setup works only once. If you need to repeat this regularly you need to manually delete the DisableSceneFlag variable.

Offline guessed

  • Community Beta
  • Master Member
  • ******
  • Posts: 5301
  • Karma: +92/-22
  • Release compat is not a bolted-on afterthought
Re: Disable a scene for next 24 hours
« Reply #2 on: October 29, 2011, 02:19:02 pm »
I would also shoot for using a unique/new serviceId, one that doesn't use the urn:micasaverde-com namespace.

This'll make the Variable values stand out as something "custom" in the future, or if anyone runs diag on your Box.

Offline HouseBot

  • Full Member
  • ***
  • Posts: 210
  • Karma: +1/-1
Re: Disable a scene for next 24 hours
« Reply #3 on: November 01, 2011, 03:33:22 pm »
I'm sorry but I did not get it to work. How does this code look when the scene is disabled?

Code: [Select]
local disableSceneFlag = luup.variable_get ("urn:micasaverde-com:serviceId:DisableSceneFlag1", "DisableSceneFlag", 0)
if (disableSceneFlag == "1") then
    luup.variable_set ("urn:micasaverde-com:serviceId:DisableSceneFlag1", "disableSceneFlag", "0", 0)
    return false
end

return true

Quote
I would also shoot for using a unique/new serviceId, one that doesn't use the urn:micasaverde-com namespace.
Can you hint to any directions of what name spaces that I should use?

Offline mcvflorin

  • Administrator
  • Hero Member
  • *****
  • Posts: 1755
  • Karma: +11/-3
Re: Disable a scene for next 24 hours
« Reply #4 on: November 02, 2011, 03:19:15 am »
The code that goes in the scene that disables the other scene (let's call it scene A) checks if the DisableSceneFlag exists, and if it doesn't, it creates it with the value "1". If the flag exists, the code doesn't do anything.

The code that goes in the scene to be disabled (scene B) checks if the flag is "1". If it is, it sets the flag to "0" and the scene doesn't run. If it's not, the code doesn't do anything.

For the subsequent scene A runs, the flag will exist and it will be "0" or "1", which means that the code won't do anything. For the subsequent scene B runs, the flag will be "0", and again, the code won't do anything. So both scenes will run normally.

Deleting the flag will reset the whole setup.

Can you hint to any directions of what name spaces that I should use?

You can use something like this "urn:HouseBot:serviceId:DisableSceneFlag1".
« Last Edit: November 02, 2011, 03:23:32 am by mcvflorin »

Offline HouseBot

  • Full Member
  • ***
  • Posts: 210
  • Karma: +1/-1
Re: Disable a scene for next 24 hours
« Reply #5 on: November 02, 2011, 07:53:57 am »
I think my issue is to get the first scene to trigger the second scene. Atleast I can't get the Luup code to change. Is it under Events tab and Device: Scene Controller, or a'm I totally off?

Offline mcvflorin

  • Administrator
  • Hero Member
  • *****
  • Posts: 1755
  • Karma: +11/-3
Re: Disable a scene for next 24 hours
« Reply #6 on: November 02, 2011, 08:30:17 am »
The code must be placed in the scene's Luup Code input box. It won't change. Only the DisableSceneFlag will change, and it can be seen in the user_data.