SunTracker - with moving ghost

Questions and comments specific to a particular plugin should go here.

Re: SunTracker - with moving ghost

Postby krambriw » Mon Jul 25, 2011 2:11 pm

Currently the action can only be called via a script. Making the action possible to trigger via a macro will require me to add configuration for it. It's not very complicated and I can fix it now for the test tonight.

Do you need that?

Best regards, Walter
krambriw
Plugin Developer
 
Posts: 1144
Joined: Sat Jun 30, 2007 2:51 pm

Re: SunTracker - with moving ghost

Postby krambriw » Mon Jul 25, 2011 4:03 pm

Here is the version that also includes configuration of the action
(deleted)
I have also made so that the action creates an event with payload information

Best regards, Walter
Last edited by krambriw on Thu Jul 28, 2011 6:36 am, edited 1 time in total.
krambriw
Plugin Developer
 
Posts: 1144
Joined: Sat Jun 30, 2007 2:51 pm

Re: SunTracker - with moving ghost

Postby piert » Mon Jul 25, 2011 7:33 pm

Thanks for making the macro-setup thingy; this makes it easier to use also for people that do not use Python scripts.

First test
21:11:36 Enable: TEST
21:11:36 SunTracker: Check if Sun will be down in X minutes: -30
21:11:36 (-30, 0, u'Overcast', 'Sunset expected at : ', '2131', 'Minutes left to wait: ', -10, 'Minutes adjusted: ', -30, 'IsSunDown: ', True)
21:11:36 print eg.result
21:11:36 True


Second test
21:12:49 Enable: TEST
21:12:49 SunTracker: Check if Sun will be down in X minutes: -10
21:12:49 (-10, 0, u'Overcast', 'Sunset expected at : ', '2131', 'Minutes left to wait: ', 9, 'Minutes adjusted: ', -10, 'IsSunDown: ', False)
21:12:49 print eg.result
21:12:49 False


Third test
21:14:22 Enable: TEST
21:14:22 SunTracker: Check if Sun will be down in X minutes: 0
21:14:22 (0, 30, u'Partly Cloudy', 'Sunset expected at : ', '2131', 'Minutes left to wait: ', 2, 'Minutes adjusted: ', -15, 'IsSunDown: ', False)
21:14:22 print eg.result
21:14:22 False


Fourth test
21:16:08 Enable: TEST
21:16:08 SunTracker: Check if Sun will be down in X minutes: 0
21:16:08 (0, 60, u'Partly Cloudy', 'Sunset expected at : ', '2131', 'Minutes left to wait: ', -15, 'Minutes adjusted: ', -30, 'IsSunDown: ', True)
21:16:08 print eg.result
21:16:08 True


I think we have a winner! Looking at the results, I have a gut feeling that the values (-15,30) would be best choice. I will test this as a next test case tomorrow evening.

Walter wrote:I have also made so that the action creates an event with payload information.

Walter wrote:Currently the action can only be called via a script. Making the action possible to trigger via a macro will require me to add configuration for it. It's not very complicated and I can fix it now for the test tonight.


I do not understand what you mean and I do not know how to get the payload to appear. Maybe you could explain and I can include in testing tomorrow evening.

best regards,
Perry
piert
Experienced User
 
Posts: 116
Joined: Tue Jun 14, 2011 2:53 pm

Re: SunTracker - with moving ghost

Postby krambriw » Mon Jul 25, 2011 8:01 pm

Good, it looks like the basis is functioning

Generating an event is necessary to trigger macros. The prints I make are only to allow easier bugfixing.

In general, you do not need the payload, I included it for advanced usage, maybe good to have later, if you build another plugin or make a script it could be good to have the status change as payload and not only as part of the subject. In this case I have made it so you have both.

So to solve your original requirement, you can now create two macros:

1) the first macro should include the event "Power ON" coming from your IR remote via USB-UIRT as well as the action "IsSunDow" that is configured according to your needs (-15, 30).

2) the second macro should have the event that is generated when the sun is down and the actions that takes care of your lights.

As soon as you press "Power ON" on your remote, the first macro starts. If sun is down within next X minutes with/without weather consideration, the event "IsSunDown: True" is generated.

