HomeGenie Forum

General Category => Troubleshooting and Support => Topic started by: jpscuba on November 24, 2015, 02:02:34 PM

Title: Programs keep randomly disabling themselves
Post by: jpscuba on November 24, 2015, 02:02:34 PM
I have several programs to control my lights.  These programs run fine for a few days and then it seems that one program will become disabled.  I have separate programs for turning on lights and turning off lights.  Here is a sample of a lamp turn off program in python.  Do I have it wrong or is something wrong with my system? 

Program Code:
    hg.Modules.WithName('FRLampModule').Off()

Startup Code:
    import time

    if hg.Scheduler.IsScheduling("0 23 * * *"):
      hg.SetConditionTrue()
    else:
      hg.SetConditionFalse()
 
    time.sleep(20)

If I re-enable the disabled program it will run again for days or weeks.  I am running version 1.1 beta r498.
Any help is appreciated.
Title: Re: Programs keep randomly disabling themselves
Post by: bkenobi on November 24, 2015, 04:50:52 PM
I don't have any help for the program being disabled unfortunately.  I have seen where one APP is enabled when I back up my setup and yet it is disabled on restore (jkutils solar altitude).

On a different note, you probably don't need this script in the first place.  Unless you are doing something more complex than turning a light on/off at a given time, you can actually just use the scheduled on/off code that's built in.  I've been using this script since it was incorporated and, outside of some strange setup fluke in my system at one time, it's always worked correctly.
Title: Re: Programs keep randomly disabling themselves
Post by: jpscuba on November 25, 2015, 03:22:23 AM
I would use the scheduled on/off but it doesn't use sunrise and sunset from SolarAltitude so I had to write some scripts.  All was working find until I updated the homegenie version to beta R498.  Should I try to update to a later version?  HG is not finding the latest version on it's own.  Is there really a problem with my program?  Is there a way to have the program enable itself at startup?  I cannot seem to find these answers in the manual or the forum.  Can anyone point me to further info that will be of use to me?
Title: Re: Programs keep randomly disabling themselves
Post by: bkenobi on November 25, 2015, 04:12:10 AM
Scheduled events work with anything that has a defined schedule or a cron formatted string.  If you have one of the weather APP's with sunrise/sunset enabled then you do get those scheduled events updated daily.  I use jkUtils solar altitude, but I believe Weather Underground and possibly jkUtils OpenWeatherMap all have sunrise/sunset.
Title: Re: Programs keep randomly disabling themselves
Post by: mvdarend on November 25, 2015, 01:55:45 PM
I would use the scheduled on/off but it doesn't use sunrise and sunset from SolarAltitude so I had to write some scripts.

It took me a while to get the syntax right for SolarAltitude too, but the following format works:
Code: [Select]
@SolarAltitude.Evening.GoldenHour.Start
I've never seen a Program disable itself though. Can you tell me what the following two lines achieve? I've never seen a Pause statement in the Trigger startup code before.
Code: [Select]
import time
time.sleep(20)
Title: Re: Programs keep randomly disabling themselves
Post by: Gene on November 25, 2015, 04:07:31 PM
Startup code
Code: [Select]
if hg.Scheduler.IsScheduling("0 23 * * *"):
      hg.Program.Run()

Program code
Code: [Select]
hg.Modules.WithName('FRLampModule').Off()

Title: Re: Programs keep randomly disabling themselves
Post by: bkenobi on November 25, 2015, 04:42:38 PM
Keep in mind that the Scheduled On/Off APP is just a C# program.  You can always modify it if you want to get the capabilities you need.
Title: Re: Programs keep randomly disabling themselves
Post by: jpscuba on November 26, 2015, 03:07:54 PM
Thanks for all the replies.  I was using the sleep in my programs because the programs were running constantly and using most of my processor on a Rasp Pi.  With the sleep it cut the CPU usage down to 1-2%.  I have upgraded to a Pi2 and have been reusing the programs I wrote about 2 years ago when some of the fetures were still buggy.  I also could not get the syntax correct when I tried it about a year ago after SolarAltitude was incorporated, thanks mvdarend for the correct syntax.

Thanks Gene for the corrected startup and program code.  I have updated my programs to consolidate them into a light control for each light instead of a program for on and a separate program for off as follows.  Yes I could use the built in scheduler but I am also trying to learn programming of the system so I can add more complex functinality at a later time.  My current programs are as follows:

Startup:
hg.Program.Run()

Program:
import time

if hg.Scheduler.WithName('SolarAltitude.Evening.Sunset.Start').IsScheduling():
    hg.Modules.WithName('BRLampModule').On()
