more G-Labs products

Author Topic: Onto creating an app.. Auto turn on/off a set of lights  (Read 3268 times)

November 14, 2014, 08:21:56 PM
Read 3268 times

Johnny H

  • **
  • Information
  • Jr. Member
  • Posts: 47
Hi,
sorry for all the questions, now that HG's up and running i'm like a school kid again lol.

like everyone I want to turn on the porch and garage scones on at sunset at turn them off at 10 pm

i created the applet based on the sample in the docs and was able to get it to work, except that i had to activate it manually via the module at the scheduled time, lol . So i'm not even sure if this is where the applet should be placed. (in the group)

So I changed the code up a little:

Program Code:
Code: [Select]
var porchLights = Modules.InGroup(PROGRAM_OPTIONS_STRING).OfDeviceType("Dimmer,Light");

    porchLights.On();
Net.SendMessage("[email protected]", "Porch Lights Turned On", "Porch Lights were turned on at sunset." );


Trigger Code:
Code: [Select]
Program.Setup(()=>
{                 
  Program.AddControlWidget("homegenie/generic/program");
});
  var sunset = Scheduler.WithName("test");
if (sunset.IsScheduling())
return true;
else
return false;

Is this the best method to perform this?, i'm assuming the trigger code would be "if its sunset.. turn the light on".
I'm then trying to figure where/how to turn them off... Do I need to create another applet and assign it to the group, or is there a way to perform both tasks with the 1 applet, or should this be done else where?
I've attached a pic, of the group and the objects in it.

Thanks,
johnny

November 15, 2014, 08:00:05 AM
Reply #1

mvdarend

  • *****
  • Information
  • Hero Member
  • Posts: 431
Hi Johnny H,

You don't need to add a widget for this, your code is almost correct, I've made a few small changes: (I'm using
SolarAltitude for the Sunset time here.)

Trigger code
Code: [Select]
var sunset = Scheduler.WithName("SolarAltitude.Evening.Sunset.Start");
if (sunset.IsScheduling())
return true;
else
return false;
or just the following line:
Code: [Select]
return Scheduler.WithName("SolarAltitude.Evening.Sunset.Start").IsScheduling();
Don't forget to set the Trigger to 'when condition evaluation switches to true'


And then the Program code (change GROUP_NAME to the name of the group the porchLights are in.)
Program code
Code: [Select]
var porchLights = Modules.InGroup("GROUP_NAME").OfDeviceType("Dimmer,Light");
porchLights.On();
Net.SendMessage("[email protected]", "Porch Lights Turned On", "Porch Lights were turned on at sunset." );


For scheduling the lights to switch off you can do the following:
Code: [Select]
return (Scheduler.IsScheduling("00 22 * * 1-7")
Program code
Code: [Select]
var porchLights = Modules.InGroup([GROUP_NAME]).OfDeviceType("Dimmer,Light");
porchLights.Off();
Net.SendMessage("[email protected]", "Porch Lights Turned Off", "Porch Lights were turned off at 22:00." );

You can also just use the Scheduled On/Off which is a standard function of a Light object, but I prefer to use scripting as I want a little more control over the event. (for example introducing some randomness in the time when the Alarm is Armed.)

Hope this helps

November 15, 2014, 02:40:12 PM
Reply #2

Johnny H

  • **
  • Information
  • Jr. Member
  • Posts: 47
Hi mvdarend,

thanks for the info i'll give that a spin today and see what happens.

Thanks,
Johnny

November 15, 2014, 02:43:54 PM
Reply #3

Johnny H

  • **
  • Information
  • Jr. Member
  • Posts: 47
mvdarend,

for to ask, for the shutoff code, i'm assuming that would that be in separate app?

thanks,
Johnny

November 15, 2014, 02:48:32 PM
Reply #4

mvdarend

  • *****
  • Information
  • Hero Member
  • Posts: 431
mvdarend,

for to ask, for the shutoff code, i'm assuming that would that be in separate app?

thanks,
Johnny

Yes, you'll need to make two apps

November 15, 2014, 03:14:59 PM
Reply #5

Gene

  • *****
  • Information
  • Administrator
  • Posts: 1472
  • Tangible is the future!
    • Yet Another Programmer
if it's not too much bother configuring each light, you could also use the Scheduled On/Off feature (see attacched screenshot).

g.

November 15, 2014, 04:58:56 PM
Reply #6

Johnny H

  • **
  • Information
  • Jr. Member
  • Posts: 47
Hi G,

thanks for the info, i'll put that on my cheat sheet. I haven't gone through all the docs as of yet, is that @ a macro for that particular field/call to another applet?.... just curious to the workings.

Thanks,
ohnny

November 15, 2014, 06:18:21 PM
Reply #7

Gene

  • *****
  • Information
  • Administrator
  • Posts: 1472
  • Tangible is the future!
    • Yet Another Programmer

March 11, 2015, 03:01:27 AM
Reply #8

NickP

  • *
  • Information
  • Newbie
  • Posts: 24
An extensive read through the posts reveals two snippets of information that might be worth adding to that page; assuming they are correct, I won't know until tomorrow.
1) Make sure the scheduler events are enabled
2) if the event has periods in the name, you have to replace them with underscores

March 11, 2015, 07:36:59 PM
Reply #9

bkenobi

  • *****
  • Information
  • Global Moderator
  • Posts: 1525
cron events will only work if the scheduling script is enabled.  I believe it is enabled by default.  Also, if you create a new named scheduled event, make sure that named event is enabled.  I haven't tried, but if you add commas to a named event, I suspect it would cause issues too.  Same with asterisks (*), slash (/ or \), ampersand (&), at (@), etc.

March 12, 2015, 02:26:07 AM
Reply #10

NickP

  • *
  • Information
  • Newbie
  • Posts: 24
Finally I got regular cron expressions working. Turns out the Scheduled ON/OFF program was in an error state. I had to recompile it to get it to green.

Hopefully @SolarAtitude.Evening.Sunset.Start will work tomorrow.

very confused what the name should be.
In the Solar Altitude program the name appears to be  @jkUtils.SolarAltitude.Evening.Sunset.Start,
On the Event Scheduling page it shows as @Evening.Sunset.Start
The examples in tis thread suggest it should be @SolarAtitude.Evening.Sunset.Start

Any background on why the differences would help. Thanks