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.

SunTracker - with moving ghost

Questions and comments specific to a particular plugin should go here.
Post Reply
piert
Experienced User
Posts: 321
Joined: Tue Jun 14, 2011 2:53 pm

Re: SunTracker - with moving ghost

Post by piert »

What I want to use it for is when I switch on the television in the evening (Eventghost receives a USB command through a USB-UIRT when I switch on the television using an infrared remote), I run a Python command that checks (via your suntracker plugin) if the sun is up or not. If it is not up, Eventghost turns on the lights.

I have found out that the time when the change from day to night occurs is at sunset, so if I were to switch on the television, for instance, one minute before sunset, the lights are NOT switched on by the Python script.
Since some 30 minutes BEFORE sunset, it is already a bit dark inside my house, I would prefer it if I could use an offset value immediately in the Pythons script, say 30 minutes prior to sunset. By doing so, if I switch on the television 25 minutes prior to sunset, the lights would be switched on.

Wow, I am now amazed by how difficult it is for me to explain exactly what I mean......I hope you understand anyway.

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

Re: SunTracker - with moving ghost

Post by krambriw »

Ok, I think I understand....

Lets say that you could have something like this in a script:

Code: Select all

#IR event coming from USB-UIRT...

if eg.event.suffix.find("TV Power ON") != -1:
    if sunIsDown(30):
        # Starting Watching TV in evening before sunset 
        # This would evaluate to True if sun will be down in 30 minutes or less
        # Now do the needful to turn on all your lamps
            

if eg.event.suffix.find("TV Power OFF") != -1:
    if sunIsDown(30):
        # Watching TV in late night, ending close to sunrise 
        # This would evaluate to False if sun will be up within 30 minutes or less
        # Now do the needful to turn off all your lamps
The above is just an attempt to explain how I have understood your requirement

Would the following also be worth considering:

- once triggered by your Power ON, should you have a loop that checks regularly? Lets assume that you watch TV from sunset to sunrise and never turns off...what would turn off your lamps in that case?
- if the weather is bad, it gets much darker inside. Should those 30 min be dynamically adjusted depending on the weather conditions? Like 30 +/- 15 depending on weather?

Best regards, Walter
piert
Experienced User
Posts: 321
Joined: Tue Jun 14, 2011 2:53 pm

Re: SunTracker - with moving ghost

Post by piert »

Yes, I think what you mean is also what I mean :D
krambriw wrote: Would the following also be worth considering:

- once triggered by your Power ON, should you have a loop that checks regularly? Lets assume that you watch TV from sunset to sunrise and never turns off...what would turn off your lamps in that case?
This would be an unusual scenario for me. What I did plan, however, is to make sure that if I start watching TV several hours before sunset, that the lights are automatically switched on 30 minutes before sunset. To do this, I enable a macro by a trigger event from switching on the TV. This macro that is now enabled will react to an automatically triggered suntracker event at 'sunset minus 30 minutes offset'. If the TV is not switched on (I am not at home, or not in the TV room), or if I switch off the TV before the suntracker trigger event will be issued (for instance I am already off to bed early), the macro is disabled, meaning that the lights will not be automatically switched on.
I have not tested this thoroughly yet, but I think by using this approach, I do not need the loop stuff that you suggest.
- if the weather is bad, it gets much darker inside. Should those 30 min be dynamically adjusted depending on the weather conditions? Like 30 +/- 15 depending on weather?
Yes, please! this would be great!

I tried to make a summary of the stuff that I use in Eventghost just for some clarification. see below. Note: I stripped several lines of text as I think they are just distracting.

Switching TV ON

<Macro Name="TV ON">
<Event Name="USB_UIRT.RC5.Lightning1.1" />

EventGhost.PythonScript
if eg.plugins.Suntracker.GetContentsOfVariable(): #if it is daylight
EventGhost.Enable Item(XmlIdLink(442)) #it is not dark yet, but enable below macro to allow switching on lights automatically if I am still watching TV at 'adjusted sunset'
else:
eg.TriggerEvent("Switch on lights")') #if night time, switch on lights

Switching TV OFF

