Author Topic: Day Or Night Plugin  (Read 60619 times)

Offline RichardTSchaefer

  • Master Member
  • *******
  • Posts: 9417
  • Karma: +715/-130
    • RTS Services Plugins
Re: Day Or Night Plugin
« Reply #15 on: February 21, 2013, 08:46:17 pm »
In your scene ... instead of looking at luup.is_night
You would check the status of the day or night switch.
Lot's of code fragents out there on accessing a device's variables.

The benefit is that you can test your day and night logic without having to wait for Daytime or Nightine. 
My primary motivation for this was to be used by the Program Logic Event Generator and Program Logic Timer Switch plugins ... so that you would not need to learn and/or use LUUP code to get something useful done.

Offline Fitzy

  • Full Member
  • ***
  • Posts: 150
  • Karma: +0/-0
Re: Day Or Night Plugin
« Reply #16 on: February 22, 2013, 07:56:53 am »
Great Plugin

Thanks for making scene creation that little bit easier :-)

Offline Cor

  • Hero Member
  • *****
  • Posts: 1080
  • Karma: +4/-4
Re: Day Or Night Plugin
« Reply #17 on: February 22, 2013, 05:41:37 pm »
@RichardTSchaefer, ah ja , I get it ...... I can use this code , you gave me a couple of days ago :-)

Code: [Select]
autoscene = luup.variable_get("urn:upnp-org:serviceId:VSwitch1","Status",32)

if(autoscene=="1")then

return true
else
return false
end

where the 32 should be changed now into the device ID of this day-night switch.

1=night
0= day ?



I have just been playing with this plugin , but difficult to check..... I cannot get the sun to rise now here at midnight  ::)
Just to confirm if it is correct with the +/-   , I have attached a screenshot.
I want: day = sunrise-20 , night is sunset+20

Is it correct what i inserted?

thanks,
Cor
« Last Edit: February 22, 2013, 06:03:10 pm by Cor »

Offline Fitzy

  • Full Member
  • ***
  • Posts: 150
  • Karma: +0/-0
Re: Day Or Night Plugin
« Reply #18 on: February 22, 2013, 07:52:10 pm »
Maybe I jumped the gun just a little too quick :-/

To begin, I have the time and regions etc set correctly in my Vera 2 unit as I am using other scenes with the sunrise / sunset option with no problem.

I installed the day / night plugin and created a scene, with the help of the dsc alarm plugin, to turn a light on when the front door was opened and turn it off 30 seconds later.

When tested this all worked great - open the door, light turns on and 30 seconds later it switches off. But it was night.

I tested this morning, 9am, local time so def after sunrise, and the light still turns on when the door is opened.

What could I have done wrong? I was of the understanding that you use the day / night plugin in the usual way you do with all other devices when creating a scene - if you want it t run only at night click the night switch at the beginning of the scene creation and vice versa for day.

Any ideas?

Offline S-F

  • Hero Member
  • *****
  • Posts: 1248
  • Karma: +61/-12
  • Clueless N00b
Re: Day Or Night Plugin
« Reply #19 on: February 22, 2013, 08:23:53 pm »
@Scottf,

I imagine you are setting the plugin to night during scene creation on the tab with all of the other switches and lights and other associated doodads? What this is doing is setting the plugin to the "night" state. Even if it's daytime. As RTS has stated, you can simulate the opposite state of the Sun with this plugin for testing purposes...... which is what you're doing. What you want to do is a little more complicated. You want a dependency on the state of the Sun. Not to make the Sun set or rise.
My forum account was apparently hacked by a leprechaun. And he's drunk all of the time. If a post of mine seems a little off kilter, it's probably because he made it.

Offline Fitzy

  • Full Member
  • ***
  • Posts: 150
  • Karma: +0/-0
Re: Day Or Night Plugin
« Reply #20 on: February 22, 2013, 08:44:43 pm »
@Scottf,

I imagine you are setting the plugin to night during scene creation on the tab with all of the other switches and lights and other associated doodads? What this is doing is setting the plugin to the "night" state. Even if it's daytime. As RTS has stated, you can simulate the opposite state of the Sun with this plugin for testing purposes...... which is what you're doing. What you want to do is a little more complicated. You want a dependency on the state of the Sun. Not to make the Sun set or rise.

@ S F

Lol, thanks for that. Totally misread what is was designed to do :-p

So I have added luup.is_night option to the scene in question.

The light now doesn't turn on - which is good given it 10am. BUT

