Notice: This forum has been recovered from an old backup, so some content, links, and dates may be outdated. The forum is currently read-only while we restore sign-in and registration functionality. Details

If you find this forum valuable and would like to help keep it online, donations to help cover hosting and domain costs are greatly appreciated, but never expected. You can support the forum through Buy Me a Coffee or Ko-fi. Thank you for helping preserve the EventGhost community.

When sun goes up and down, take control of your lights

Got a good idea? You can suggest new features here.
Post Reply
krambriw
Plugin Developer
Posts: 2570
Joined: Sat Jun 30, 2007 2:51 pm
Location: Stockholm, Sweden
Contact:

When sun goes up and down, take control of your lights

Post by krambriw »

Hi,

Finally, I have migrated my C++ application (NexaSunRise) to a Python script that I would like to share with you. See attached eg .xml project.

Basically the script handles 12 labels (called A1-A3, B1-B3, C1-C3 and D1-D3) that you can map to any defined eg event.

For each label you have possibility for individual time settings for each day of the week.

All settings are described in the script where you have your dedicated area to change the values according to your personally needs.

The script activates the defined events when the sun goes up and down and when the defined time settings matches actual time.

I use eg with this script to control outdoor and indoor lights of my house.

The script also creates a simple html-log file of the actions and other stuff the script does. I have linked this to my web server, then its easy to see that the script is doing the work also from remote when not at home.

My special thanks goes to Bitmonster that has helped and answered my questions promptly. This forum is really great.

As you know there is always room for learning. You will most likely find some functions that can be written "smarter". But the script works fine and fast. And the Python compiler seems to be very efficient :D

Also a thanks to Henrik H├ñrk├Ânen. I found the nice Sun.py script at his site which provides the actual calculation of Sunrise/Sunset at the specified geographical position.

Hope you have some use of this script. I do not want to know how much time I used to spend, adjusting timers before I used it...

Best regards, Walter
Attachments
SunRiseSet_sample.zip
(16.48 KiB) Downloaded 337 times
krambriw
Plugin Developer
Posts: 2570
Joined: Sat Jun 30, 2007 2:51 pm
Location: Stockholm, Sweden
Contact:

Re: When sun goes up and down, take control of your lights

Post by krambriw »

Just a small adjustment to make the synchronization work better around the clock

Walter
Attachments
02.09.2007_SunRiseSet_with_scheduler.py
(109.26 KiB) Downloaded 314 times
krambriw
Plugin Developer
Posts: 2570
Joined: Sat Jun 30, 2007 2:51 pm
Location: Stockholm, Sweden
Contact:

Re: When sun goes up and down, take control of your lights

Post by krambriw »

There is a little bug in the script related to daylight savings and time zones. I┬┤m working on an update....

In the meanwhile, use the following setting to read the status of daylight savings from the computer instead of calculating it (remember to activate that in Windows)

Code: Select all

# Select if status for daylight savings shall be calculated (EU-rules) or 
# taken from os
iDST_From_OS = 1
krambriw
Plugin Developer
Posts: 2570
Joined: Sat Jun 30, 2007 2:51 pm
Location: Stockholm, Sweden
Contact:

Re: When sun goes up and down, take control of your lights

Post by krambriw »

Alright, here is the updated and fixed script...

I had a bug in the part that calculates the daylight savings (for EU) that would have crashed the script in October when daylight savings ends. If you used the info from OS as mentioned in previous posting, it would work without problem.

Another thing I have improved is the handling of different time zones. I have not seen anybody using this script in Vladivostok or Hawaii but it should now be possible too.

Before you replace the script, take a copy of your current one with your personal settings!!!!

Best regards, Walter
Attachments
14.09.2007_SunRiseSet_with_scheduler.py
(109.51 KiB) Downloaded 288 times
krambriw
Plugin Developer
Posts: 2570
Joined: Sat Jun 30, 2007 2:51 pm
Location: Stockholm, Sweden
Contact:

Re: When sun goes up and down, take control of your lights

Post by krambriw »

I found some more bugs :oops:

In the time offset calculation, in the daylight saving routines and in the routine that reads the actual status via OS.

The attached script has all the fixes included.

Remember to copy your personal settings before you paste this script over the other in EG.

Best regards,
Walter
Attachments
03.11.2007_SunRiseSet_with_scheduler.zip
(12.09 KiB) Downloaded 309 times
User avatar
Bitmonster
Site Admin
Posts: 2239
Joined: Mon Feb 06, 2006 10:28 pm

Re: When sun goes up and down, take control of your lights

Post by Bitmonster »

Well, you use fixed repeating structures very excessive in this code and this bloats the code very much. I would suggest to get this down to an array of dictionaries. This way it is much easier to administer the settings and you are not limited to twelve simultaneous settings. Something like this:

Code: Select all

setup = [
   {
        "thursdayEvening": 0200,
        "eventName": "A1_ON",
        "iOffset": -15,
    },
    {
        "sundayEvening: 2300,
        "eventName": "A1_OFF",
        "iOffset": -15,
    },
]


or even better to function calls, that put their data into an array, so the user can configure it like:

Code: Select all

RegisterDaylightEvent(
    eventName = "A1_ON",
    time = "sunrise", # possible values are "sunrise", "sunset" or a fixed time
    offset = -15,
    weekdays = "Monday, Tuesday, Thursday", # apply only to some weekdays
)