This event should be placed in the second macro, then it starts the second macro that has the necessary actions to turn on lamps included.

The only thing you need to do is to first generate the events and then drag them to the macros where they belong.


Hope you got it,

Best regards, Walter
krambriw
Plugin Developer
 
Posts: 1144
Joined: Sat Jun 30, 2007 2:51 pm

Re: SunTracker - with moving ghost

Postby piert » Tue Jul 26, 2011 8:12 am

Oops, I had forgotten to untick the "log only assigned and activated events" in Eventghost, so I actually never saw the events that were generated from your plugin!
krambriw wrote:If sun is down within next X minutes with/without weather consideration, the event "IsSunDown: True" is generated.


I tried it just now and the generated event does indeed include the result "False" twice, first one being the event, second one the payload:
9:40:55 Enable: TEST
9:40:55 SunTracker: Check if Sun will be down in X minutes: 0
9:40:55 (0, 60, u'Rain', 'Sunset expected at : ', '2129', 'Minutes left to wait: ', 649, 'Minutes adjusted: ', -60, 'IsSunDown: ', False)
9:40:55 print eg.result
9:40:55 False
9:40:55 Main.IsSunDown: False False
9:40:55 <start unnamed macro>
9:40:55 print eg.event.string
9:40:55 Main.IsSunDown: False
9:40:55 print eg.event.payload
9:40:55 False


I think it will definitely be worthwile to have the payload available for Python scripts that take actions on all events from the plugin, based on the payload. However, I noticed that the event prefix is Main and your event suffix is IsSunDown: False, i.e. including the 'False' statement:

9:45:21 print eg.event.suffix
9:45:21 IsSunDown: False


Would this not make it impossible to catch all related events (i.e. also the "IsSunDown: True") with using a wildcard? Or do you have another solution to catch events?

Also, would it be easy to add more payload options somehow? I would think that the "modified sunset time" and/or amount of time left until "modified sunset" would be a nice to have. Suppose that when you execute the script early on the day, you can use the amount of time left to the modified sunset time to set a timer to trigger an event. I know this can also be done by using your suntracker schedule, but this would be easier to use and maintain, I think.
It may also be more clear to the user if the description in the log print (and maybe also in the payload then?) could include "True sunset expected at:" and "Modified sunset expected at:".

Finally, to make it more clear what this action block of your plugin is doing, it might be a good idea to provide a clear definition inside the action block itself. Maybe something like:
"This plugin action creates a 'virtual new sunset time' based on an offset entered by the user in the first entry box, which can be 120 minutes prior to 120 minutes after true (unmodified) sunset time. Furthermore, this new virual sunset time can be further modified if the Weather compensation factor is used. Although the maximum amount of modification time to be applied is entered by the user, the actual amount of this additional time factor is calculated by the plugin automatically based on actual weather conditions obtained from the internet. Finally, the result of this action block returns True if, at the time this action block is executed, the Sun would have been down according to the calculated 'vritual new sunset time'.
Note: the true (unmodified) sunset time can be obtained by executing this action block and examining the print results in the log.
For further information and help: reference to this forum thread."

Ok, I will be testing some more in the next days and will get back if any issues/comments. Until then: thank you very much for your work and congratulations on the results thusfar!

Regards,
Perry
piert
Experienced User
 
Posts: 116
Joined: Tue Jun 14, 2011 2:53 pm

Re: SunTracker - with moving ghost

Postby krambriw » Tue Jul 26, 2011 6:11 pm

Hi Perry, thanks for your nice suggestions, I do agree, it is worth improving on the documentation so thanks for the draft

Would this not make it impossible to catch all related events (i.e. also the "IsSunDown: True") with using a wildcard? Or do you have another solution to catch events?


This depends on how you catch the events. If you just use macros, its very easy to drag and drop the respective event to the correct macro. The payloads are not used at all in this case. If you write a script or a plugin, yoy can easily take benefit of the payload content. To make it fit better with wild card matching I could change the event format to "IsSunDown.True" and "IsSunDown.False" respectivily.