elif hg.Scheduler.IsScheduling("00 23 * * *"):
  hg.Modules.WithName('BRLampModule').Off()
time.sleep(20)

I assume that this startup causes the program to run constantly but I am still using only 8% CPU with all  programs running.  Would it be better to have a separate programe for on and off and have  the startup check the conditional and then call program.run() or is what I have about the same CPU wise?

    Joe
Title: Re: Programs keep randomly disabling themselves
Post by: Gene on November 26, 2015, 03:18:26 PM
so I wonder why don't you use the scheduled on/off feature?

Title: Re: Programs keep randomly disabling themselves
Post by: Gene on November 26, 2015, 03:32:44 PM
by the way, the cpu usage problem is due to continuos program initialization (the startup code), so a better solution for your code would be changing it like this:

Program
Code: [Select]
import time

while (hg.Program.IsEnabled)
    if hg.Scheduler.WithName('SolarAltitude.Evening.Sunset.Start').IsScheduling():
       hg.Modules.WithName('BRLampModule').On()
    elif hg.Scheduler.IsScheduling("00 23 * * *"):
       hg.Modules.WithName('BRLampModule').Off()
    time.sleep(20)

this way the program will be only initialized one time, and it will run in the background.

g.
Title: Re: Programs keep randomly disabling themselves
Post by: jpscuba on November 26, 2015, 03:37:37 PM
Thanks Gene,
     I'll try the scheduler for the simple light control and also change the programs that will get more complex at a later time.  I plan on adding some scenes to the lamps later and wanted to learn the correct programming now.

Title: Re: Programs keep randomly disabling themselves
Post by: jpscuba on November 26, 2015, 03:59:29 PM
I just tried the scheduler on one of my outside light modules and it did not work.  I now remember that this is why I didn't use it in the past.  I did update the programs as you suggested with the while loop and it has reduced my CPU usage down to 1/2% which is great.  I also wrote a program for the same light module which worked fine.  I have attached the scheduler screenshot to show what I had programmed.

Title: Re: Programs keep randomly disabling themselves
Post by: mvdarend on November 26, 2015, 04:18:33 PM
You need to activate the scheduler or it won;t work.
Title: Re: Programs keep randomly disabling themselves
Post by: jpscuba on November 26, 2015, 04:31:24 PM
I just retried it as such and still not working.  Nothing in the log files either.

Title: Re: Programs keep randomly disabling themselves
Post by: Gene on November 26, 2015, 05:28:26 PM
hi jpscuba,

ensure the timezone is correctly set on your hg server. Also verify that the Scheduled On/Off program is enabled and running (it should since you see options in the module popup).

g.
Title: Re: Programs keep randomly disabling themselves
Post by: bkenobi on November 26, 2015, 08:48:34 PM
Maybe this is obvious, but after changing the settings in that dialog, you have to select update for them to be set.
Title: Re: Programs keep randomly disabling themselves
Post by: jpscuba on November 27, 2015, 12:59:55 PM
I checked that the scheduler on/off was running under programs.  I also checked the time zone on the Rasp Pi and verified by checking the time stamps in the HG log file.  Is there somewhere in HG that I need to set the time zone that I could not find?

When I made the schedule entry for the module I did use the update button.  I then exited the module edit screen and re-entered it to check that the save took correctly.
Title: Re: Programs keep randomly disabling themselves
Post by: bkenobi on November 28, 2015, 05:32:26 PM
If you run the "date" command in Linux, it will output the system time:
Code: [Select]
pi@raspberrypi ~ $ date
Sat Nov 28 08:28:56 PST 2015
In HG, the log file will display a time stamp for all actions which should match your Linux time:
Code: [Select]
2015-11-28 08:30:06.2102 Info WebServiceGateway 192.168.0.5 HTTP GET 200 /hg/html/pages/control/widgets/jkUtils/SolarAltitude/images/Widget.Preferences.png [OPEN]Beyond that, you need to have the weather APP that provides the sunrise/sunset set to the correct location.  jkUtils utilizes a lat/long while WU and OpenWeatherMap use a city.
Title: Re: Programs keep randomly disabling themselves
Post by: jpscuba on December 06, 2015, 01:30:14 PM
bkenobi,
    I did log into the Ras Pi and run the date command.  I then checked the HG logs and saw that the time stamps for the log entries matched the current time on the Ras Pi as verified from the date command.  After checking that my time and time zone was correct I tried to use the scheduler for one of my light switches using a time value instead of a sunrise/sunset value.  I ensured that the scheduler was running and I also made sure that the schedule of the light switch was activated (check box) but it still does not turn on the light.

I was able to correct my light programs using the suggestions from Gene and those have been running great.