more G-Labs products

Author Topic: Alarm clock light automation  (Read 4653 times)

November 03, 2015, 06:35:39 PM
Read 4653 times

roger.wills

  • ***
  • Information
  • Full Member
  • Posts: 53
I have a Fibaro RGBW controller looking after a rgbw LED strip, all works as it should.

I want to link this strip to the alarm function on my android phone to turn on about 10 minutes before hand and gradually fade up to 100% luminosity.

I'm not aware of any capability built in that will allow me to do this out of the box, would be very happy to hear otherwise.

Breaking this down a bit. I intend to use Tasker on my Android phone to detect a new instance of an alarm whenever I set it (mainly because I already own that app) and then pass a trigger event to HG to run a script/programme to turn on the LED strip as described to a preset colour approximating daylight to help with waking up, I'll probably leave it on for a while before turning it off ready for the next alarm!

The Tasker end of things to detect a new alarm being set on the phone is straightforward enough for me to do, however, passing a trigger event to HG and then getting HG to gradually increase the level of the LED strip other than manually is beyond me at the moment. I've seen suggestions of event handlers on the forum but they were written for more technically minded people, programmers, not mere novices like me and are just out of my grasp of comprehension.

Can anyone help? I was quite surprised that this one didn't already exist somewhere.

Thanks.


November 04, 2015, 05:19:43 PM
Reply #1

roger.wills

  • ***
  • Information
  • Full Member
  • Posts: 53
Managed to look at this a bit more and used the Web API by launching urls from Tasker using the following format:

http://<hg_address>/api/<module_domain>/<module_address>/<command>/<param>

Looks like I can do all of this from Tasker itself but I think it would be tidier to run a programme from within HG at a specified amount of time before the alarm to gradually fade up the led strip.

