We have moved at community.getvera.com

Author Topic: Is this possible (Conditional)  (Read 1827 times)

Offline waynebrady

  • Full Member
  • ***
  • Posts: 110
  • Karma: +0/-0
Is this possible (Conditional)
« on: October 26, 2011, 03:01:49 am »
I have a scene to turn on the lights when my alarm (Vista 20p) is disarmed and it works like a charm. But I don't want the lights to turn on anytime before 7pm.

How can I achieve this?

Offline mcvflorin

  • Administrator
  • Hero Member
  • *****
  • Posts: 1755
  • Karma: +11/-3
Re: Is this possible (Conditional)
« Reply #1 on: October 26, 2011, 05:23:35 am »
Add this code in that scene:
Code: [Select]
local t = os.date ("*t")
if (t.hour <= 19) then
    return false
end

return true

The scene won't run if the code returns false, which in this case it happens only if the hour is less than 19. But I think that this code would be more appropriate for what you want:
Code: [Select]
return luup.is_night()

In this case the scene would run only at night.
« Last Edit: October 26, 2011, 05:26:08 am by mcvflorin »

Offline waynebrady

  • Full Member
  • ***
  • Posts: 110
  • Karma: +0/-0
Re: Is this possible (Conditional)
« Reply #2 on: October 26, 2011, 11:51:14 am »
Awesome. Where can I find useful code snippets like this?

Also, what time does luup.is_night() define as "night?"

Offline oTi@

  • Community Beta
  • Master Member
  • ******
  • Posts: 4041
  • Karma: +32/-6
  • UI what ?!
Re: Is this possible (Conditional)
« Reply #3 on: October 26, 2011, 02:29:14 pm »
Also, what time does luup.is_night() define as "night?"
Sunset through sunrise.
Dezwaved at the moment...

Offline mcvflorin

  • Administrator
  • Hero Member
  • *****
  • Posts: 1755
  • Karma: +11/-3
Re: Is this possible (Conditional)
« Reply #4 on: October 27, 2011, 06:40:21 am »
Awesome. Where can I find useful code snippets like this?

Here and here. Also, there are many useful scripts on the forum, especially in this section.