HomeGenie Forum
Automation Program Plugins and Wizard Scripting => APP Contributions => Topic started by: bkenobi on June 17, 2014, 07:54:59 AM
-
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!
-
I have seen a bug for some time that only crops up periodically in which the light controlled by the motion sensor will turn on and then immediately off. I believe I have finally isolated the cause and fixed it. If any bugs are found in this version, please let me know.
-
Hi,
I only try your "Last_Event-20140605.hgx" for now, because i have to install my light controller ;).
I like the idea to log the level of my equipments. That work fine and i want this for a long time.
I just add the function for "Shutter" and "DoorWindow".
Bye
-
I can't imagine working with this code without some kind of debug output. I highly recommend using such a log in every code at least for the writing/debug phase! I also have an Activity Log code that I can upload if anyone is interested. I'll add it tonight (or when I remember).
-
I just remembered that I have a copy of the Activity Log code on my flash drive. Enjoy!
Although the comment for this module indicate it outputs X10 commands, it is currently set up to output all HG activity. If you want to just output a certain type of command, an if statement could be added to filter out any undesired entries.
WARNING: This code will write a lot of lines to the specified file since HG performs a lot of checks for things like the Scheduler. If you use the code as it is here, you will generate a large log file. But, if you are running on a Raspberry Pi, this will increase the number of writes to your storage media significantly. I have read that flash has a limited number of writes before it fails, so use of this code could decrease the life of your flash device. Hypothetical? Real? Who knows, but you have been informed! :D
-
I was thinking about the Activity log and realized that there were A LOT of activity events generated by the Scheduler and other HG modules. These are probably not needed for most people, so I added a toggle for them in the Script settings.
-
Hi,
I use your "Last_Event-20140605.hgx" and write the log file on a share folder (usb key shared by my dd-wrt router). First to limit use of sd-card and then to have easily access for other use.
And with another rasp, i tweet every new line of the log file on a dedicated twitter account (and limited access account ;)).
It's just for fun and not very useful :).
But if some is interesting, i can describe the step and how exactly i did.
Bye
-
Very interesting. Even if I don't use the method, I'd like to hear how you accomplished this.
-
So :
Test by mounting manually :
[/list]mount -t cifs -o user=<xxx> //<@IP>/cle /mnt/cle
When it work i had it on my fstab configuration to work on rasp next reboot :
vim.tiny /etc/fstab
Then add a line like this :
//<@IP>/cle /mnt/cle cifs rw,user,username=<xxxx>,password=<xxxx> 0 0
+ Import "Last_Event-20140605.hgx" in HG scenario.
+ Edit property of device you want to log, and then for "last event" check the checkbox.
+ Modify the path for the log by editing this scenario.
- Install command line twitter
I use this web site :
http://xmodulo.com/2013/12/access-twitter-command-line-linux.html (http://xmodulo.com/2013/12/access-twitter-command-line-linux.html)
But to get the pin code, i need to add this (because my rasp has no screen and can't launch a web browser) :
export LAUNCHY_DEBUG=true
t authorize -d
I create a simple script to tweet each new line :
#!/bin/bash
tail -fn0 /mnt/cle/LastEvent.log | while read line
do
t update ?$line?
done
-
Good tutorial. Thanks for posting!
Just curious if this was mostly to offload the twitter or if you think this will save writes in the long run? The way I see it, this will shift the write from the main SD card on your Pi to a non-replaceable flash on your router. I love the concept of writing to a different device to save writes on SD, but this seems to shift the writes to a less opportune media. Thanks again!
-
I updated all of the modules to fix a variety of issues that I found through further testing. I recommend updating to this version since the older versions don't function quite right.
Also, based on Gene's suggestions and nolio's guide, I have changed the logging default locations. They are now located in the HG log path (/usr/local/bin/homegenie/log). I mapped a path on my file server to the HG log path so that these files would be written to the other system rather than the Raspi SD card. This is not required as the files will write to the drive as normal if nothing is mapped.
Enjoy and let me know if you see any bugs.
-
I found one small mistake that is now fixed. I couldn't test it last night because it was in the day code. The issue relates to the chime implementation during the day and resulted in the nuisance check code not working correctly. I think everything else is fine.
-
I found one small mistake that is now fixed. I couldn't test it last night because it was in the day code. The issue relates to the chime implementation during the day and resulted in the nuisance check code not working correctly. I think everything else is fine.
What should I do with the hgx file?
Your smartlight probably is not what I'm looking for but it might contain something I could use. (My last programming experience was 30 years ago) and I've been across Gene's smartlight and the hue code but I cannot make my lights "softsart" with desired values and timers. :'(
-
I've tweaked a few small things over the last few weeks that seem to have made the system run perfectly. Primarily, I was having issues with the IsOn and IsOff functions so I switched to using Parameter("Status.Level").DecimalValue instead. I have not had any issues with the code since this change, so I'll share what I hope is the final release.
dutchie: Download the .hgx file to your administration machine (the system you connect to the HG web interface). Go to HG -> Configure -> Automation. I added a new group for my modules, but you can add to an existing one if you prefer. Once you navigate to that group, select Actions -> Import Program. Select the hgx file and confirm upload. You will have to compile the program and then you will be able to configure your modules as you wish.
-
Thanks a lot bkenobi for the contribution (and your explanation to install it ;)).
After my vacation I'm gonna spend (a whole lot of) time to see if I can tweak it.
I want the light to softstart (especially at night) and slowly increases to desired value and turns off after given time in the same way.
-
That shouldn't be too difficult. Sounds like a nice effect!
-
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.
-
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.
-
I found a couple bugs that have now been addressed.
-
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!
-
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.
-
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.
-
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!
-
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!
-
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.
-
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.
-
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
-
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
-
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 ?
-
I believe what you want is to instead of this:
20141230 16:47:15.6765930 ; Parents ; Sensor.Humidity ; 56
Have something more like this:
20141230 16:47:15.6765930 ; <sensor name> ; Sensor.Humidity ; 56
where <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:
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.
-
I think physical device is somewhere in the struct module.Instance
I will find. I don't think is different between Zwave or X10. Only the phisical object is used by the interface at the end point, but the struct is the same I think, only the driver change. It's one of the advantage of C#.
-
r453 has introduced a new set of history data that makes the LastEvent scripts unnecessary. As such, once you update to r453+ you can delete LastEvent and update the attached scripts. Enjoy!
In case anyone wants to see what the new history data can do, I've included a script (History_log) that will output this data. This module is not needed, but it might be informative.
-
Thank's bkenobi.
I think you can introduced the notion of my contribution (Calendar and Hour tables) in your project.
Look at this message http://www.homegenie.it/forum/index.php?topic=591.msg3539#msg3539 (http://www.homegenie.it/forum/index.php?topic=591.msg3539#msg3539)
Cheers
Dani
-
During speed test of HG, I've found that writing log data to a network drive can cost up to 1 second when turning on a light. I have added a parameter to determine whether logging is desired. By default, it will be set to false so no logging will be performed. If you want to enable logging, just change the parameter to "TRUE" and restart the code.
As always, let me know if there are any problems found. Enjoy!
-
Hi Kenobi,
My alarm system doesn't work when i activate your History_log-20150103.hgx.
I replace at the end :
return false;
By :
return true;
And my alarm system work fine again. I am sure to understand why ??? But it seems that when your script "catch" the event and never go out of the When.ModuleParameterChanged((module, parameter) => (because return is set to "false") ... Possible ??
Bye
-
return false;
This code will keep the loop running until all changes have been dealt with. It should kick out of the loop at that point and go back to sleep. I believe HG runs things in parallel, so I wouldn't have thought this would be an issue.
Out of curiosity, what are you using the History log for? I primarily was using it to look at the values HG was reporting to verify other code was working. I don't use it for normal operation. I do use Activity log all the time which uses the same code structure.
-
return false;
This code will keep the loop running until all changes have been dealt with. It should kick out of the loop at that point and go back to sleep. I believe HG runs things in parallel, so I wouldn't have thought this would be an issue.
Can you reproduce on your side ?
Out of curiosity, what are you using the History log for? I primarily was using it to look at the values HG was reporting to verify other code was working. I don't use it for normal operation. I do use Activity log all the time which uses the same code structure.
I use activity log to
- Check the status chance of a device which not work fine around 0°
- Like to have a history view of change of my devices
But i simplify the code to just log the new status (not the last status).
-
I'm not sure I understand the request. using false in a loop will keep it running until it reaches the end of modules that have changed. That is defined by Gene in his documentation. If you set true as the condition, it will only process the first module that is changing (which may be only one anyway).
The new status should be the same data the the Activity log outputs currently. The main difference would be that the time stamp that is reported is a fractional second later than the module change due to processing time. If you wanted, you could report either the module change time instead of the current time stamp time or output the change time after the module that is changing. It's very simple code so you can change it pretty easily.
-
Hey bkenobi,
I'm struggling to get Advanced Smart Lights to work correctly...
Currently we have 48 Virtual Modules for outputs from HomeGenie (off to a bank of 48 relays) and aprox. 48 Virtual Modules for inputs to HomeGenie.
I have applied Advanced Smart Lights to around 15 or so outputs, IE: Light Fittings.
I have assigned them all their own inputs, with most rooms having a PIR, and a button for said light.
After getting virtually the whole house pre-configured, I have gone to test.. If I press the button associated with the "Lounge Main Lights", it in turn switches on aprox. 6 - 8 other outputs which are associated with different inputs. I initially thought that it may have been due to the input names being fairly similar, IE: Lounge Main Lights, Kitchen Main Lights, etc.. but after changing some input names around to numbers instead, I still had the same issue of multiple other outputs being switched on.
Just to add to that, when triggering a PIR for any of the zones, they get switched on properly...
I was hoping you could give me some of your thoughts on this..
Thanks in advance!
Joe
-
Your best bet is to turn on the debug log and look at what's going on. It might also help to redirect the mono output to a file such that you can see more details about what HG is doing as well. I can try to look at things if you need some help, but be aware that I only use X10, so I may have to defer to users with more experience with other automation hardware.
It's also possible that different automation hardware requires some slight tweaks in the Advanced Smart Lights code. I don't think that should be required since everything is referred to by module name or the module's parameter which should be independent of the type of hardware.
-
Hi bkenobi,
With the latest HG (r496) : parameter.Statistics.History[x].Value
seems to doesn't work anymore, did it work for you with in the newest version ?
I have got a message "Argument is out of range. Parameter name: index" when i put x > than 0 ...
Bye
-
I have it running on 496, but I did notice that my chime went off 4 times within 1 minute when my wife left this morning meanin that something may need fixing. I'll look at the code.
-
I am remote at the moment but did not get any errors when I compiled the code. I looked at the logic and if the History[X] events are not valid, then that would explain why the chime tripped every time motion was sensed.
-
I compiled the Advanced Smart Lights code from my home network and still got no errors. However, I can confirm that the code does NOT function as it did prior to updating to 495/496 last weekend. Now whenever motion is sensed it triggers the chime. The way it SHOULD work is that a check of the last time motion was sensed should result in triggering the chime at most once every xx minutes based on the specified timeout duration. It appears that the history[X] parameter does not function the way it used to. Perhaps something else changed, but that appears most likely. I'll direct Gene to this post to see if he can help.
-
Hi bkenobi,
the value history in previous version was ignoring the "HistoryLimit" property. This property is used to keep the history within a certain number of elements that is by default 10. If you need more data you can change the HistoryLimit value.
Could this be the issue?
The main change on the ValueStatistic class is the following:
https://github.com/genielabs/HomeGenie/blob/master/HomeGenie/Data/ValueStatistics.cs#L130
g.
-
Also have a look at the new documentation:
http://genielabs.github.io/HomeGenie/api/ape/a00005.html (http://genielabs.github.io/HomeGenie/api/ape/a00005.html)
perhaps there are some useful properties you may want to use in your programs (like IdleTime).
g.
-
I left the house before sunrise this morning and found that although the chime went off multiple times, the lights themselves behaved correctly. Both sections of code use the history[X] parameter, so it must be working to some degree. Perhaps the change is in how multiple triggers are registered? I'll let you know what I find.
For reference, I did not set the HistoryLimit value, but since I'm only using the first two elements of the array, the default value of 10 should be sufficient.
-
I haven't seen an issue compiling history
- through my testing. I did find a peculiar result in doing some testing though. When I use the following code to determine how long it's been since the last event, it should produce a time span of approximately 2 seconds.
var event1 = module.Parameter("Status.Level").Statistics.History[0].
var event2 = module.Parameter("Status.Level").Statistics.History[1].Timestamp;
var elapsed = new TimeSpan(event1.Ticks - event2.Ticks);
However, in at least one instance (I was looking at other things, so this wasn't thoroughly sused yet) it returns a value <1 second even though the motion sensor doesn't act anywhere near that quick (roughly 2 second detect timeout). The reported elapsed time was ~0.2 seconds. I'm going to have to look at the entire history[] array to verify that I witnessed a fluke of some kind.
Also, perhaps someone could explain the correct syntax for switching my setup commands that are causing warning messages (AddFeature, AddFeatureTextInput, AddInputField). Am I just supposed to add another blank field somewhere and change the method? I'll take a look but last time it looked confusing so I've been ignoring the warnings.
-
AddFeature & co. are explained here:
http://genielabs.github.io/HomeGenie/programs.html (http://genielabs.github.io/HomeGenie/programs.html)
-
Oh, that's much easier than I thought it would be. The only thing that probably should be noted is that when changing from AddFeature (old) or AddFeatureTextInput to AddFeature (new), the value held within the module parameters is lost and needs to be reset. It's not a big deal for my code here, but it might be problematic if the feature holds more complex values (e.g., cron events).
-
The documentation for AddOption suggests that all types in the html/ui/widgets directory are available. However, it appears that neither slider nor checkbox works. Perhaps I'm missing something, but the following lines produce text boxes:
Program.AddOption("Adv_SmartLight.EnableLog", "false", "1) Enable log file","checkbox");
Program.AddOption("Adv_SmartLight.LogPath", @"/usr/local/bin/homegenie/log/SmartLights.log", "2) Path to log file","text");
Program.AddOption("Adv_SmartLight.TimerFidelity", "1", "3) How often does code check for timer end (seconds)","slider:0:30:1");
Program.AddOption("Adv_SmartLight.SwitchTimeout", "5", "4) How long between switch commands constitutes double tap (seconds)","slider:0:10:1");
Program.AddOption("Adv_SmartLight.SensorNuisanceLimiter", "20", "5) Nuisance limiter - Two motion detects within limiter will trigger chime (seconds)","slider:0:60:1");
If I'm doing something wrong or misunderstand implementation, please correct me!
-
Hi bkenobi,
they all works with AddFeature, but currently the only supported type for AddOption is "text". You can leave them specified, because in some next hg update these will be implemented for AddOption as well.
g.
-
My primary concern is that checkbox holds a value of "On" or blank and my code currently checks for the string "TRUE" or "FALSE". I want to update to be consistent with the new methods but don't want to have to redo my logic if possible. It would be ideal (I think) if the checkbox value was boolean so we could just use it directly in logic, but I don't know if that's possible. I used an inline if in my updated code to simplify one checkbox (addfeature) so that can be used as well if I know what to expect.
-
I try the following code :
When.ModuleParameterChanged((module, parameter) =>
{
............
if ( parameter.Statistics.History[0].Value != parameter.Statistics.History[1].Value ) {
.........
The parameter.Statistics.History[0].Value work fine but parameter.Statistics.History[1].Value as the error : Argument is out of range / Parameter name : index
Does it work on your side ? Any idea why ?
-
When do you get that error? Is it when you compile it or when it's running? I'm not getting any compile errors, but the code doesn't work right now (I've been making some changes so I could have broken it some other way). There should be 10 values in the history[X] array by default (presumably 0-9). These should be the last 10 events (even if they are repeated). When I was initially testing this code, I was outputing the array and it was exactly as expected but I have not tested it since my last release.
-
Running, error is pop-up by a try/catch. I write HistoryLimit "parameter.Statistics.HistoryLimit" and the value is 10, but something seems to fail with array ....
-
I added the following code to the script just after the WhenParameterIsChanging line:
//Log sensor_mod history array
Program.Notify("HistoryLimit",module.Parameter("Status.Level").Statistics.HistoryLimit.ToString());
string tmp = "";
for (int i = 0; i<=9; i++ )
{
tmp += module.Parameter("Status.Level").Statistics.History[i].Value + " ";
}
Program.Notify("History array",tmp);
When a parameter changes, I get only one line of notification for the HistoryLimit output. I do not see anything for the History[X] output. I changed the notification to output each history[X] element. I am able to output element 0 but nothing else prints. When I compile the code, I get the following error:
TC: Object reference not set to an instance of an object
Without this value, my code won't work.
-
I believe I have tested all related code and found that the only part that seems to be an issue is the HistoryValue array which contains a value in element 0 only. Without element 1 as well, I cannot determine my timer functions so lights will turn on but not off.
At this time, I have determined that there was a change in mid September 2015 that modified code related to Statistics.HistoryValue. I don't know why this change caused problems, but I can confirm that it does seem to cause problems. I will be migrating back to a version prior to r494 so that this code will be reverted. Hopefully this issue will be resolved and I can eliminate this recommendation.
EDIT: r496 has fixed the issue with the HistoryValue array. If you have issues with ASL, update HG to something more recent than 496.
-
I have noticed that on my setup I have certain scenarios where the ASL enabled light will take 10 seconds to turn on. I am currently debugging this issue to determine what is causing this. It only started happening after the history array issue was introduced as older versions of HG worked as expected. Currently, I can say that using a switch causes a delay. I have also seen that one motion sensor light works correctly but another (using the start timer on ON) does not work. When I locate the bug I will post a fixed APP and/or submit an issue on github to get things working correctly.
If you have any issues with a lengthy delay to turn your light on, please post to hopefully shorten the debug cycle.
-
After further testing it appears that r496 (HG 1.1) does not work well with my setup (RPi v1B w/ CM15A). I believe there was a change to the mono requirements that necessitates an update not available (i.e., a newer .NET framework). I have not been able to fix the issue with a fresh system install, so I am currently recommending using HG 1.0 r493 or earlier. Email support was also lost at some point so an earlier version might also be good if that is useful.
-
ASL works with r501. There was a change to HG in 1.1 that caused asynchronous tasks to not work correctly with X10 (and other systems in the future). Either way, if you use r496 through r500 ASL won't work correctly.
-
Meant to ask, is it possible to use multiple sensors to control one light, or maybe have any sensor in a group turn on all lights within a group?
Thinking outside lighting :)
-
Sure can. I use 2 motion sensors to control the same light. There are 2 ways to do that (with X10 anyway).
- Set motion sensor to the same address
- Set motion sensor names to same base name
If you set both/all motion sensors to the same HC/UC then any motion will be reported as the same motion sensor in HG and will operate the light(s) as though it was a single motion sensor.
Or, if you set the linked motion sensors to the same base name, then the code will be able to use them all and you get to see them as separate sensors in HG (e.g., "south motion 1", "south motion 2", "south motion 3", etc.). I use this approach.
If you use either approach, make sure you set the code to "motion triggers on ON" so that OFF signals from an area you moved out of do not cause the lights to go out on you when you are in a different sensors zone.
If you want to have multiple lights controlled by the same sensors, just use the same setup on multiple light modules. You will have to duplicate the settings, but it works just fine.
-
I'm not using x10, just using GPIO on the raspberry pi.
-
I use X10 and RPi GPIO. I have not tested other systems. The ASL code *SHOULD* work on every type of system, but it hasn't been tested. I used the HG name to reference components so you should be able to mix and match what you use as you want. If you find something that does/doesn't work, you could post here and I (or someone experienced with that tech) could try to fix it.
-
Ok, will have a bit of a read of the code and work out how I can do it and give it a test :)
-
My situation is slightly different so I have made a couple of modifications to ASL. I don't know if you are still maintaining this or not.
They can be found on https://github.com/texasaggie97/advanced-smart-lights (https://github.com/texasaggie97/advanced-smart-lights).
In particular the changes I made were:
- Module selection now uses HG feature to pick from list of appropriate modules
- Allow using a module of type switch to control the light (I am using a ZWave switch)
- Allow the "motion detection" module be a Zone Sensor. This change is not actually zone sensor specific. Since ZWave modules can be renamed, additionally check for match based on Domain + Address
I did not fix use of obsoleted functions (at least not yet).
I know this thread hasn't had any activity in a while but I didn't see a better place to put this and it didn't seem like it deserved it's own post.
-
I'm not exactly maintaining it, so your updates are much appreciated. I plan on updating my HG installation for testing soon so I'll try your updates.
-
Thank you for Advanced Smart Lights. It was almost exactly what I needed.
If you put this on GitHub somewhere I can send you a pull request.
-
I have a github.com account and will put it on there with my other codes. it may take a little bit, but I'll get it up there.
-
My laptop crashed last summer and apparently I didn't set up Github again. I had it all working with my other stuff (Arduino based projects) but something changed in the new application where I can't figure it out now. I can create a repository but can't upload files or see my other repos. If/when I get that figured out, I'll upload all of my scripts and make them public.
-
I've had similar issues with the github desktop app.. I ended up dragging the files into the repo in a web browser..
I hate the github desktop app! visual studio's integration is better..
-
I tried to use the web interface but I wasn't able to figure out how to edit the repo that way. That's when I installed the desktop app...which was worse! I used both in the past and didn't have issues so maybe I got dumb over the last year. :o
-
I don't know why Github is so complicated now, but I was able to get the web interface to allow me to upload my scripts. I still can't figure out the new Windows app. It worked GREAT last time I tried it but now it's just a steaming pile of garbage. Anyway, the scripts are all located in my signature.
-
You have made some good things bkenobi.
I wonder if there is any place to collect all good user HG scripts? Even if you are a active poster and your signature show up in many places, many good scripts are hidden and forgotten in old threads. Hard for new users to start digging around to find them.
-
yes, these can be added to the HG repository. I intended to do that, but never got around to it. once there, a user can add them via the HG Web interface very easily. The reason I didn't upload them before was that Gene made some changes that meant I should rewrite things. I haven't touched the code, so I didn't want to upload potentially problematicscripts.
-
I understand. And I also think that scripts should be tested thoroughly before being a part of the HG repository.
But there are many good scripts that maybe is not good enough for HG repository, but good enough to start with. Or get ideas on what could be done, or maybe just need small modifications to fit for that users needs.
And since Gene is not very active I think it is not very encouraging to make a pull request and it maybe get included within the next 6-12 months.
There should be a place where people could add just a link to their hgx file, maybe a link to the thread started on the forum and a small description about the script.
Then maybe more people use the script, test it, bugs get fixed, and then they could be a part of HG repository.
-
That's basically what this sub-forum is for, but it doesn't have a cents repository. People post here but users have to dig through each thread to find the files.
-
I believe I sused the one bug I've seen in the code in which a light can turn off immediately after turning on. I've uploaded it to my github account in my signature.
-
i've altered your code to work with the updated jKutils - are you taking pull requests?
-
I'm not that involved with github. If you make a pull request I assume I can review and then let github merge it in?
-
Yep :)
-
Well then go ahead and pull away. I'll try to get the update included.