more G-Labs products

Author Topic: How to turn the light on to 100% every time switch is used  (Read 1132 times)

August 24, 2016, 04:43:46 AM
Read 1132 times

IanR

  • **
  • Information
  • Jr. Member
  • Posts: 31
Hello

I have found in http://www.homegenie.it/forum/index.php?topic=1009.0 a reference to a program that can make the dimmer reset to 100% when the unit is switched on.
But I cant find the program what is it called?

I have tried "level memory program" but is dose what is called and returns the dimmer to last level not 100%

Ian

August 24, 2016, 06:10:23 PM
Reply #1

bkenobi

  • *****
  • Information
  • Global Moderator
  • Posts: 1525
I know I use this script in my setup, but I'm having a tough time finding it this morning.  I'll look again, but when I'm remote the menus are REALLY slow to load so it takes a long time to check through each section.

August 24, 2016, 06:30:51 PM
Reply #2

bkenobi

  • *****
  • Information
  • Global Moderator
  • Posts: 1525
Ok, found it!

PID: 84
Programs -> X10 -> "Set to 100% when switched on"

I thought I was using it, but it's turned off.  I don't know if it's been moved since I installed HG last but you should be able to find it in that location or something similar.  Worst case, you can search through the modules.xml file and locate it that way.  If for some reason it's not installed with the stock build anymore, you can use the attached export.  I'd recommend using the built in one if it's there.

August 24, 2016, 10:14:27 PM
Reply #3

IanR

  • **
  • Information
  • Jr. Member
  • Posts: 31
Hello
If its in the x10 section will it work on Z-wave?

Ian

August 24, 2016, 11:26:51 PM
Reply #4

IanR

  • **
  • Information
  • Jr. Member
  • Posts: 31
Hello
I have tried the x10 program and it dose not work on z-wave.
So I am trying to write my own program but cant find how to send the required value to the dimmer to set it to 100%.

Program.Notify("***What do I put in here***", module.Instance.Name + "<br>" + module.Instance.Address + " set to " + "99.00");

or am i total off track?

Ian

August 25, 2016, 06:47:11 AM
Reply #5

bkenobi

  • *****
  • Information
  • Global Moderator
  • Posts: 1525
Yes, totally off track.  That command will simply pop up a notification in the interface not do anything with zwave.  You need to set the level parameter to change the dim level.

August 25, 2016, 04:36:00 PM
Reply #6

bkenobi

  • *****
  • Information
  • Global Moderator
  • Posts: 1525
The reason this does not work with zwave is pretty self explanatory once you look at the code.

Code: [Select]
// We want to do further processing whenever a module changes
When.ModuleParameterIsChanging( (module, property) => {
  if (module.HasFeature("X10.LevelFix") && module.IsOfDeviceType("Dimmer") && property.Name == "Status.Level")
  {
    var level = module.Parameter("Status.Level");
    var lastlevel = module.Parameter("Status.LastLevel");
    //
    bool justswitchedon = (level.DecimalValue > 0 && lastlevel.DecimalValue == 0);
    lastlevel.Value = level.Value;
    if (justswitchedon)
    {
      Program.Notify("X10 Auto Bright", module.Instance.Name + "<br>" + module.Instance.Address + " set to 100%");
      module.Command("Control.Bright").Set("100");
      return false; // <-- prevent ModuleParameterChanged event from being fired
    }
  }
  return true; // <-- continue routing event to other listeners
});

Program.GoBackground();

The first logic statement has
Code: [Select]
module.HasFeature("X10.LevelFix") as one of the checks.  Zwave won't have this feature, so it will not work on those modules.  The command that actually sets the dim level is down further.
Code: [Select]
module.Command("Control.Bright").Set("100");

If you want to use this with zwave, you need to change the logic statement so it will also include a hasfeature for zwave (or some other way to verify that the specific module will work with your code you want to run against it).  I'd recommend a review of the zwave feature set in HG and/or trial and error coding.  I don't think there's any reason you couldn't get this to work with minimal effort though.

August 31, 2016, 11:16:43 PM
Reply #7

IanR

  • **
  • Information
  • Jr. Member
  • Posts: 31
Hello

So I have been trying to create a program to turn all my z-wave dimmer on to full (99%) when switched on. see code below. It works. (if a bit messy)
But it cant tell if the user has switched it on using the input switch i1 or if HG has switched it on. Is there a way to tell the code the difference?

Code:
Code: [Select]
//
// When z-wave light is switched and is on then change it to 100%
//

When.ModuleParameterChanged( (module, parameter) => {
  // when switched on
 if (module.IsOfDeviceType("Dimmer") && parameter.Name == "Status.Level")
  {
       // Check if the module has just been turned on from zero and is currently on
    if ( parameter.Statistics.Last.Value == 0 && module.Level != 0)
     {   
        // setup and set historry level to 99% so it will not try and revert back.
       var memory = module.Parameter("Status.MemoryLevel");
       memory.Value = "0.99"; 
        // set the current level to 99% if you change this to 100% it crashes HG so don't
       module.Level = 99; 
       // returning false, prevent from routing event to other listeners     
       return false;
     }
  }
  // returning true, will route event to other listeners
  return true;
});
Program.GoBackground();

Ian