<Macro Name="TV OFF">
<Event Name="USB_UIRT.RC5.Lightning2.2" /> #this is the event that gets triggered when switching off the TV
EventGhost.PythonScript
from time import sleep
if eg.plugins.Suntracker.GetContentsOfVariable(): #If daytime,
print "do nothing"
else:
sleep(10) #if is nighttime, give me 10 seconds to leave the room while lights still on
eg.TriggerEvent("switch off all lights")') #switch off all lights
Disable Below macro # this will be the default situation: when not watching TV, the lights in the TV room do not need to be automatically switched on.


Macro to make it possible to automatically switch on the lights if started to watch TV long before sunset.

EventGhost.DisableItem(XmlIdLink(442)) #disable below macro when switching off TV
</Action>
</Macro>
<Macro Name='Trigger event watch TV at night"' id="442" Expanded="True">
<Event Name="Main.ON" /> # this is the suntracker event that gets issued at sunset-offset value of 30 minutes and weather compensated
<Action>
EventGhost.TriggerEvent('switch on lights', 0.0) #lights are switched on at above suntracker event if this macro enabled
</Action>
</Macro>
</Folder>
</EventGhost>
krambriw
Plugin Developer
Posts: 2570
Joined: Sat Jun 30, 2007 2:51 pm
Location: Stockholm, Sweden
Contact:

Re: SunTracker - with moving ghost

Post by krambriw »

Hi Perry,

Attached is a version I think is working according to your requirement. Before I publish it in the first post, it would be good if you could try it out. It is compatibel with the previous/latest version, just copy and replace the file. In this version I have also included many more weather conditions that Google weather is supplying, trying to make it more predictable.

(Attachement deleted, see posts below)

The function is as follows:

Look at this typical code that you can put in a script:

Code: Select all

bSunIsDown = eg.plugins.Suntracker.IsSunDown(30, 15)
print bSunIsDown
You call the function, using two parametres. The first is the standard time you would like to have as basis, i.e. 30 minutes in the above example.

The second parametre is for the weather compensation, i.e. 15 minutes in this case

So with those settings the example above would work like this, the "IsSunDown" will be set to true 30 minutes before the actual sunset, unless the weather has an impact; if the weather is sunny and clear, the time can be reduced down to 15 minutes before, if the weather is bad, the time can be extended up to 45 minutes before.

With this, you can modify as you like. If you do not want any weather involvement, just set the last parametre to 0

Typically, you could do a lot of variants, below are just a few samples:

Code: Select all


bSunIsDown = eg.plugins.Suntracker.IsSunDown(45,0) # fixed 45 minutes before, no weather influence

bSunIsDown = eg.plugins.Suntracker.IsSunDown(30, 30) # 0-60 minutes before depending on weather

bSunIsDown = eg.plugins.Suntracker.IsSunDown(0, 30) # -30-30 minutes after/before depending on weather

In this version I have included a print statement to allow for simple check and debugging. You can just comment it out if it gets irritating.

Best regards, Walter
Last edited by krambriw on Sun Jul 24, 2011 8:17 am, edited 1 time in total.
piert
Experienced User
Posts: 321
Joined: Tue Jun 14, 2011 2:53 pm

Re: SunTracker - with moving ghost

Post by piert »

Hi Walter,

Thanks, this is great news!
It looks like it is exactly what I am looking for. Looking forward to starting testing tomorrow.
Walter wrote: bSunIsDown = eg.plugins.Suntracker.IsSunDown(30, 30) # 0-60 minutes before depending on weather
bSunIsDown = eg.plugins.Suntracker.IsSunDown(0, 30) # -30-30 minutes after/before depending on weather
This should read #30-60 minutes before and 0-30 minutes before, respectively. Am I right?

The new variables can do wonders for my Python actions when I switch on and off my TV. However, the third involved scenario, i.e. automatic switching on of the lights if I start watching TV before sunset (i.e. even before the new earlier times that the new variables will be set to) until after sunset, requires me to set a suntracker schedule that issues an event automatically at the time it gets dark in the house. This could already be done with the current version of suntracker. However, I have been trying for several days, but every time the schedule that I have set is lost at some point during the day. I am not sure what is going on here. I have followed your advice to set the suntracker schedule to switch on every day of the week at 11.00 in the morning (you mentioned this is required to 'get the schedule going'), so I would assume that, come sunset (or rather, 30 minutes before sunset and with weather compensation...) I would get an ON event for this suntracker event. However, this never happens.
When I check the schedules in the suntracker plugin itself, the schedule is not shown. If I choose 'restart all suntrackers', the schedule shows up again?
I wonder what is going on there....

