We have moved at community.getvera.com

Author Topic: Scene Day/Night automatic  (Read 4705 times)

Offline Bric

  • Jr. Member
  • **
  • Posts: 66
  • Karma: +1/-0
Scene Day/Night automatic
« on: July 21, 2014, 05:44:20 pm »
Hi,

I want to create a scene where i turn on home theater , and the selected lights ONLY if it's dark.
I have the home theater turned on by luup code. it works great already.

Sorry , more simple:
If I create a scene like this:
Name: Turn on lights
I will turn lights 1 and 5 for example only at day. I only want it turns on the lights , IF it is between  6:00pm and 6:00am. (at night)

In case i touch the "Turn on light" at 1:pm for example, it doesn't turn light on , because its is day.

How can i do this ?


Offline Z-Waver

  • Master Member
  • *******
  • Posts: 4437
  • Karma: +249/-120
Re: Scene Day/Night automatic
« Reply #1 on: July 21, 2014, 07:14:57 pm »
You need to include this line in your scene.
Code: [Select]
return luup.is_night() == trueIt will cause the scene to run only if the present time is between sunset and sunrise a.k.a. night. Search the forums for more details about it.

If you want to specify some other time frame, besides sunset to sunrise, you will need to use a plugin like PLEG.

Offline Bric

  • Jr. Member
  • **
  • Posts: 66
  • Karma: +1/-0
Re: Scene Day/Night automatic
« Reply #2 on: July 21, 2014, 08:30:18 pm »
You need to include this line in your scene.
Code: [Select]
return luup.is_night() == trueIt will cause the scene to run only if the present time is between sunset and sunrise a.k.a. night. Search the forums for more details about it.

If you want to specify some other time frame, besides sunset to sunrise, you will need to use a plugin like PLEG.

But this will cause the entire scene to run or not, right?
because i have on this scene the lights and a luup command to turn on my home theater by harmony hub.
That's what i want:
ALWAYS turn on the hometheater
ONLY turns on lights if is between sunset and sunrise.


Offline srvan1

  • Newbie
  • *
  • Posts: 18
  • Karma: +1/-0
Re: Scene Day/Night automatic
« Reply #3 on: July 21, 2014, 09:15:01 pm »
Hi,

In case i touch the "Turn on light" at 1:pm for example, it doesn't turn light on , because its is day.

How can i do this ?

You mean you want the system not to respond to you turning it on at 1 PM? I am new to micasa, too, but base on my understand, turning it on would create an event, you could then immediately have a luup code to turn off if it is within the time frame you specified. I do not know of any code or workaround to prevent a device from firing up altogether.

Offline Bric

  • Jr. Member
  • **
  • Posts: 66
  • Karma: +1/-0
Re: Scene Day/Night automatic
« Reply #4 on: July 21, 2014, 09:22:14 pm »
Hi,

In case i touch the "Turn on light" at 1:pm for example, it doesn't turn light on , because its is day.

How can i do this ?

You mean you want the system not to respond to you turning it on at 1 PM? I am new to micasa, too, but base on my understand, turning it on would create an event, you could then immediately have a luup code to turn off if it is within the time frame you specified. I do not know of any code or workaround to prevent a device from firing up altogether.


Will try to explain my scene:
I have a scene called Watch TV.
When i touch it, it turns on 2 lights AND turns on my hometheater (receiver, tv, tv box)
I have a logitech harmony hub that receive the command to start from vera , by luup command.
the luup command is already inside the scene.

I want :
 if it is night ok, the scene can full run. (luup comand and lights)
if it is day, only the luup command to harmony hub is sent. (the lights dont turn on)

Offline srvan1

  • Newbie
  • *
  • Posts: 18
  • Karma: +1/-0
Re: Scene Day/Night automatic
« Reply #5 on: July 21, 2014, 09:38:39 pm »
Hi,

I want :
 if it is night ok, the scene can full run. (luup comand and lights)
if it is day, only the luup command to harmony hub is sent. (the lights dont turn on)

I am assuming you can control the lights with micasa since they are zwave switches, if that is the case then why not put an if statement to check for is it night as Z-Waver suggested luup.is_night(), if it is, then turn on the lights, else do nothing, and outside the if statement, you could have the code to fire up your harmony hub as you indicated above.

---your scene (pseudocode)
--a bunch of codes
.
.
if night, lights on
end if
--fire up harmnoy hub
end scene

Is that what you had in mind or did we misunderstand you?
« Last Edit: July 21, 2014, 09:53:37 pm by srvan1 »

Offline Bric

  • Jr. Member
  • **
  • Posts: 66
  • Karma: +1/-0
Re: Scene Day/Night automatic
« Reply #6 on: July 21, 2014, 10:30:36 pm »
Hi,

I want :
 if it is night ok, the scene can full run. (luup comand and lights)
if it is day, only the luup command to harmony hub is sent. (the lights dont turn on)

I am assuming you can control the lights with micasa since they are zwave switches, if that is the case then why not put an if statement to check for is it night as Z-Waver suggested luup.is_night(), if it is, then turn on the lights, else do nothing, and outside the if statement, you could have the code to fire up your harmony hub as you indicated above.

---your scene (pseudocode)
--a bunch of codes
.
.



Is that what you had in mind or did we misunderstand you?

Yes, you are right!
i copied the command line that z waver posted and changed my location to another city (that is day now), but doens t worked.
It keeps turning on both hometheater and lights.
I think i have to input another command on luup.
 
