Author Topic: Allow light switch to cancel a running scene  (Read 425 times)

Offline jrweiland

  • Sr. Newbie
  • *
  • Posts: 40
  • Karma: +0/-0
Allow light switch to cancel a running scene
« on: March 14, 2018, 02:13:54 pm »
I currently have a morning wake-up scene where my bedroom light slowly grows brighter and brighter to wake me up.

My bedroom light hooked to Aeotech Dimmable Light, which I control with a connected rocker switch.

The scene begins by turning light on to 5%, and then the scene has multiple delayed actions where the light gets brighter by about 20% every minute until it's at 100%.  Then it returns to 0% after about 10 mins.

Here's my question:  is there a way to insert LUUP code into the scene, that would cause a tap of the light switch to completely terminate the scene while it's in the middle of running? 

Because currently, if I tap the bedroom light switch (to turn light off) in the middle of the scene, the light will just turn back on a few second later because of the multiple delayed actions to continually make the light brighter.

Would love your advice!  Thanks so much
« Last Edit: March 14, 2018, 02:16:12 pm by jrweiland »

Online akbooer

  • Master Member
  • *******
  • Posts: 5750
  • Karma: +246/-69
  • "Less is more"
Re: Allow light switch to cancel a running scene
« Reply #1 on: March 14, 2018, 04:00:34 pm »
You can't interrupt delayed actions.  You would have to refactor the scene to generate the ramp with a timer so that it could be abandoned at any time.
3x Vera Lite-UI5/Edge-UI7, 25x Fibaro, 23x TKB, 9x MiniMote, 2x NorthQ Power, 2x Netatmo, 1x Foscam FI9831P, 2x Philips Hue
Razberry, MySensors Arduino, HomeWave, AltUI, DataYours, openLuup, ZWay, ZeroBrane Studio.

Online jswim788

  • Hero Member
  • *****
  • Posts: 644
  • Karma: +40/-2
Re: Allow light switch to cancel a running scene
« Reply #2 on: March 15, 2018, 01:45:30 pm »
You can't interrupt delayed actions.  You would have to refactor the scene to generate the ramp with a timer so that it could be abandoned at any time.
But couldn't the function called by the luup.call_delay itself check to see if something has changed and skip the action?  I.e., the delay still occurs, but on wake up the called action does a check for an interruption.  Not saying this is a good solution, just curious.

Online akbooer

  • Master Member
  • *******
  • Posts: 5750
  • Karma: +246/-69
  • "Less is more"
Re: Allow light switch to cancel a running scene
« Reply #3 on: March 15, 2018, 03:30:56 pm »
I presume we are talking about a scene with actions at different delays.  There is no luup.call_delay(), that's the way you'd have to refactor it if you wanted to address the situation.

This is the reason that it's almost always a bad plan to use actions with long delays.  Plus the fact that they'll fail if there's an intervening Luup restart.
3x Vera Lite-UI5/Edge-UI7, 25x Fibaro, 23x TKB, 9x MiniMote, 2x NorthQ Power, 2x Netatmo, 1x Foscam FI9831P, 2x Philips Hue
Razberry, MySensors Arduino, HomeWave, AltUI, DataYours, openLuup, ZWay, ZeroBrane Studio.

Offline Drex

  • Sr. Newbie
  • *
  • Posts: 26
  • Karma: +0/-0
Re: Allow light switch to cancel a running scene
« Reply #4 on: March 15, 2018, 03:54:47 pm »
Why not create a dummy switch runlighton .

when the wake up is started set it on.

Before each delayed action use if then to run each delayed action?

If (runlightswitch) then increase more

If (runlightswitch) then increase more 2
Etc


Set up a LUA code when you turn off light via rocker  to set the runlightswitch to off

It won?t turn on again via scene  until scene run again...


Then it will skip the delayed ramps until the next time you run the scene...


Online akbooer

  • Master Member
  • *******
  • Posts: 5750
  • Karma: +246/-69
  • "Less is more"
