HomeGenie Forum
General Category => Troubleshooting and Support => Topic started by: kevinvinv on October 22, 2016, 10:55:36 PM
-
Once I switched to version 525 my night and day detection stopped working. I might have messed it up myself though... Does anyone care to examine the below and see if they see something wrong? Basically it always reports NIGHT
if (module.Is("BackPorchMotion"))
{
//jkUtils
time_sunrise = DateTime.ParseExact(Program.WithName("jkUtils - Solar Altitude").Parameter("jkUtils.SolarAltitude.Morning.Sunrise.Start").Value, "H:mm", System.Globalization.CultureInfo.InvariantCulture);
time_sunset = DateTime.ParseExact(Program.WithName("jkUtils - Solar Altitude").Parameter("jkUtils.SolarAltitude.Evening.Sunset.End").Value, "H:mm", System.Globalization.CultureInfo.InvariantCulture);
//Program.Notify("Hello","time_sunrise");
//[email protected];
//[email protected];
if (DateTime.Compare(DateTime.Now, time_sunrise)<0 || DateTime.Compare(DateTime.Now, time_sunset)>0)
{
Night = true;
Program.Notify("Msg from BackPorchMotion","It is Nighttime");
//Log("Night");
}
else
{
Night = false;
Program.Notify("Msg from BackPorchMotion","It is Daytime");
//Log("Day");
}
}
-
To make things more readable in v525 I rewrote a number of my scripts that were using similar logic to yours.
What I have now for the above:
Created a new Scheduler rule: Nighttime
@SolarAltitude.Evening.Sunset.End > @SolarAltitude.Morning.Sunrise.Start
And then you can basically replace all your above code with the following (untested)
if (module.Is("BackPorchMotion"))
{
if (Scheduler.IsScheduling("Nighttime"))
{
Night = true;
Program.Notify("Msg from BackPorchMotion","It is Nighttime");
//Log("Night");
}
else
{
Night = false;
Program.Notify("Msg from BackPorchMotion","It is Daytime");
//Log("Day");
}
}
-
Oh- I think I understand that... I'll give it a try. Thanks!!!
-
I just edited the above code, I forgot the 'if (module.Is("BackPorchMotion"))' part...
-
That is a lot simpler than what I have in the Advanced Smart Lights code. If/when I update to the new scheduler, it looks like I'll need to rewrite some things to simplify!
-
Is it worth editing the built in smartlights code and submitting a pull request to replace it with yours?
-
I thought about it, but Gene actually updated his built-in code recently. I should put it in the repository so it would be easier to find though. All of my contributions are in the ASL thread, but none are in the repository. I never updated them to conform to the new standards (they still use both pages to define the code and the current approach is to avoid doing that) so I didn't know if it should be put up there prior to the fix.
-
Well, I cant get it to work.
Does Scheduler.IsScheduling() work with the NEW schedule tool? And if so, what does it actually mean?
I searched the forums and found a lot of stuff on Scheduler.IsScheduling way before this new 525 schedule tool came out... maybe it doesn't work with the new schedule tool?
Thoughts?
-
My apologies, apparently it doesn't work here either with the new scheduling tool...
I'd rewritten a lot of scripts to something like the above, but had not actually put them in use yet. (lighting was not yet installed in the new house)
Because it compiled and 'looked' like it should work I just assumed it would be OK.... :-[
Sorry about that...
Another option is to look at the new scripting options in the Scheduler, SensorTimeout is a pretty good example of what you're trying to achieve I think.
-
OK Thanks! At least I feel better now! :)
I'll keep looking!
-
BTW-- sorry- can you tell me where to find the SensorTimeout thing you mentioned?
Thanks again!!!
-
Configure -> Scheduler the schedule 'Sensor.Timeout' should be at the top.
Gene has said he's working on the documentation (http://www.homegenie.it/forum/index.php?topic=1721.msg10856#msg10856), hopefully we can find out if Scheduler.IsScheduling is deprecate or not.
-
I've heard talk about a virtual module... Maybe this is what I need to use .
Have the scheduler enable a module during the night
Query this module in my code.
Thoughts?
I am growing a little weary of this hobby... and I think my wife is too!
-
OK- so here is what is working as far as detecting night and day
I use the scheduler to turn on a dusk to dawn X10 channel
I detect Night by just checking the state of that module like this:
________________________
bool Night = false;
// Query Dusk to Dawn module to see if it is night or not
var DuskToDawn = Modules.InDomain("HomeAutomation.X10").WithAddress("A1").Get();
var NSense = DuskToDawn.Parameter("Status.Level").DecimalValue;
if(NSense==1) {
Night=true;
Program.Notify("Hello", "It is Night");
} else {
Night=false;
Program.Notify("Hello", "It is Day");
}
___________________________
Thanks!!