more G-Labs products

Author Topic: Advanced Smart Lights  (Read 20537 times)

August 04, 2014, 08:43:57 PM
Reply #15

bkenobi

  • *****
  • Information
  • Global Moderator
  • Posts: 1525
That shouldn't be too difficult.  Sounds like a nice effect!

August 04, 2014, 09:03:48 PM
Reply #16

dutchie

  • **
  • Information
  • Jr. Member
  • Posts: 47
Imagine that you are sleeping and when you get out off bed when it is dark the light starts at 0% and slowly increase to desired low level so you can go to bathroom without hurting your eyes to full light exposure. (right now my kid hurts himself because it is to dark  ;))

Or just when you wake up early in the morning. Soft light, soft music to wake up, opening curtains or whatever.

August 05, 2014, 12:09:57 AM
Reply #17

bkenobi

  • *****
  • Information
  • Global Moderator
  • Posts: 1525
Modern X10 modules are mostly soft start type.  I personally don't like this, but they are supposed to make bulbs last longer.  My soft start lights are all outdoors, so I really just want the lights to turn on.

If you use X10 modules, then you might need to ramp them down to 0% when you shut them off if you want them to ramp up.  I think that X10 modules will initially turn on to the last dim level prior to dimming to your specified value.  I think Insteon and other systems are more flexible than X10, but I have no experience with them.

August 17, 2014, 05:20:49 PM
Reply #18

bkenobi

  • *****
  • Information
  • Global Moderator
  • Posts: 1525
I found a couple bugs that have now been addressed. 

September 30, 2014, 11:36:46 PM
Reply #19

RichieC

  • ***
  • Information
  • Full Member
  • Posts: 67
Hi..

Could you explain how the single/double on/off function is supposed to work - I'm a bit confused by it.. maybe it's just me ;-)

If a have a light that is on (triggered by a motion sensor) and i send a single off for that light, it turns off and then immediately back on again. If i send a double off it turns off and stays off until the motion sensor turns it on again when it detects movement.

Is this how it is supposed to work? If so then what is the single off used for ?

The way i would like this to work is:
1. Single off - turn off the light, but allow the motion sensor to turn it back on (after a short delay to allow you to exit the area).
2. Double off - turn off the light and ignore the motion sensor, so that the light wont turn on again until a single on is received (which would enable the motion sensor again).
3. Single on - turn the light on and start the timer so that the light turns off automatically (during the day). This also re-enable the motion sensor if it's disabled.
4. Have a double on turn the light on leave it on - no timer (during the day).

Hopefully this makes sense...

Rich

This is a large update to Gene's Smart Lights C# code.  This code will control a module with a motion sensor.  If the controlled module is a light (on/off light) or dimmer (dimmable light), it can also be optionally controlled by a wall switch transmitter.  If the module is a siren, it will treat it as a notification chime. 

Day/night is handled via jkUtils though Weather Underground is possible too with minimal modifications to the code.

There is an option for triggering the timer when motion is initially detected (on received) or after motion has stopped (off received).

The wall switch control has an advanced functionality beyond simply turning on and off the light module.  If a double on is received, it will turn the light on and enable the timer.  If a double off is received with the timer running, it will override and turn off the light immediately.  If a single off is received and the timer is on, it will not turn the light off.  In order to use this advanced switch control, it's also necessary to add the Last Event code.  This will allow HG to properly track duplicated on or off commands which is not possible by default.

The final code that is available is a stuck module check.  This is useful if you have a module that does not transmit properly every time or, more likely, the signal is not received consistently.  In this case, the stuck module check code will use a timer to turn the module off after a user specified timeout period.

I've spent a lot of time debugging, so hopefully everything works 100%.  If bugs are located, please let me know.  Enjoy!

October 01, 2014, 01:11:32 AM
Reply #20

bkenobi

  • *****
  • Information
  • Global Moderator
  • Posts: 1525
The way i would like this to work is:
1. Single off - turn off the light, but allow the motion sensor to turn it back on (after a short delay to allow you to exit the area).
2. Double off - turn off the light and ignore the motion sensor, so that the light wont turn on again until a single on is received (which would enable the motion sensor again).
3. Single on - turn the light on and start the timer so that the light turns off automatically (during the day). This also re-enable the motion sensor if it's disabled.
4. Have a double on turn the light on leave it on - no timer (during the day).