So things I have to work out still are:
  • starting tasks in Tasker at specified times, calculated from the alarm information - straight forward I am sure, just not looked at it yet
  • creating a loop in a wizard script program to increment the Control.Level value of the led strip by 1 every 6 seconds until at full value (this would fade up the led strip to full power over a period of 10 minutes.

I am sure the latter is straightforward, but if anyone can point me in the right direction to do that I'd appreciate it.

Thanks

November 04, 2015, 10:50:43 PM
Reply #2

bkenobi

  • *****
  • Information
  • Global Moderator
  • Posts: 1525
Code: [Select]
While (Program.IsEnabled
{
  module = Modules.WithName("LED_Strip");
  if (module.Parameter("Status.Level").Value < 100)
  {
    module.Parameter("Status.Level").Value = module.Parameter("Status.Level").Value +6;
    Pause(6);
  }
  else
  {
    return false;
  }
}

This is more of a pseudo code, but it should get you started.

November 07, 2015, 04:59:13 PM
Reply #3

roger.wills

  • ***
  • Information
  • Full Member
  • Posts: 53
thanks bkenobi.

Not sure what code this is, Python, C#, etc? I've tried pasting into HG as different code types but none work, there are errors!

I'm not really a programmer, I've dabbled in the past to do some specific simple things but that's it I really need to be held by the hand! To reference the specific Fibaro device I have I assume that I change the "Led_Strip" to something like "Bedroom_Alarm_Light_Strip" i.e. the specific name of the device on my system? I've already made this change to the code you provided on the assumption that is correct...




November 08, 2015, 01:59:44 AM
Reply #4

bkenobi

  • *****
  • Information
  • Global Moderator
  • Posts: 1525
I use C# in HG.  The code I posted should be pretty close, but I didn't check it in HG to verify it worked so I expected it to have errors.  You should be able to past the code into an APP and put "Program.Run();" in the setup code (according to Gene, I haven't updated a script to use that approach yet).

November 08, 2015, 09:19:14 AM
Reply #5

mvdarend

  • *****
  • Information
  • Hero Member
  • Posts: 431
Here is another way of doing it: (Code in C#)

Startup code:
Code: [Select]
return false; // Probably not needed anymore, still put it there out of habit :)
Program Code:
Code: [Select]
// Fibaro RGBW LED strip (HomeAutomation.ZWave)

int targetLevel = 50; // 100 is Maximum level
int timeInSeconds = 60; // 600 = 10 minutes

// Loop from 0 to targetLevel
for (int level = 0; level < targetLevel; level++)
{
  // 10.2 Red, 10.3 Green, 10.4 Blue, 10.5 White
  Modules.WithName("LED 10.2").Command("Control.Level").Set(level.ToString());
  Modules.WithName("LED 10.3").Command("Control.Level").Set(level.ToString());
  Modules.WithName("LED 10.4").Command("Control.Level").Set(level.ToString());
  Modules.WithName("LED 10.5").Command("Control.Level").Set(level.ToString());
  Pause(timeInSeconds / targetLevel);
}

In my case the LED strip is called LED strip Main and the color channels are 10.1, 10.2 etc. See the starup code of the FIbaro RGBW APP for more information on how it works.

I've set targetLevel to 50 and timeInSeconds to 60 to make it easier to test, change them to the desired values once it's working as you like.

I've also set it up so that all colors are increased equally, you can play around with it to get different Hues. You'll nee to experiment with that though, it the way the RGBW controller works sometimes the colours weren't changing as I'd expected.

You can run it from within the code editor, or from another Progarm with Program.Run("ProgramId"); or with a HTTP command, although I haven't tested that.
« Last Edit: November 08, 2015, 09:21:57 AM by mvdarend »

November 08, 2015, 10:15:14 AM
Reply #6

roger.wills

  • ***
  • Information
  • Full Member
  • Posts: 53
That's great thanks both, I'll try and let you know how I get on

November 08, 2015, 12:18:38 PM
Reply #7

roger.wills

  • ***
  • Information
  • Full Member
  • Posts: 53
Ok,

Now I have the syntax I'm getting this and have got a working program as below (can't seem to work out how to insert this as code like you have, the button doesn't seem to be working for me). Also note that I am using "Kitchen Floor Lights", an existing LED strip, to test this code and I will change that when the hardware arrives and I get the strip installed in the bedroom.

There is one issue that I can't seem to solve. When the LED strip first comes on the Level flares up to being almost 100% before it fades back down to level of 1, seems to work as it should thereafter. I assume there is something else I need to adjust somewhere so that we are not rudely awakened by this initial flare? (Note the second to last line of the Program code was an attempt to set the level low in case there was a memory effect when the strip was turned back on... clearly it had no effect!

Thanks.

Startup Code:
return false;

Program Code:
int targetLevel = 100; // 100 is Maximum level
int timeInSeconds = 600; // 600 = 10 minutes

Modules.WithName("Kitchen Floor Lights").Command("Control.ColorHsb").Set("224,213,177");
Modules.WithName("Kitchen Floor Lights").Command("Control.Level").Set("1");
// Loop from 0 to targetLevel
for (int level = 1; level < targetLevel+1; level++)
{
  Modules.WithName("Kitchen Floor Lights").Command("Control.Level").Set(level.ToString());
  Pause(timeInSeconds / targetLevel);
}
Pause(600);
Modules.WithName("Kitchen Floor Lights").Command("Control.Level").Set("1");
Modules.WithName("Kitchen Floor Lights").Command("Control.Level").Set("0");

November 08, 2015, 06:17:24 PM
Reply #8

mvdarend

  • *****
  • Information
  • Hero Member
  • Posts: 431
It's probably this line:
Code: [Select]
Modules.WithName("Kitchen Floor Lights").Command("Control.ColorHsb").Set("224,213,177");
HSB = Hue, Saturation, Brightness, meaning that you're setting the Brightness to 177 (out of a possible 255), try setting it to 1. (You can probably lose the next line as well if this works.)

November 08, 2015, 06:45:56 PM
Reply #9

roger.wills

  • ***
  • Information
  • Full Member
  • Posts: 53
Thanks mvdarend.

Thought you had it when you suggested this, but alas, it made no difference. I recompiled, restarted HG service, but nothing changed with the suggested change!

Perhaps I need to revert to the method that you used originally to set each channel individually. I must confess to not understanding how to do the equivalent in my set up as I don't know what the individual channels are called here. How can I find out? Also, if your module is called "LED strip Main" how come you only refer to "LED 10.2" (etc) for each channel (i.e. you seem to have truncated the module name to the first 3 letters of the actual name?)? That confuses me and again in my set up I can't see what the equivalent would be?

Thanks for your help on this.

November 08, 2015, 06:58:45 PM
Reply #10

mvdarend

  • *****
  • Information
  • Hero Member
  • Posts: 431
It's been a while since I last did much with the Fibaro RGBW module so I've forgotten exactly how they work.

I do remember that sometimes it didn't do exactly what I expected, so I ended up always controlling each colour channel separately in all my automation programs. (but to be honest, I can't remember exactly why I decided it was better to do that  :-[ )

Dani did document his findings quite well in the App itself, you can find the comments here:
Configure -> Programs -> Z-Wave -> Fibaro RGBW -> Edit -> Startup Code

Your LED channels most likely have the same addresses as mine Your LED channels will be 'sub-channels' of the main one (in your case the Addres for 'Kitchen Floor Lights'), you can find out in the 'Add Modules'  dialog (Configure -> Groups -> Choose a group -> Actions -> Add Modules), you should see something like the screenshot below.
« Last Edit: November 08, 2015, 07:00:50 PM by mvdarend »

November 08, 2015, 07:25:16 PM
Reply #11

mvdarend

  • *****
  • Information
  • Hero Member
  • Posts: 431
Quote
HSB = Hue, Saturation, Brightness, meaning that you're setting the Brightness to 177 (out of a possible 255), try setting it to 1. (You can probably lose the next line as well if this works.)

What I said here is incorrect as far as the FibaroRGBW module goes...  :-[ I just had a look at the code and it doesn't work as I had expected.

HSB does mean Hue, Saturation, Brightness..., but the Fibaro module uses the values sent as RGB (Red, Green, Blue), so basically I was telling you to set Blue to 1...

That's probably why I ended up always controlling each colour channel separately, because the APP does that anyway.
« Last Edit: November 08, 2015, 07:27:23 PM by mvdarend »

November 08, 2015, 07:33:45 PM
Reply #12

roger.wills

  • ***
  • Information
  • Full Member
  • Posts: 53
OK, thanks will have another look.

Ref: ColorHSB, I thought that I was seeing RGB rather than HSB being changed, you've confirmed it and my sanity!

November 08, 2015, 08:28:53 PM
Reply #13

roger.wills

  • ***
  • Information
  • Full Member
  • Posts: 53
OK, I've tried applying the changes, again, it's not working  as expected.

However, I think I may have discovered a problem. When I checked the "module add" as per your screen shot I found as attached.

There is a multilevel switch and sub-channels only for Dimmer? Is that right? Looks like to me that something hasn't been updated when the Fibaro RGBW controller was added or it may be the way I've added it to the Group? I tried referencing these sub-channels in the code but they did not control the LED strip.

I'm going to look again at how to add the Fibaro RGBW controller in case I missed something, if anything seems obvious to you please shout!

November 08, 2015, 09:04:34 PM
Reply #14

roger.wills

  • ***
  • Information
  • Full Member
  • Posts: 53
Ok,

Finally I worked it out!

I didn't realise that I needed to add those Dimmer channels to the Group and also rename them. Now that I have done this and adjusted the code, all is working as required.

mvdarend, bkenobi, many thanks for being patient and talking me through it. The lack of non-techy oriented documentation makes these things difficult for folk like me! The learning curves are not just steep but there are many of them all running together, you never know as a beginner whether you are barking up the right tree to get things to work!

My only final question is, is there a way of making the "sub-channels" disappear in the mobile app (Android) so that it doesn't get cluttered? Note, I haven't upgraded to the new beta app yet, that was taking on too much at once!