Regarding the content of the payload, I see a couple of possibilities; one possibility is to extend the payload content with more information and having a suitable delimiter like this "False|Real sunset expected at|2132|Virtual sunset expected at|2032|Remaining time to Virtual Sunset|36". Another possibility is to generate one event per each info.

Best regards, Walter
krambriw
Plugin Developer
 
Posts: 1144
Joined: Sat Jun 30, 2007 2:51 pm

Re: SunTracker - with moving ghost

Postby piert » Tue Jul 26, 2011 6:13 pm

I just had to share this:

I was doing experimenting with -30 min offset and full weather compensation of 60 minutes and it struck me as strange that I got different results when testing this two times in a row with only a few minutes in between the test.

20:01:11 (-30, 60, u'Overcast', 'Sunset expected at : ', '2129', 'Minutes left to wait: ', 28, 'Minutes adjusted: ', -60, 'IsSunDown: ', False)
20:01:11 print: it is still light
20:01:11 Main.IsSunDown: False False

then 2 minutes later:

20:03:28 (-30, 60, u'Cloudy', 'Sunset expected at : ', '2129', 'Minutes left to wait: ', -4, 'Minutes adjusted: ', -90, 'IsSunDown: ', True)
20:03:28 print: it is dark man
20:03:28 Main.IsSunDown: True True

After further examination I found the difference in conditions: it had changed from Overcast to Cloudy conditions (which I must admit is correct when looking out the window!), resulting in an extra 30 minutes weather compensation. This is really very cool indeed!!
piert
Experienced User
 
Posts: 116
Joined: Tue Jun 14, 2011 2:53 pm

Re: SunTracker - with moving ghost

Postby piert » Tue Jul 26, 2011 6:31 pm

krambriw wrote:To make it fit better with wild card matching I could change the event format to "IsSunDown.True" and "IsSunDown.False" respectivily.

That would be a good idea, I think.

krambriw wrote: extend the payload content with more information and having a suitable delimiter like this "False|Real sunset expected at|2132|Virtual sunset expected at|2032|Remaining time to Virtual Sunset|36".

This would be also great. I do not know if there is a limit to the number of items in a payload, otherwise I would suggest also keeping your original items there as well (value settings, minutes adjusted, type of weather condition), i.e. the information that you show in the 'information bar' that shows up in the log.
piert
Experienced User
 
Posts: 116
Joined: Tue Jun 14, 2011 2:53 pm

Re: SunTracker - with moving ghost

Postby krambriw » Tue Jul 26, 2011 7:01 pm

OK, I go ahead with the changes then.

That' cool how it is changing depending on the weather condition. I have used this feature in SunTracker a couple of years for all my outdoor lights and for some of the indoor lights in my house and it is actually working well. I'm for sure depending on the Google weather status but most of the time it is quite accurate. And it makes a difference, a cloudy evening is different to a clear sky

Bets regards, Walter
krambriw
Plugin Developer
 
Posts: 1144
Joined: Sat Jun 30, 2007 2:51 pm

Re: SunTracker - with moving ghost

Postby krambriw » Wed Jul 27, 2011 6:13 am

Here is now the updated version.
(deleted)
Lets see if it has what is needed,

Best regards, Walter
Last edited by krambriw on Thu Jul 28, 2011 6:35 am, edited 1 time in total.
krambriw
Plugin Developer
 
Posts: 1144
Joined: Sat Jun 30, 2007 2:51 pm

Re: SunTracker - with moving ghost

Postby piert » Wed Jul 27, 2011 10:47 pm

Dear Walter,

It seems there is a problem. The plugin now thinks that the sun is not down. However, when I look out the window now, I can definitely confirm that no sun is shining at the moment..... ;-)

0:42:51 Main.IsSunDown.False u"-30|60|Rain Showers|Real Sunset expected:|2124|Virtual Sunset expected:|1954|Minutes to Virtual Sunset:|1152|Minutes adjusted:|-90|IsSunDown:|False"

I think the 'IsSunDown'-check during the night should stay True until sunrise next morning, right?
Last edited by piert on Thu Jul 28, 2011 9:23 pm, edited 1 time in total.
piert
Experienced User
 