This is not how I intended it to work, but with some tweaking of the logic it certainly could.  The code is intended to work as follows:
1. Single off - turn light off only if the light was turned on with the switch.  If the light was turned on by motion, do nothing.  If the light was turned on by motion and the switch was turned on, a single off is needed for the light to turn off at some point.
2. Double off - turn light off if light was turned on either by motion or light switch.  If motion is sensed after this is sent, it will turn back on immediately.
3. Single on - turn light on if it's off.  If motion has already turned it on, motion will not turn it off when it times out.  This will work at any time of the day.
4. Double on - turn the light on and set a timer.  This is essentially tricking the code into thinking motion was detected and using the same timer.  This will work at any time of the day.

Your concept for 2 is actually something I've considered implementing.  I have had issue with windy nights where the lights will continually turn on when the trees move around too much.  I currently have no way to disable the motion lights other than disabling the code.  My latest thought was to implement a triple off but thought that was getting too fancy.

October 01, 2014, 01:38:13 AM
Reply #21

RichieC

  • ***
  • Information
  • Full Member
  • Posts: 67
Thanks for the quick reply!

I might see if i can modify the code to do this..

The main reason i want option2 to work this way is that i have a motion sensor in my living room controlling the lights and i want to disable the sensor if im watching a movie - I don't want the light turning back on whenever someone moves! - as you said the only way to do this currently is to disable smart lights for that room.

Also, i think its a bit more intuitive (to me at least) for it to work this way - if i have visitors it's a bit of a pain to have to explain how my light switches work!

Something else that id like to add is some detection for lights being turned on/off locally - most of my light switches are X10 switches that don't send any X10 commands when they are switched manually, but my motion sensors also report light levels so im thinking i could use this to detect if a light has been switched manually and send the appropriate X10 on/off command so that homegenie knows that the light has been switched.

I'll let you know how i get on!

Rich

The way i would like this to work is:
1. Single off - turn off the light, but allow the motion sensor to turn it back on (after a short delay to allow you to exit the area).
2. Double off - turn off the light and ignore the motion sensor, so that the light wont turn on again until a single on is received (which would enable the motion sensor again).
3. Single on - turn the light on and start the timer so that the light turns off automatically (during the day). This also re-enable the motion sensor if it's disabled.
4. Have a double on turn the light on leave it on - no timer (during the day).

This is not how I intended it to work, but with some tweaking of the logic it certainly could.  The code is intended to work as follows:
1. Single off - turn light off only if the light was turned on with the switch.  If the light was turned on by motion, do nothing.  If the light was turned on by motion and the switch was turned on, a single off is needed for the light to turn off at some point.
2. Double off - turn light off if light was turned on either by motion or light switch.  If motion is sensed after this is sent, it will turn back on immediately.
3. Single on - turn light on if it's off.  If motion has already turned it on, motion will not turn it off when it times out.  This will work at any time of the day.
4. Double on - turn the light on and set a timer.  This is essentially tricking the code into thinking motion was detected and using the same timer.  This will work at any time of the day.

Your concept for 2 is actually something I've considered implementing.  I have had issue with windy nights where the lights will continually turn on when the trees move around too much.  I currently have no way to disable the motion lights other than disabling the code.  My latest thought was to implement a triple off but thought that was getting too fancy.

October 01, 2014, 05:07:24 AM
Reply #22

bkenobi

  • *****
  • Information
  • Global Moderator
  • Posts: 1525
Sounds like an interesting setup.  I use the code for control of my outdoor lighting so this approach is more intuitive.  The most important part of the logic was to make sure the WAF was high!  I can see that different logic might work better for interior use as you've described.  One thing to be careful of is that outdoor light from the sun might be enough to trigger the motion sensor's day/night trigger.  If so, you may have the code turn lights on during the day unexpectedly.

Good luck and absolutely keep me posted on how the code works out for you.  I wrote it for my needs but am curious how it works for others!

October 02, 2014, 05:25:00 PM
Reply #23

