more G-Labs products

Author Topic: Make switch control lamp dimmer module  (Read 2043 times)

August 06, 2015, 08:04:14 PM
Read 2043 times

Fmstrat

  • **
  • Information
  • Jr. Member
  • Posts: 34
Hi,

I'm trying to make a switch that's connected to a switched outlet (tall lamps) also turn on a lamp dimmer module that's in the corner of the room to level 100.

I've tried to say if the level of the switch is greater than 0, set the dimmer module to 100, but it's not working. Here's the code:

Code: [Select]
<?xml version="1.0" encoding="utf-16"?>
<ProgramBlock xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <ConditionType>OnSwitchTrue</ConditionType>
  <Conditions>
    <ProgramCondition>
      <Domain>HomeAutomation.ZWave</Domain>
      <Target>12</Target>
      <Property>Status.Level</Property>
      <ComparisonOperator>GreaterThan</ComparisonOperator>
      <ComparisonValue>0</ComparisonValue>
    </ProgramCondition>
  </Conditions>
  <Commands>
    <ProgramCommand>
      <Domain>HomeAutomation.ZWave</Domain>
      <Target>14</Target>
      <CommandString>Control.Level</CommandString>
      <CommandArguments>100</CommandArguments>
    </ProgramCommand>
  </Commands>
  <ScriptCondition />
  <ScriptSource />
  <ScriptErrors>[]</ScriptErrors>
  <Domain>HomeAutomation.HomeGenie.Automation</Domain>
  <Address>1009</Address>
  <Name>Connect living room lamps - on</Name>
  <Description>Make the small lamp turn on via the room switch</Description>
  <Group>Scenes</Group>
  <Features />
  <ActivationTime>2015-08-06T17:55:10.394508Z</ActivationTime>
  <TriggerTime>2015-08-06T17:55:17.708523Z</TriggerTime>
  <Type>Wizard</Type>
  <IsEnabled>true</IsEnabled>
</ProgramBlock>

It works if I use the web interface to turn on the switch, but if the button on the switch is used, it seems there is no broadcast of the level. Is there a way to overcome this? Thanks.

August 06, 2015, 08:09:09 PM
Reply #1

Fmstrat

  • **
  • Information
  • Jr. Member
  • Posts: 34
I should note, I tried enabling the Z-Wave "Level Poll" program, but it didn't seem to have any effect, even when waiting past the 15 minute polling interval.

I'm using a standard GE Z-wave wall switch.

August 06, 2015, 08:34:52 PM
Reply #2

bkenobi

  • *****
  • Information
  • Global Moderator
  • Posts: 1525
There are 2 scripts that might do what you need already.  There is a level memory program that will remember and set the dim level of a light every time it's turned on.  There is also a program that turns the light on to 100% when it is turned on.  I think the second is what you are looking for.

August 06, 2015, 11:00:55 PM
Reply #3

Fmstrat

  • **
  • Information
  • Jr. Member
  • Posts: 34
There are 2 scripts that might do what you need already.  There is a level memory program that will remember and set the dim level of a light every time it's turned on.  There is also a program that turns the light on to 100% when it is turned on.  I think the second is what you are looking for.

Thanks! There doesn't seem to be one that does exactly what I described, but I'm using the source from the two you mention to cobble together a "Connected Switches" program. However, I'm having a problem grabbing the "name" of the connected switch.

Specifically, I do this for the parameter in the trigger section:

Code: [Select]
Program.AddFeature("HomeAutomation.ZWave", "Light,Dimmer,Switch", "HomeGenie.ConnectedSwitches.ConnectedModule", "Name of the module to connect to", "module.text:any:light,dimmer,switch:module.name");

Which works. I can choose "Living room lamp" for that field. And then I attempt to do this in the program section (partial code):

Code: [Select]
var connectedModuleName = module.Parameter("HomeGenie.ConnectedSwitches.ConnectedModule").Value;
Program.Notify("Connected Switches", connectedModuleName);
Modules.WithName(connectedModuleName).On();

However, "connectedModuleName" is equal to "HomeAutomation.ZWave:14" instead of "Living room lamp", and there doesn't appear to be a way (that I can figure out) to convert it to the real name to use with "WithName"

Any ideas?

Another note, and I don't know if this is just the UI, but the Notify doesn't occur when I press the switch, only when I turn on the lights via the web interface. This uses the same basic code structure as the Energy Management plugin to limit brightness.

*Edit* Even hardcoding the name doesn't work. As before, it only works if I use the web interface to turn on the switch, not if I hit the switch manually. Is there a way to make wall switches "broadcast" the on/off event?