Re: Allow light switch to cancel a running scene
« Reply #5 on: March 15, 2018, 04:02:27 pm »
@Drex

Quote
Before each delayed action use if then to run each delayed action?

If (runlightswitch) then increase more

Where, exactly, were you proposing to put that code?
3x Vera Lite-UI5/Edge-UI7, 25x Fibaro, 23x TKB, 9x MiniMote, 2x NorthQ Power, 2x Netatmo, 1x Foscam FI9831P, 2x Philips Hue
Razberry, MySensors Arduino, HomeWave, AltUI, DataYours, openLuup, ZWay, ZeroBrane Studio.

Online jswim788

  • Hero Member
  • *****
  • Posts: 644
  • Karma: +40/-2
Re: Allow light switch to cancel a running scene
« Reply #6 on: March 15, 2018, 04:15:09 pm »
I presume we are talking about a scene with actions at different delays.  There is no luup.call_delay(), that's the way you'd have to refactor it if you wanted to address the situation.

This is the reason that it's almost always a bad plan to use actions with long delays.  Plus the fact that they'll fail if there's an intervening Luup restart.
Agree it's not the best plan, but I was guessing the original poster might have been referring to a Lua scene script such as this one by @Z-Waver: http://forum.micasaverde.com/index.php/topic,36273.msg270078.html#msg270078  I've seen similar scripts posted.  This could potentially be modified to check as desired.  We can see what @jrweiland says.

Offline jrweiland

  • Sr. Newbie
  • *
  • Posts: 40
  • Karma: +0/-0
Re: Allow light switch to cancel a running scene
« Reply #7 on: March 15, 2018, 09:58:48 pm »
I?m open to anything! Love the idea of one long drawn out ramp that can easily interrupted at any time. But I figured that couldn?t be done

All the spread out delayed actions were my clumsy workaround lol

Offline aa6vh

  • Hero Member
  • *****
  • Posts: 618
  • Karma: +13/-0
Re: Allow light switch to cancel a running scene
« Reply #8 on: March 16, 2018, 10:47:29 am »
Well if you are willing to do some coding in LUA, then you could accomplish what you want.

I have code that turns on my garage light for 5 minutes. If I press the scene button a second or third time, the time is extended. And if I press the scene button during those 5 minutes, then the time counter is reset.

Code: [Select]
function GarageTimer(stuff)
  gGarageTimer = gGarageTimer - 1
  if (gGarageTimer > 0) then
    luup.call_timer("GarageTimer", 1, "15", "", "")
  elseif (gGarageTimer == 0) then
    luup.call_action("urn:upnp-org:serviceId:SwitchPower1","SetTarget",{ newTargetValue="0" },37)
  end
end
if (gGarageTimer == nil) then
  gGarageTimer = 0
end
if (gGarageTimer <= 0) then
  luup.call_timer("GarageTimer", 1, "15", "", "")
end
if (gGarageTimer < 20) then
  gGarageTimer = 20
elseif (gGarageTimer < 40) then
  gGarageTimer = 40
elseif (gGarageTimer < 120) then
  gGarageTimer = 120
else
  gGarageTimer = 0
end

The function GarageTimer is envoked every 15 seconds, and restarts the call timer to call itself again.

You could have a variable that holds the ramp value, and modify that value as desired each time the GarageTimer function is called. To stop the ramping, simply set the gGarageTimer variable to 0, and set the light appropriately.

Hope this helps.

Offline Drex

  • Sr. Newbie
  • *
  • Posts: 26
  • Karma: +0/-0
Re: Allow light switch to cancel a running scene
« Reply #9 on: March 16, 2018, 03:50:13 pm »

@akboer

in a scene that runs at 6am...

sure, its not pretty, (but there is a lot about vera that is not pretty), and aa6vh has a great example of how to do it.

i have been tinkering with openhab2, and quite frankly, its rule logic is more programming oriented, and though its a PITA, could easily been done there and called back to the vera.

now that i have really started to tinker with both, its amazing what both VERA/mios and the openhab consortium have produced.  incredible!