I used the day / night plugin to test the scene. I clicked night, the plugin went from day to night. I opened the door and nothing.

I had restarted / reloaded but still nothing.

I'm guessing I'm just going to have to wait until tonight to test it and uninstall the plugin.

:-/
« Last Edit: February 22, 2013, 09:03:25 pm by Scottf »

Offline S-F

  • Hero Member
  • *****
  • Posts: 1248
  • Karma: +61/-12
  • Clueless N00b
Re: Day Or Night Plugin
« Reply #21 on: February 22, 2013, 09:04:59 pm »

Hmmmm. Maybe and maybe not. As RTS has stated this plugin is designed to be used with his PL plugins. You could use one of them to create your scene in combination with this day/night plugin. If all you have is a simple scene which you only want to run at night I'd personally use luup.is_night. But that's just me. Even though I know squat about programming I have been using this LUUP code for a couple years and it's pretty simple.
My forum account was apparently hacked by a leprechaun. And he's drunk all of the time. If a post of mine seems a little off kilter, it's probably because he made it.

Offline Fitzy

  • Full Member
  • ***
  • Posts: 150
  • Karma: +0/-0
Re: Day Or Night Plugin
« Reply #22 on: February 22, 2013, 09:12:47 pm »

Hmmmm. Maybe and maybe not. As RTS has stated this plugin is designed to be used with his PL plugins. You could use one of them to create your scene in combination with this day/night plugin. If all you have is a simple scene which you only want to run at night I'd personally use luup.is_night. But that's just me. Even though I know squat about programming I have been using this LUUP code for a couple years and it's pretty simple.

I tend to agree; I'm certainly no programmer either but I just added the luup.is_night to the scene:

if ( luup.is_night() ) then
  return true
else
  return false
end

If it works, which so far so good (the light at least doesn't turn on during the day anymore) it was pretty dam easy and straightforward. Now just to wait until tonight to test it - EDIT: all works great.

Think I will just stick with that.

Thanks for your help and clarifying my stupid mistake :-p
« Last Edit: February 23, 2013, 07:50:20 am by Scottf »

Offline RichardTSchaefer

  • Master Member
  • *******
  • Posts: 9417
  • Karma: +715/-130
    • RTS Services Plugins
Re: Day Or Night Plugin
« Reply #23 on: February 23, 2013, 01:38:52 am »
Here are the details to use Day or Night instead of luup.is_night.
Benefits:
  1) You can add/subtract minutes from the sunrise/sunset that luup.is_night uses.
  2) You can test you  Night-time scenes during the day and/or day-time scenes at night without having to wait for the sun/moon to flip.

In your LUUP code:
DeviceID  = 32
local night = luup.variable_get("urn:rts-services-com:serviceId:DayTime","Status", DeviceID)
return  (night == '0')


Replace 32 with the Device ID of your Day or Night Instance.
This code pattern is useful for using ANY device variable in Vera as an on/off predicate for your scene.
Go to the Advanced Tab of the device you want to control the input of your scene.
Find a Device # (DayOrNight in this example).
Find the Variable (Status in this example).
Hover the mouse over the variable name (Status in this example) ... This will yield the Service Id Argument.
Put the appropriate condition test in the return statement.
If the return statement returns false the scene execution will be canceled.

In this case the Day or Night as a "0" zero status at night ... so the scene will proceed at night and cancel otherwise.

The Program Logic Event Generator plugins allow you to just select things from menus and not have to worry about function names, order of arguments, serviceIds ....



Offline Cor

  • Hero Member
  • *****
  • Posts: 1080
  • Karma: +4/-4
Re: Day Or Night Plugin
« Reply #24 on: February 23, 2013, 05:50:33 am »
Oh , my question has been buried a little bit. May I ask if someone can read this post , especially the last question with the screenshot.?

many thanks,
Cor
http://forum.micasaverde.com/index.php/topic,12806.msg103620.html#msg103620

Offline Fitzy

  • Full Member
  • ***
  • Posts: 150
  • Karma: +0/-0
Re: Day Or Night Plugin
« Reply #25 on: February 23, 2013, 08:14:29 am »
Here are the details to use Day or Night instead of luup.is_night.
Benefits:
  1) You can add/subtract minutes from the sunrise/sunset that luup.is_night uses.
  2) You can test you  Night-time scenes during the day and/or day-time scenes at night without having to wait for the sun/moon to flip.