*Edit 2* Using level polling in combination works when the switch is used, but this creates a ton of notifications on the web dashboard every 5 seconds. Still looking for a "broadcast" function if possible.

*Edit 3* And I am seeing this in the log when turning the switch on/off:
Code: [Select]
./homegenie.log:2015-08-06T17:27:41.1493370-04:00 HomeAutomation.ZWave 12 ZWave Node ZWaveNode.WakeUpNotify 1
./homegenie.log:2015-08-06T17:27:53.6346300-04:00 HomeAutomation.ZWave 12 ZWave Node ZWaveNode.WakeUpNotify 1

Thanks again!
« Last Edit: August 06, 2015, 11:30:05 PM by Fmstrat »

August 06, 2015, 11:43:46 PM
Reply #4

Fmstrat

  • **
  • Information
  • Jr. Member
  • Posts: 34
OK, digging into this deeper gave me more understanding of the "Wake up notify" program for Z-wave. It looks like the "Wake up notify" program grabs the nodeinfo and goes through the following if statements to get to a switch change:

Code: [Select]
var nodeinfo = module.Parameter("ZWaveNode.NodeInfo");
...
string nif = " " + nodeinfo.Value + " ";
...
if (nif.Contains(" 84 ") || nif.Contains(" 25 ") || nif.Contains(" 26 ") || nif.Contains(" 43 "))
...
if (nif.Contains(" 60 ")) // MultiInstance
...
else if (nif.Contains(" 25 ")) // Switch Binary
...
module.Command("MultiInstance.Get").Execute("Switch.Binary/" + instance);

The "nif" for a standard switch is "04 10 01 25 27 73 70 86 72 77". The wake up is not seeing this because it doesn't contain "60". I'm thinking the wake up needs a completely seperate section for non-multiInstance switch binaries and dimmers that skips the 60 check, and does something like:

Code: [Select]
else if (nif.Contains(" 25 ")) // Switch Binary
...
module.Command("Basic.Get").Execute();

I would be happy to attempt to implement this, but I'm a bit worried I'll screw something else up since I don't know why the multiInstance is set up the way it is. If you would like to explain the multiInstance to me, I can take a stab in GitHub as I have on the other things I've found.

Thanks!


August 06, 2015, 11:58:59 PM
Reply #5

Fmstrat

  • **
  • Information
  • Jr. Member
  • Posts: 34
Sorry to keep flooding the topic, but I think I have a fix. This works for detecting wake up on all wall switches and dimmers, but I'm not sure on the plug in dimmers.

I inserted this code as an "else if" to the "if 60" statement:

Code: [Select]
        if (nif.Contains(" 60 ")) // MultiInstance
        ...
        else if (nif.Contains(" 27 ")) // Any switch
        {
          if (nif.Contains(" 26 "))
          Pause(3); // Pause 3 second to ensure dimmers get to final value
          Program.Notify("Z-Wave Node WakeUp", module.Instance.Name + "<br>" + module.Instance.Address + " Basic Get");
          module.Command("Basic.Get").Execute();
          Pause(.2);
        }

*Edit* I've added the above to the other pull request: https://github.com/genielabs/HomeGenie/pull/193
« Last Edit: August 07, 2015, 12:07:47 AM by Fmstrat »

October 05, 2015, 12:17:19 PM
Reply #6

roger.wills

  • ***
  • Information
  • Full Member
  • Posts: 53
I am trying to do something similar to you. I have a Fibaro RGBW led strip and a Aeotec Microswitch that switches some lights on and off. I'm trying to link them so that if either one is switched on or off the other is as well. I've got it working via the portal interface, but when I use the physical switch that turns the lights on and off, it doesn't work.

Please bear with me as I am new to HomeGenie and not particularly technical, certainly not a programmer, but what follows explains what I have done I hope.

I've used the wizard to create four programs (wizard scripts) that turn them on and off. They are triggered by checking the Zwave Status.Level property, either greater than 0 to turn them on or equal to 0 to turn them off. Very simple stuff and straightforward enough for me!

However, having found this post and discovered that the lines of code are already in the programs.xml for version 1.1 beta r496, I can't get the physical switch to control the Fibaro RGBW led strip as well as the lights. It only turns off the lights (there is some sort of delay as well about 3 or 4 seconds that I can't seem to overcome).

I must be missing a trick somewhere? Can you point me in the right direction please, preferably in layman's terms ( if you take shortcuts assuming I know what you are talking about I will get lost!).

Thanks.