the luup command is like this now:

return luup.is_night() == true
os.execute HarmonyHubControl login password start_activity_xxx

Offline srvan1

  • Newbie
  • *
  • Posts: 18
  • Karma: +1/-0
Re: Scene Day/Night automatic
« Reply #7 on: July 21, 2014, 11:57:42 pm »

return luup.is_night() == true
os.execute HarmonyHubControl login password start_activity_xxx

What is the line of code that turns on your lights?

Assuming what you have now work just fine, besides the light issue.

Have that (or those lines) inside this code below...

if (luup.is_night()) then
... your code to turn on the lights you want when it is night
end

That should do what you asked.

Offline Z-Waver

  • Master Member
  • *******
  • Posts: 4437
  • Karma: +249/-120
Re: Scene Day/Night automatic
« Reply #8 on: July 22, 2014, 07:45:09 am »
@Bric - I did not realize that you wanted partial scene execution. I understand now. As @srvan1 has described, wrapping the turn Off lights section of the scene in an IF statement with the luup.isnight() function would work as you seem to want.

Code: [Select]
if (luup.is_night()) then
luup.call_action("urn:upnp-org:serviceId:SwitchPower1", "SetTarget", {newTargetValue = "1"}, 55)
end

I would however, recommend that you look at PLEG for this. It will allow you to accomplish this scene far more easily than writing this LUA code and also provide other fine grained time options besides just sunset to sunrise.


Offline aa6vh

  • Hero Member
  • *****
  • Posts: 642
  • Karma: +15/-0
Re: Scene Day/Night automatic
« Reply #9 on: July 22, 2014, 10:28:33 am »
Another option that may be easier to maintain:

Create two scenes, one that turns on your home theater, the other that turns on your lights. You will need to find out the scene number for the lights scene.

Include the following code in your Home Theater scene (code assumes light scene is scene #6):

Code: [Select]
if luup.is_night() then
  local lul_args = {}
  lul_args["SceneNum"]="6"
  luup.call_action("urn:micasaverde-com:serviceId:HomeAutomationGateway1","RunScene",lul_args,0)
end

Now all you have to do to watch TV is run the Home Theater scene.
« Last Edit: July 22, 2014, 10:39:03 am by aa6vh »

Offline Bric

  • Jr. Member
  • **
  • Posts: 66
  • Karma: +1/-0
Re: Scene Day/Night automatic
« Reply #10 on: July 22, 2014, 11:06:30 am »
srvan1, z waver, aa6vh.

Thanks for the help, but i don't know what i'm doing wrong.

I have just tested what aav6vh said.
I made 2 changes to my scene:

1- Copied this to to luup scene:
if luup.is_night() then
  local lul_args = {}
  lul_args["SceneNum"]="6"
  luup.call_action("urn:micasaverde-com:serviceId:HomeAutomationGateway1","RunScene",lul_args,0)
end

I verified that the scene number is 7 that i want. So i changed lul_args["SceneNum"]="6"  to  ="7"
I'm at Brasil, so i changed my location on mcv ui5 to tokio (now it's night there).

2- I deleted the lights going on on this scene, because of course, the luup command is supposed to turn the lights on if it's night.

The hometheater starts , but no lights going on.


Zwaver,  i installed the pleg, but i don't know how to use it.

Srvan1, i tested yesterday what you said, and didn't worked too.



Offline srvan1

  • Newbie
  • *
  • Posts: 18
  • Karma: +1/-0
Re: Scene Day/Night automatic
« Reply #11 on: July 22, 2014, 11:42:11 am »
Bric, would you happen to know the Device IDs of the lights you want to turn on? Not the scene ID ok, but the actual device you want to turn on.

Offline Bric

  • Jr. Member
  • **
  • Posts: 66
  • Karma: +1/-0
Re: Scene Day/Night automatic
« Reply #12 on: July 22, 2014, 01:37:39 pm »
Bric, would you happen to know the Device IDs of the lights you want to turn on? Not the scene ID ok, but the actual device you want to turn on.

ok, i saw that now.  the device id (not scene id) number 7 is another light.
This light doesnt turn on too.

i dont need to have any plugins to do this. right?

Offline aa6vh

  • Hero Member
  • *****
  • Posts: 642
  • Karma: +15/-0
Re: Scene Day/Night automatic
« Reply #13 on: July 22, 2014, 02:15:37 pm »
I would suggest trying a couple of experiments:

1. Does your light scene operate correctly when run manually?

2. If you temporarily remove the "is_night" line (and the corresponding "end"), so that the light scene is run every time you run the first scene, does it work?

If 1 and 2 are true, then it would suggest that your "is_night" is not working, which is prossibly due to having a bad location set in Vera.
« Last Edit: July 22, 2014, 02:18:03 pm by aa6vh »

Offline srvan1

  • Newbie
  • *
  • Posts: 18
  • Karma: +1/-0
Re: Scene Day/Night automatic
« Reply #14 on: July 22, 2014, 03:45:00 pm »

i dont need to have any plugins to do this. right?

No you don't need any plugins.

Let me ask you this, did you write that scene yourself or with some help? What I want to know is do you have the luup line of code that actually turns on your light?

Since you already changed your location to a different area, I am assuming you know how to change it back so now you are in the right location.

It all boils down to, what is the actual line of code in your scene that you use to turn on the light, paste it here so we could see it. If you could provide that line of code, you are one step closer to having what you asked for initially.