In your LUUP code:
DeviceID  = 32
local night = luup.variable_get("urn:rts-services-com:serviceId:DayTime","Status", DeviceID)
return  (night == '0')


Replace 32 with the Device ID of your Day or Night Instance.
This code pattern is useful for using ANY device variable in Vera as an on/off predicate for your scene.
Go to the Advanced Tab of the device you want to control the input of your scene.
Find a Device # (DayOrNight in this example).
Find the Variable (Status in this example).
Hover the mouse over the variable name (Status in this example) ... This will yield the Service Id Argument.
Put the appropriate condition test in the return statement.
If the return statement returns false the scene execution will be canceled.

In this case the Day or Night as a "0" zero status at night ... so the scene will proceed at night and cancel otherwise.

The Program Logic Event Generator plugins allow you to just select things from menus and not have to worry about function names, order of arguments, serviceIds ....

@RichardTSchaefer

Thanks for the info.

Would there be any reason why when I tried to test a scene with luup.is_night in it by clicking on night in the day night plugin and running the scene nothing happens? The scene doesn't run. (it's night here now and the scene works as it should).

So, to clarify, for someone like myself with little exposure to programming, I get that the day night plugin can be used to test scenes by manually selecting day or night / making the system think its night when it's day and vice versa BUT I'm now not 100% clear on its use in scenes.

If we go by the info you provided in your reply will this allow the day night plugin to be used within a scene or do you think the program logic event generator would be more suitable?

I think I will check it out.

Again thanks


Offline RichardTSchaefer

  • Master Member
  • *******
  • Posts: 9417
  • Karma: +715/-130
    • RTS Services Plugins
Re: Day Or Night Plugin
« Reply #26 on: February 23, 2013, 09:58:49 am »
If you want to have the Day or Night plugin to enable/disable a Scene ... you would put the above 3 lines of code in the LUUP section of either the Trigger of the Scene (To cancel just this trigger) OR the Scene itself (to cancel any trigger).   In your case you probably only have one trigger so it does not matter where you put it.

So if the trigger for the Scene is Motion or a door trigger ... and the thee lines of code are used to cancel the trigger you can test your scene by walking around and/or opening a door while Day or Night indicates day and then while it indicates night.  The plugin will automatically change the switch at the appropriate time or the next reboot ... which ever happens first.

I recommend PLEG if you are not a programmers and down't want to become one to add any advanced logic into Vera.
The definition of Advanced for Vera is if you want to control a scene by anything other than the Logical OR of the inputs.

The problem statement here is:     Door opens AND its Night Time.

Most users would consider this Basic!

This problem is described as the Logical AND which by Vera's  definition constitutes being Advanced and prior to PLEG would requite you to use LUUP code.



Offline radarengineer

  • Sr. Member
  • ****
  • Posts: 402
  • Karma: +4/-0
Re: Day Or Night Plugin
« Reply #27 on: February 23, 2013, 10:07:23 am »
1=night
0= day ?

Is it correct what i inserted?

thanks,
Cor

Day == 1, Night == 0, so your code is backwards I believe. I think your time offset is correct. You want it to be day 20 min early and night 20 minutes later? So a day is 40 min longer overall?

I have a way of testing this for you but you have to wait a day. If you install EventGhost + my Vera Plugin for Eventghost and set Eventghost to log times, it will show you a timestamp for every device changing state (at least the ones I support, including this one). That only helps if you have a windows machine lying around.

Offline RexBeckett

  • Master Member
  • *******
  • Posts: 3888
  • Karma: +476/-10
Re: Day Or Night Plugin
« Reply #28 on: February 23, 2013, 10:15:41 am »
Oh , my question has been buried a little bit. May I ask if someone can read this post , especially the last question with the screenshot.?

many thanks,
Cor
http://forum.micasaverde.com/index.php/topic,12806.msg103620.html#msg103620

Your settings are correct for daytime to start 20 minutes before sunrise and end 20 minutes after sunset.

Offline RexBeckett

  • Master Member
  • *******
  • Posts: 3888
  • Karma: +476/-10
Re: Day Or Night Plugin
« Reply #29 on: February 23, 2013, 10:21:59 am »
Quote
Would there be any reason why when I tried to test a scene with luup.is_night in it by clicking on night in the day night plugin and running the scene nothing happens? The scene doesn't run. (it's night here now and the scene works as it should).
The override settings on Day or Night only affect it's own status - they have no effect on luup.is_night. If you use the Day or Night status in your code instead of luup.is_night, then the overrides will work correctly.