Anyway, I will let you know how it goes over the coming days. Thanks again!
Best regards,
Perry
krambriw
Plugin Developer
Posts: 2570
Joined: Sat Jun 30, 2007 2:51 pm
Location: Stockholm, Sweden
Contact:

Re: SunTracker - with moving ghost

Post by krambriw »

Walter wrote:
bSunIsDown = eg.plugins.Suntracker.IsSunDown(30, 30) # 0-60 minutes before depending on weather
bSunIsDown = eg.plugins.Suntracker.IsSunDown(0, 30) # -30-30 minutes after/before depending on weather

This should read #30-60 minutes before and 0-30 minutes before, respectively. Am I right?
I had a little bug in the attached version and mixed up the sign needed for the parametres, sorry here is the updated one:
(deleted)
I think & hope it works like this, see my log below:

(30, 30) # 0-60 minutes after

Code: Select all

09:47:55      (30, 30, u'Overcast', 'Sunset expected at : ', '2134', 'Minutes left to wait: ', 722, 'Minutes adjusted: ', 15, 'IsSunDown: ', False)
Sunstatus change expected to happen at 2149

(0, 30) # 30 before <---> 30 after

Code: Select all

09:48:42      (0, 30, u'Overcast', 'Sunset expected at : ', '2134', 'Minutes left to wait: ', 691, 'Minutes adjusted: ', -15, 'IsSunDown: ', False)
Sunstatus change expected to happen at 2119

(-15, 15) # 30 before <---> 0 after

Code: Select all

09:49:23      (-15, 15, u'Overcast', 'Sunset expected at : ', '2134', 'Minutes left to wait: ', 682, 'Minutes adjusted: ', -23, 'IsSunDown: ', False)
Sunstatus change expected to happen at 2111

(-15, 45) # 60 before <---> 30 after

Code: Select all

09:50:05      (-15, 45, u'Overcast', 'Sunset expected at : ', '2134', 'Minutes left to wait: ', 666, 'Minutes adjusted: ', -38, 'IsSunDown: ', False)
Sunstatus change expected to happen at 2056


The first parametre never change sign, the second will eventually change sign depending on the weather condition. For some conditions it is added, for some it is divided by two and subtracted, and for some it is fully subtracted

Your original requirement would be solved with (-30, 0) and no weather influence. To use weather conditions, maybe (-15, 15) or (0, 30) would be good first trials

Best regards, Walter

PS Configure the plugin for summer season begins / ends also (myself I have 06-08 but it may be different for your location)
Last edited by krambriw on Thu Jul 28, 2011 6:37 am, edited 1 time in total.
piert
Experienced User
Posts: 321
Joined: Tue Jun 14, 2011 2:53 pm

Re: SunTracker - with moving ghost

Post by piert »

Hi Walter,

First of all, thank you for taking the time to make the additional options possible.
I have been doing some testing on the new possibilities of your plugin.

It appears that the newly added action-block "SunTracker: Check if Sun will be down in X minutes" can not be configured (yet?) after it has been inserted in Eventghost.
I assume this would be possible in a final version. Otherwise, some more explanatory comments would be helpful.

Therefore, I have played around with the Python script you provided:

bSunIsDown = eg.plugins.Suntracker.IsSunDown(30, 15)
print bSunIsDown

You wrote about this:
"the "IsSunDown" will be set to true 30 minutes before the actual sunset"

I tried this at around 4 o'clock in the afternoon. With default conditions the result returned is False.
Obviously, I wanted to see 'something happen', so I was looking to find the 'tilting point' by adding a very large offset.
So, if I set (-600, 0), which is 10 hours prior to sunset (in The Netherlands), I would expect to see a different outcome.
However, the result returned is still False?

Will be testing some more later; to be continued.....
krambriw
Plugin Developer
Posts: 2570
Joined: Sat Jun 30, 2007 2:51 pm
Location: Stockholm, Sweden
Contact:

Re: SunTracker - with moving ghost

Post by krambriw »

I think I have another bug, I'm debugging right know...

Conditions needed:

- you have to have SunTracker plugin running with the configuration for your location
- use format (-30, 0) as example if you want the trigger before sunset, (30, 0) will give a trigger after sunset
- I think I do not support so high values like 600, I have to include an error handler

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

Re: SunTracker - with moving ghost

Post by krambriw »

With the existing version you have, try the settings (-30, 1)
krambriw
Plugin Developer
Posts: 2570
Joined: Sat Jun 30, 2007 2:51 pm
Location: Stockholm, Sweden
Contact:

Re: SunTracker - with moving ghost

Post by krambriw »

It doesnt work the way I expected, need more time to figure it out...
piert
Experienced User
Posts: 321
Joined: Tue Jun 14, 2011 2:53 pm

Re: SunTracker - with moving ghost

Post by piert »

With the existing version you have, try the settings (-30, 1)
I did, using the following Python script:
bSunIsDown = eg.plugins.Suntracker.IsSunDown(-30,1)
print bSunIsDown
This is the outcome of the Python script at 21.22:
21:22:45 (-30, 1, u'Clear', 'Sunset expected at : ', '2133', 'Minutes left to wait: ', -18, 'Minutes adjusted: ', -29, 'IsSunDown: ', False)
21:22:45 False

And this is the outcome of the Python script at 21.37:
21:37:52 (-30, 1, u'Clear', 'Sunset expected at : ', '2133', 'Minutes left to wait: ', -33, 'Minutes adjusted: ', -29, 'IsSunDown: ', True)
21:37:52 True
This is unexpected, I think? I would have thought that sunisdown for test 1 should have had 'True' as outcome (as the sun was going to be down within the given time-slot).
It appears that the IsSunDown looks at the normal Sunset instead of the adjusted Sunset to determine its True or False status.
piert
Experienced User
Posts: 321
Joined: Tue Jun 14, 2011 2:53 pm

Re: SunTracker - with moving ghost

Post by piert »

Oops, my test results just crossed your reply.
No worries, take your time!
krambriw
Plugin Developer
Posts: 2570
Joined: Sat Jun 30, 2007 2:51 pm
Location: Stockholm, Sweden
Contact:

Re: SunTracker - with moving ghost

Post by krambriw »

Its getting late ...let's see tomorrow evening

Best regards, Walter

BTW no configuration needed for this action, all settings are in the parametre
krambriw
Plugin Developer
Posts: 2570
Joined: Sat Jun 30, 2007 2:51 pm
Location: Stockholm, Sweden
Contact:

Re: SunTracker - with moving ghost

Post by krambriw »

Hi,

I think this version works now.

(deleted, did not work)

I also covered the case if you would turn on the TV after midnight while the sun is still down. It is a new day and in this case, I'm checking if the sun is still down so the correct status always is returned

Try typically (-30, 0) first before adding weather so we can check if the basis is working ok



Best regards, Walter
Last edited by krambriw on Mon Jul 25, 2011 6:34 pm, edited 1 time in total.
piert
Experienced User
Posts: 321
Joined: Tue Jun 14, 2011 2:53 pm

Re: SunTracker - with moving ghost

Post by piert »

I will do some tests tonight with the Python script.

You made several actions available that can be inserted into the Eventghost tree. For one of them, action "SunTracker: Check if Sun will be down in X minutes", I still have no clue what it does or how it works.
I would have thought that it might work like your other "SunTracker: Sunstate with weather compensation", where you have to enter the compensation time inside the action item. However, there are no entries to configure this block.
When I run it, it complains that it requires 3 arguments and that only one is given, see log:
When I execute:
13:52:42 SunTracker: Check if Sun will be down in X minutes

I get this result in the logs:
13:52:42 Error in Action: "SunTracker: Check if Sun will be down in X minutes"
13:52:42 Traceback (most recent call last) (1522):
13:52:42 File "C:\Program Files\EventGhost\eg\Classes\ActionBase.py", line 170, in CallWrapper
13:52:42 return self(*args)
13:52:42 TypeError: __call__() takes exactly 3 arguments (1 given)
Post Reply