Posts: 116
Joined: Tue Jun 14, 2011 2:53 pm

Re: SunTracker - with moving ghost

Postby krambriw » Thu Jul 28, 2011 6:34 am

Dear Perry,

I thought I had that covered but....

I have changed the check so now it should stay "True" after virtual sunset until sunrise next day

I cross my fingers,
__init__.py
(135.81 KiB) Downloaded 66 times

Best regards, Walter
krambriw
Plugin Developer
 
Posts: 1144
Joined: Sat Jun 30, 2007 2:51 pm

Re: SunTracker - with moving ghost

Postby Foune » Thu Jul 28, 2011 9:02 am

Hello krambriw,

I'm new to Eventghost and Python (I've just finished my first plugin). I'm looking for integrating your plugin in my incoming automation setup. I you have some time, could you explain me some part of your code :

Code: Select all
def run(self):
        try:
            dummy (?)
        except NameError:
            dummy = 0
            prevDate = 0
            initsynch = 1
            iSynchLight = 1
            prevDate = 0
            lightON = False
            iRndm = 0
            bToggle = False

        random.jumpahead(137) (?)



And :

Code: Select all
tr = random.random() (why use random here ?)
            remain = 61.0 - int(time.strftime("%S", time.localtime())) + tr
            self.finished.wait(remain)
            self.finished.[b]clear[/b]()


I don't understand why you multiply iWeather :

Code: Select all
            if self.plugin.iGetWeather <  self.[b]iWeather * 2[/b]:
                self.plugin.iGetWeather =  self.iWeather * 2


And finally in the main loop :

Code: Select all
if self.iGetWeatherCntr == 0:
                self.currCondition = self.CheckWeatherCondition()
                self.iGetWeatherCntr = self.iGetWeather
            else:
                self.iGetWeatherCntr -= 1
...
...
remain = 60.0 - int(time.strftime("%S", time.localtime()))


--> If I understand, the main loop is launched every hour, rounded to 00 minutes : 9h00, 10h00 etc. But how often is the weather retrieved?

Thanks by advance
Foune
 
Posts: 12
Joined: Sun Jul 03, 2011 7:08 pm

Re: SunTracker - with moving ghost

Postby krambriw » Thu Jul 28, 2011 1:32 pm

Hi Foune,

Welcome, I hope you will enjoy. This is a very nice forum with a lot of helpful and experienced friends around, I'm sure you will find this very useful and good too.

I will try to explain the parts you are wondering about

1) This is a trick to set some variables with a certain value when the thread starts. Maybe can be done differently but it remains as is since the plugin was just a very long script in the beginning. The code executes and dummy is not found, an exception is raised, the variables are created and set including dummy. Next pass, dummy already exists, and the variables are not changed

2) I use random to make the threads start with a little offset in respect to each others. Before I noticed I could get a collision since the threads are accessing shared data and instead of implementing semaphores I tried this, and it has worked good enough

3) I multiply iWeather to avoid flickering of lights just because the weather is changing temporarily. Lets say that it's evening and the normal time for turning on lights are changed due to cloudy conditions. The ligts are then turned on earlier than normal. Sun breaks thrue and the weather changes. To be sure this is a stable situation, I am waiting the double time...if the sun goes away again within the double wait period, nothing happens, lights will stay on. Every time the plugin creating an event, it doubles this time to safeguard that flicker is avoided as much as possible

4) The main loop is launched every minute and the weather condition is also fetched every minute. The usage of weather condition is however "blocked" around the events as decscribed above to avoid flickering...

Best regards, Walter
krambriw
Plugin Developer
 
Posts: 1144
Joined: Sat Jun 30, 2007 2:51 pm

Re: SunTracker - with moving ghost

Postby Foune » Thu Jul 28, 2011 3:34 pm

Thank you very much for you explanations. I think that for a H24 use, the weather should be updated only every hour.
Foune
 
Posts: 12
Joined: Sun Jul 03, 2011 7:08 pm

PreviousNext

Return to Plugin Support

Who is online

Users browsing this forum: No registered users and 1 guest