RegisterDaylightEvent(
    eventName = "A1_OFF",
    weekdays = "all", # "all" might be the default, so it could be omitted
    time = 2300,
)
Please post software-related questions in the forum - PMs will only be answered, if really private, thanks!
krambriw
Plugin Developer
Posts: 2570
Joined: Sat Jun 30, 2007 2:51 pm
Location: Stockholm, Sweden
Contact:

Re: When sun goes up and down, take control of your lights

Post by krambriw »

I would be more than happy to improve...but I'm not that skilled...however willing to learn

The twelve limitation would be nice to get rid of, yes, even though its more then enough for a normal building. But if you extend it eg could control all lights in Berlin and we would save a lot of energy...

The user configuration part I think you should keep together in one chunk because editing function call parametres is very risky...or have I misunderstood you???

The best would be to have a gui that is used to edit the settings. And with support of drag & drop of eg events :D

Best regards, Walter
User avatar
Bitmonster
Site Admin
Posts: 2239
Joined: Mon Feb 06, 2006 10:28 pm

Re: When sun goes up and down, take control of your lights

Post by Bitmonster »

I like functions for configuring, because you can use default arguments to limit the count of parameters that need to be set and you can check the values for validity immediately (and not when the codes first uses them). And they are a big step forward a plugin.
Please post software-related questions in the forum - PMs will only be answered, if really private, thanks!
krambriw
Plugin Developer
Posts: 2570
Joined: Sat Jun 30, 2007 2:51 pm
Location: Stockholm, Sweden
Contact:

Re: When sun goes up and down, take control of your lights

Post by krambriw »

OK, I accept, can you show me an exampel taken from my script how you would preferre it?

Best regards, Walter
vuego
Experienced User
Posts: 69
Joined: Wed Jan 17, 2007 9:22 pm
Location: Sweden

Re: When sun goes up and down, take control of your lights

Post by vuego »

Thanks alot krambriw.
This is possibly the only feature I miss in EventGhost. I hope that it will be included in the main program sometime :)

Now to my issue. I don't really know how to install the script. I downloaded your Nov 03 version, added a Python Script Action in Autostart and copied/pasted everything from the .py file. Perhaps it should be done in another way?

When I execute the script (with F5 or restart EventGhost) I get the following errors logged:
15:43:29 Traceback (most recent call last):
15:43:29 Python script "0", line 3535, in <module>
15:43:29 TheTask()
15:43:29 Python script "0", line 3515, in TheTask
15:43:29 SunUpDown()
15:43:29 Python script "0", line 1550, in SunUpDown
15:43:29 st = str(eg.globals.sunRiseSet(year, month, day, myLongitude, myLatitude))
15:43:29 AttributeError: Bunch instance has no attribute 'sunRiseSet'
I'm using EventGhost v0.3.6.1262.

Thanks
krambriw
Plugin Developer
Posts: 2570
Joined: Sat Jun 30, 2007 2:51 pm
Location: Stockholm, Sweden
Contact:

Re: When sun goes up and down, take control of your lights

Post by krambriw »

Dear Vuego,
The best is to start looking at the sample xml I attached in the first posting. The one you have used is only the latest update of the main script.

The sample uses 3 scripts in total;
- the one you have already
- a basic sunset/sunrise calculation script (missing this is why you get the errors)
- a script to ask the main script to shut down itself

In the sample you see that to get automatic start of the script you need to move it to the autostart (move it to the end of the autostart list) as in the picture sample below

Best regards, Walter
Attachments
sample.jpg
sample.jpg (12.25 KiB) Viewed 8738 times
vuego
Experienced User
Posts: 69
Joined: Wed Jan 17, 2007 9:22 pm
Location: Sweden

Re: When sun goes up and down, take control of your lights

Post by vuego »

The sample works much better. Thanks alot :)
krambriw
Plugin Developer
Posts: 2570
Joined: Sat Jun 30, 2007 2:51 pm
Location: Stockholm, Sweden
Contact:

Re: When sun goes up and down, take control of your lights

Post by krambriw »

Good to hear!

And now when you got the original sample to work, its easy to update to the latest script (just download, copy and paste it using the EG editor)

BestR
halle
Posts: 1
Joined: Sun Feb 17, 2008 3:28 pm

Re: When sun goes up and down, take control of your lights

Post by halle »

hallå
är ny på det här, inte så lätt att hänga med på allt

jag b├Ârjade med att l├ñgga in en ny action/python script, sen klistrade jeg in allt fr├Ñn SunRiseSet_sample.xml och d├Âpte den till Sun.py Script, sen gjorde jag ett nytt script med alla koder fr├Ñn 03.11.2007_SunRiseSet_with_scheduler.py. N├ñr jag k├Âr execute item s├Ñ f├Ñr jag upp domma felkoderna. Vad har jag gjort f├Âr fel?????? N├Ñgon som kan hj├ñlpa mej????
Attachments
Untitled.jpg
krambriw
Plugin Developer
Posts: 2570
Joined: Sat Jun 30, 2007 2:51 pm
Location: Stockholm, Sweden
Contact:

Re: When sun goes up and down, take control of your lights

Post by krambriw »

I think you are not far away...

You have an indent problem in line 1 as indicated in the log.

Python is very sensitive with the format....
Post Reply