RichieC

  • ***
  • Information
  • Full Member
  • Posts: 67
I hadn't really thought about how things might be a bit different for outdoor lighting, but i can see what you are thinking on this now..

I'm thinking of setting up the light monitoring as a separate app and it's a good point that sunlight from a window might make the system think that a light has been switched and cause it to switch the light on ..  perhaps if i allow the user to enter a light level for each room that corresponds to the actual level for a light being on it might limit false triggers from sunlight etc.. depends on how accurate this is in practice i guess. Open to ideas anyone may have on this.

Sounds like an interesting setup.  I use the code for control of my outdoor lighting so this approach is more intuitive.  The most important part of the logic was to make sure the WAF was high!  I can see that different logic might work better for interior use as you've described.  One thing to be careful of is that outdoor light from the sun might be enough to trigger the motion sensor's day/night trigger.  If so, you may have the code turn lights on during the day unexpectedly.

Good luck and absolutely keep me posted on how the code works out for you.  I wrote it for my needs but am curious how it works for others!

October 21, 2014, 04:39:12 PM
Reply #24

bkenobi

  • *****
  • Information
  • Global Moderator
  • Posts: 1525
I have been tweaking things here and there to improve reliability.  Primarily, when my Raspi reboots, it seems that things get out of synch.  I believe I have that issue resolved now.  Also, the Chime would work for a while and then stop functioning.  I don't understand the cause since my code hasn't changed.  The only thing I can think is that the C# implementation must have changed slightly and so the code somehow functions differently.

I believe the only updates are to the Advanced Smart Lights and Last Event codes.  The others are unchanged I believe but included for completeness.  I've also included my update to the Scheduled ON/OFF code which should be helpful to people with X10 or systems with local control that HG can't receive.
« Last Edit: December 19, 2014, 06:06:12 PM by bkenobi »

December 19, 2014, 06:20:50 PM
Reply #25

bkenobi

  • *****
  • Information
  • Global Moderator
  • Posts: 1525
I fixed some things with the Advanced Smart Lights code so everything is actually working now.  There was a bug in the way HG was looping through smart_modules, so I rewrote things such that it doesn't cause issues.  I also noticed that I hard coded the email recipients into the CheckIP code.  I have changed it so that recipient(s) can be added/changed without recompiling.
« Last Edit: December 20, 2014, 04:46:05 AM by bkenobi »

December 30, 2014, 04:59:39 PM
Reply #26

dani

  • *****
  • Information
  • Global Moderator
  • Posts: 535
I have a small issue with the module Activity log.
We dont get the name of the module that log the data, we get always Parents.
As you can see in the joined file.

Cheers
Dani

December 30, 2014, 05:18:04 PM
Reply #27

bkenobi

  • *****
  • Information
  • Global Moderator
  • Posts: 1525
Interesting.  I only use this code with X10 and don't really know about the differences with ZWave.  If you have an idea what the correct code would be, I can update to include the download.

I'm glad that the worst issue I've heard of is that the log doesn't output the module name correctly.   ;D

December 30, 2014, 05:38:31 PM
Reply #28

dani

  • *****
  • Information
  • Global Moderator
  • Posts: 535
Don't worry I found the issue, the name is used in one of my zwave module.
Is it possible to add the physical module reference ?

December 30, 2014, 06:11:35 PM
Reply #29

bkenobi

  • *****
  • Information
  • Global Moderator
  • Posts: 1525
I believe what you want is to instead of this:
Code: [Select]
20141230 16:47:15.6765930 ; Parents ; Sensor.Humidity ; 56Have something more like this:
Code: [Select]
20141230 16:47:15.6765930 ; <sensor name> ; Sensor.Humidity ; 56where <sensor name> is what you have named the sensor.

This is easy to fix, but again I don't know ZWave.  What you need to alter is line 12:

Code: [Select]
  string logtext = module.Instance.Name + " ; " + parameter.Name + " ; " + parameter.Value;

module.Instance.Name will work for X10, but you may need to use something different for ZWave.  My recommendation would be to include an if/then such that if the module is zwave use the new statement and else use what is currently in the code.  Maybe Gene could provide some advice on what to use to get the module name for ZWave.