Python Plugin: MoonPhases

Python and python framework
assenzuid
Posts: 181
Joined: Friday 13 November 2015 10:11
Target OS: Raspberry Pi
Domoticz version: Beta
Location: The Netherlands, Emmen Area
Contact:

Re: Python Plugin: MoonPhases

Post by assenzuid » Wednesday 07 February 2018 11:14

Just updated to the latest beta (3.8890), will try it again.

assenzuid
Posts: 181
Joined: Friday 13 November 2015 10:11
Target OS: Raspberry Pi
Domoticz version: Beta
Location: The Netherlands, Emmen Area
Contact:

Re: Python Plugin: MoonPhases

Post by assenzuid » Wednesday 07 February 2018 11:42

assenzuid wrote:
Wednesday 07 February 2018 11:14
Just updated to the latest beta (3.8890), will try it again.
Same result

User avatar
ycahome
Posts: 215
Joined: Sunday 12 February 2017 11:55
Target OS: Linux
Domoticz version: lat Beta
Contact:

Re: Python Plugin: MoonPhases

Post by ycahome » Wednesday 07 February 2018 13:02

Cannot perform tests on Raspberry because all 3 raspis I own are productive.

I have cloned my Ubuntu based Domoticz (its nice to have VMware Virtualization) and upgraded to Beta V.3.8891.

Seems to work ok

User avatar
htilburgs
Posts: 509
Joined: Tuesday 03 November 2015 12:01
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Python Plugin: MoonPhases

Post by htilburgs » Wednesday 07 February 2018 14:12

ycahome wrote:
Wednesday 07 February 2018 9:48
htilburgs wrote:
Wednesday 07 February 2018 0:59
After installing MoonPhases Plugin, Domoticz Crashes:

Domoticz v3.8889
Domoticz Log Entry:
Hi there again.

Your installation seems ok. I can't tell what exactly is causing this behavior.

You remind me some months ago that I personally faced the same behavior with another plugin.
Ended up to reinstall Domoticz and recreate database/sensors from scratch.

Don't get me wrong, am not saying that the plugin is correct and your installation is wrong. Just saying that didn't found any solution for "Domoticz received fatal signal 11 !..." error.

Do you have other plugins working?
Domoticz is fresh compiled because of the same Error with the buienradar plugin

Other plugins (pimonitor, batterylevel) work nice.
Think is an Python issue, but not sure
Hardware:
RPi3 - Aeon Labs Z-Stick GEN5 - Fibaro Dimmer 2 - Fibaro Roller Shutter 2 - Fibaro Smoke Sensor - Yeelight RGBW Led bulb - Yeelight Smart LED Light Strip - Neo Coolcam PIR Motion Sensor - Neo Coolcam PowerPlug - Nest Thermostat v3

aleph0
Posts: 72
Joined: Thursday 12 May 2016 15:47
Target OS: Linux
Domoticz version: 4.9728
Location: South of France
Contact:

Re: Python Plugin: MoonPhases

Post by aleph0 » Wednesday 07 February 2018 20:44

Marci wrote:
Wednesday 07 February 2018 0:24
Umm no... % cloud cover. [...] DarkSkies makes it available in their JSON feed but the current DarkSkies sensors for Domoticz don’t utilise it.
Hi ! I got the same need a few month ago, so I wrote a script for that. I shared it for you here viewtopic.php?f=61&t=22090

User avatar
fubar
Posts: 17
Joined: Friday 19 January 2018 4:44
Target OS: Linux
Domoticz version: beta
Location: Sydney
Contact:

Re: Python Plugin: MoonPhases

Post by fubar » Saturday 10 March 2018 4:22

Excellent plugin - just what I was looking for - thanks @ycahome

Installed without drama to the current beta, once I'd fixed indentation errors from cutting and pasting the python script.

Now, the only problem is that all of the images are upside down!! :o

This may come as a surprise for those living in the Northern hemisphere, but here in Australia we see the moon the correct way up - the full moon looks more like a rabbit here - not at all the grinning old man of the Northern hemisphere.

For anyone else living south of the equator, I wrote a quick script to rotate the images and freshen the icons. Enjoy!

To fix the icons, I just had to uninstall the moon phases hardware entry; run the script to freshen the individual icon archives; replace the original zips in the plugins folder; restart domoticz; reinstall the plugin as hardware and reconfigure with my weather underground api key


Code: Select all

# turn moon right way up for images kindly provided for domoticz plugin
# see  http://www.domoticz.com/forum/viewtopic.php?f=65&t=21993
# ross lazarus me fecit march 10 2018
# run this in a temporary directory containing all the moon icon zip files and they will be
# rotated 180 degrees to suit the Southern hemisphere

import os
ourd = os.getcwd()
flist = os.listdir('.')
flist = [x for x in flist if x[0] == 'M']
for f in flist:
    os.chdir(ourd)
    dname = f.split('.')[0]
    try:
        os.mkdir(dname)
    except:
        print dname, 'already exists'
    os.chdir(dname)
    try:
       os.system('unzip -o ../%s' % dname)
    except:
       print f, 'zip contents already exist'
    pnames = os.listdir('.')
    pnames = [x for x in pnames if x.endswith('.png')]
    for pname in pnames:
        os.system('mogrify -rotate "180" ./%s' % pname)   
        print 'rotated',pname
    os.system('zip -f ../%s' % dname)
    print 'freshened',dname


User avatar
ycahome
Posts: 215
Joined: Sunday 12 February 2017 11:55
Target OS: Linux
Domoticz version: lat Beta
Contact:

Re: Python Plugin: MoonPhases

Post by ycahome » Saturday 10 March 2018 9:20

fubar wrote:
Saturday 10 March 2018 4:22

To fix the icons, I just had to uninstall the moon phases hardware entry; run the script to freshen the individual icon archives; replace the original zips in the plugins folder; restart domoticz; reinstall the plugin as hardware and reconfigure with my weather underground api key


Code: Select all

# turn moon right way up for images kindly provided for domoticz plugin
# see  http://www.domoticz.com/forum/viewtopic.php?f=65&t=21993
# ross lazarus me fecit march 10 2018
# run this in a temporary directory containing all the moon icon zip files and they will be
# rotated 180 degrees to suit the Southern hemisphere

import os
ourd = os.getcwd()
flist = os.listdir('.')
flist = [x for x in flist if x[0] == 'M']
for f in flist:
    os.chdir(ourd)
    dname = f.split('.')[0]
    try:
        os.mkdir(dname)
    except:
        print dname, 'already exists'
    os.chdir(dname)
    try:
       os.system('unzip -o ../%s' % dname)
    except:
       print f, 'zip contents already exist'
    pnames = os.listdir('.')
    pnames = [x for x in pnames if x.endswith('.png')]
    for pname in pnames:
        os.system('mogrify -rotate "180" ./%s' % pname)   
        print 'rotated',pname
    os.system('zip -f ../%s' % dname)
    print 'freshened',dname


Nice work.
can we detect the hemisphere somehow safely (I suppose that city and timezone are not a valid indication)? then we can select the iconset to install or even select icon to update device (too many devices will be added).

User avatar
fubar
Posts: 17
Joined: Friday 19 January 2018 4:44
Target OS: Linux
Domoticz version: beta
Location: Sydney
Contact:

Re: Python Plugin: MoonPhases

Post by fubar » Sunday 11 March 2018 1:59

can we detect the hemisphere somehow safely (I suppose that city and timezone are not a valid indication)? then we can select the iconset to install or even select icon to update device (too many devices will be added).

Yes - below is the wunderground json I get for Sydney and it has hemisphere as a subkey of moon_phase so it should be relatively simple. I'll change the script to create a separate set of icons with S in the name for the southern hemisphere that you can bundle up although one wrinkle is that the amount of rotation needed to make the image look right for the local latitude varies but let's not get carried away!!

Code: Select all

{
  "response": {
  "version":"0.1",
  "termsofService":"http://www.wunderground.com/weather/api/d/terms.html",
  "features": {
  "astronomy": 1
  }
	}
		,	"moon_phase": {
		"percentIlluminated":"36",
		"ageOfMoon":"23",
		"phaseofMoon":"Last Quarter",
		"hemisphere":"South",
		"current_time": {
		"hour":"10",
		"minute":"39"
		},
		"sunrise": {
		"hour":"6",
		"minute":"50"
		},
		"sunset": {
		"hour":"19",
		"minute":"19"
		},
		"moonrise": {
		"hour":"0",
		"minute":"54"
		},
		"moonset": {
		"hour":"15",
		"minute":"14"
		}
	},
	"sun_phase": {
		"sunrise": {
		"hour":"6",
		"minute":"50"
		},
		"sunset": {
		"hour":"19",
		"minute":"19"
		}
	}
}

User avatar
ycahome
Posts: 215
Joined: Sunday 12 February 2017 11:55
Target OS: Linux
Domoticz version: lat Beta
Contact:

Re: Python Plugin: MoonPhases

Post by ycahome » Sunday 11 March 2018 8:50

fubar wrote:
Sunday 11 March 2018 1:59
. I'll change the script to create a separate set of icons with S in the name for the southern hemisphere that you can bundle up
Just upload or PM with the iconset.

Thanks

User avatar
fubar
Posts: 17
Joined: Friday 19 January 2018 4:44
Target OS: Linux
Domoticz version: beta
Location: Sydney
Contact:

Re: Python Plugin: MoonPhases

Post by fubar » Sunday 11 March 2018 13:48

I have it working - needed some tweaks to plugin.py and new zips with the SH_ icons. Let me run it for a few days then I could post here or if you have a github repo how about a pull request?

User avatar
ycahome
Posts: 215
Joined: Sunday 12 February 2017 11:55
Target OS: Linux
Domoticz version: lat Beta
Contact:

Re: Python Plugin: MoonPhases

Post by ycahome » Sunday 11 March 2018 13:54

Pull request will be the most preferable way.

Changed the initial post after our discussion to point new users to GitHub!! ;) ;)

https://github.com/ycahome/MoonPhases

BTW: did you tried "Python plugin manager" plugin??????

Regards

User avatar
fubar
Posts: 17
Joined: Friday 19 January 2018 4:44
Target OS: Linux
Domoticz version: beta
Location: Sydney
Contact:

Re: Python Plugin: MoonPhases

Post by fubar » Monday 12 March 2018 0:40

Pull request submitted. Seems to be working for me...

I'll check out and try the python plugin manager - thanks for all your work!

[update] Installed the ppm and used it to setup the NUT device for my ups - worked perfectly. So far so good - nice work!

Been poking around domoticz custom image handling - have a headache from all that C code - but clearly, removing a plugin will involve removing all custom images both from the database and from the .../www/images/ cache too - I had all sorts of fun trying to replace already installed images, fighting brower caches and other ugly layers of complexity. Making new ones was much easier than replacing old ones!

I'm seeing strangeness in the debug log - only the new SH_ icons appear to be being loaded at start - I still haven't figured out why...

Code: Select all

2018-03-12 17:58:49.487 (Moon days) Initialized version 1.0.0, author 'ycahome ft. jackslayter'
2018-03-12 17:58:49.488 (Moon days) Debug log level set to: 'true'.
2018-03-12 17:58:49.488 (Moon days) 'HardwareID':'9'
2018-03-12 17:58:49.488 (Moon days) 'HomeFolder':'/home/rlazarus/domoticz/plugins/MoonPhases/'
2018-03-12 17:58:49.488 (Moon days) 'Version':'1.0.0'
2018-03-12 17:58:49.488 (Moon days) 'Author':'ycahome ft. jackslayter'
2018-03-12 17:58:49.488 (Moon days) 'Name':'Moon days'
2018-03-12 17:58:49.489 (Moon days) 'Port':'0'
2018-03-12 17:58:49.489 (Moon days) 'Key':'MoonPhases'
2018-03-12 17:58:49.489 (Moon days) 'Mode1':'081dbdbeaac85246'
2018-03-12 17:58:49.489 (Moon days) 'Mode2':'au'
2018-03-12 17:58:49.489 (Moon days) 'Mode3':'sydney'
2018-03-12 17:58:49.489 (Moon days) 'Mode4':'60'
2018-03-12 17:58:49.489 (Moon days) 'Mode6':'Debug'
2018-03-12 17:58:49.489 (Moon days) 'DomoticzVersion':'3.9014'
2018-03-12 17:58:49.489 (Moon days) 'DomoticzHash':'6b5dd0b7'
2018-03-12 17:58:49.489 (Moon days) 'DomoticzBuildTime':'2018-03-11 00:16:03'
2018-03-12 17:58:49.489 (Moon days) Device count: 0
2018-03-12 17:58:49.489 (Moon days) Creating images from file '/home/rlazarus/domoticz/plugins/MoonPhases/SH_MoonPhases1NM.zip'.
2018-03-12 17:58:49.497 (Moon days) Added icon: SH_MoonPhases1NM from file SH_MoonPhases1NM.zip
2018-03-12 17:58:49.497 (Moon days) Creating images from file '/home/rlazarus/domoticz/plugins/MoonPhases/SH_MoonPhases2WC.zip'.
2018-03-12 17:58:49.500 (Moon days) Added icon: SH_MoonPhases2WC from file SH_MoonPhases2WC.zip
2018-03-12 17:58:49.500 (Moon days) Creating images from file '/home/rlazarus/domoticz/plugins/MoonPhases/SH_MoonPhases3FQ.zip'.
2018-03-12 17:58:49.503 (Moon days) Added icon: SH_MoonPhases3FQ from file SH_MoonPhases3FQ.zip
2018-03-12 17:58:49.503 (Moon days) Creating images from file '/home/rlazarus/domoticz/plugins/MoonPhases/SH_MoonPhases4WG.zip'.
2018-03-12 17:58:49.505 (Moon days) Added icon: SH_MoonPhases4WG from file SH_MoonPhases4WG.zip
2018-03-12 17:58:49.505 (Moon days) Creating images from file '/home/rlazarus/domoticz/plugins/MoonPhases/SH_MoonPhases5FM.zip'.
2018-03-12 17:58:49.508 (Moon days) Added icon: SH_MoonPhases5FM from file SH_MoonPhases5FM.zip
2018-03-12 17:58:49.508 (Moon days) Creating images from file '/home/rlazarus/domoticz/plugins/MoonPhases/SH_MoonPhases6WG.zip'.
2018-03-12 17:58:49.511 (Moon days) Added icon: SH_MoonPhases6WG from file SH_MoonPhases6WG.zip
2018-03-12 17:58:49.511 (Moon days) Creating images from file '/home/rlazarus/domoticz/plugins/MoonPhases/SH_MoonPhases7LQ.zip'.
2018-03-12 17:58:49.513 (Moon days) Added icon: SH_MoonPhases7LQ from file SH_MoonPhases7LQ.zip
2018-03-12 17:58:49.513 (Moon days) Number of icons loaded = 9
2018-03-12 17:58:49.513 (Moon days) Icon 101 MoonPhases1NM
2018-03-12 17:58:49.513 (Moon days) Icon 102 MoonPhases2WC
2018-03-12 17:58:49.513 (Moon days) Icon 103 MoonPhases3FQ
2018-03-12 17:58:49.513 (Moon days) Icon 104 MoonPhases4WG
2018-03-12 17:58:49.513 (Moon days) Icon 105 MoonPhases5FM
2018-03-12 17:58:49.513 (Moon days) Icon 106 MoonPhases6WG
2018-03-12 17:58:49.513 (Moon days) Icon 107 MoonPhases7LQ
2018-03-12 17:58:49.513 (Moon days) Icon 108 MoonPhases8WC
2018-03-12 17:58:49.514 (Moon days) Icon 116 SH_MoonPhases8WC
2018-03-12 17:58:49.514 (Moon days) Creating device 'Status'.
Last edited by fubar on Monday 12 March 2018 8:59, edited 1 time in total.

User avatar
fubar
Posts: 17
Joined: Friday 19 January 2018 4:44
Target OS: Linux
Domoticz version: beta
Location: Sydney
Contact:

Re: Python Plugin: MoonPhases

Post by fubar » Monday 12 March 2018 8:55

I got the widget to show the moon phase instead of a title - don't need to be reminded that it's the moon ;)
moonphases_2.png
moonphases_2.png (16.66 KiB) Viewed 1120 times
It's a brutal hack - change the Name every time but I'm not sure it matters - let me know if there's a better way?

Pull request updated.

User avatar
ycahome
Posts: 215
Joined: Sunday 12 February 2017 11:55
Target OS: Linux
Domoticz version: lat Beta
Contact:

Re: Python Plugin: MoonPhases

Post by ycahome » Monday 12 March 2018 22:01

I don't see your modifications, are you sure that you checked all my comments?

User avatar
fubar
Posts: 17
Joined: Friday 19 January 2018 4:44
Target OS: Linux
Domoticz version: beta
Location: Sydney
Contact:

Re: Python Plugin: MoonPhases

Post by fubar » Monday 12 March 2018 23:51

For now it's working for me as I don't need any scripting for it. I've added some responses on the pull request.

To make it more generally useful I'll need some advice on how to achieve a decent looking dashboard widget without the current hack of changing the Name parameter - need a generic widget allowing more text to be displayed. I spent some time spelunking the documentation on typenames and their handling but gave up as it's confusing - it seems that the generic text device cannot have an updated icon which seems amazing to me while the custom device doesn't allow much customising of the text fields displayed...

:(

brainpaincgn
Posts: 10
Joined: Wednesday 03 February 2016 1:35
Target OS: Raspberry Pi
Domoticz version: 3.9052
Location: Cologne, Germany
Contact:

Re: Python Plugin: MoonPhases

Post by brainpaincgn » Thursday 22 March 2018 1:28

Hi,

is someone else getting 'key errors'?

2018-03-22 00:24:42.788 Error: (PP-Manager) Something went wrong with update of MoonPhases
2018-03-22 00:24:42.808 Error: (PP-Manager) Something went wrong with update of BatteryLevel
2018-03-22 00:24:52.696 Error: (Moon Phases) 'onHeartbeat' failed 'KeyError'.
2018-03-22 00:24:52.696 Error: (Moon Phases) ----> Line 183 in /home/pi/domoticz/plugins/MoonPhases/plugin.py, function onHeartbeat
2018-03-22 00:24:52.696 Error: (Moon Phases) ----> Line 120 in /home/pi/domoticz/plugins/MoonPhases/plugin.py, function onHeartbeat

I created a new API-key on the WU site, I tried my existing key, but I am still getting the same errors...

I installed the plugin via Plugin Manager.

Thanks in advance,
Sascha
--
brainpaincgn

User avatar
fubar
Posts: 17
Joined: Friday 19 January 2018 4:44
Target OS: Linux
Domoticz version: beta
Location: Sydney
Contact:

Re: Python Plugin: MoonPhases

Post by fubar » Thursday 22 March 2018 7:18

Works for me.
Debug logs may help - turn debug on in both ppmanager and moonphases hardware entries?
Both of those could be connection issues...but the debug log will give a lot more info including the weather underground url being called - it should show json with the appropriate local data in your browser if moonphases is configured correctly?

Weather underground, like most services, has occasional disturbances

User avatar
ycahome
Posts: 215
Joined: Sunday 12 February 2017 11:55
Target OS: Linux
Domoticz version: lat Beta
Contact:

Re: Python Plugin: MoonPhases

Post by ycahome » Thursday 22 March 2018 18:35

Seems that you are facing problems with MY plugins :lol: :lol: :P :P

Can you restart Domoticz, enable debug on "MoonPhases" and post your log in a code placeholder?

brainpaincgn
Posts: 10
Joined: Wednesday 03 February 2016 1:35
Target OS: Raspberry Pi
Domoticz version: 3.9052
Location: Cologne, Germany
Contact:

Re: Python Plugin: MoonPhases

Post by brainpaincgn » Thursday 22 March 2018 21:59

Hi ycahome,

Could you please tell me what a code placeholder is? :?

Thanks,
Sascha
--
brainpaincgn

User avatar
ycahome
Posts: 215
Joined: Sunday 12 February 2017 11:55
Target OS: Linux
Domoticz version: lat Beta
Contact:

Re: Python Plugin: MoonPhases

Post by ycahome » Thursday 22 March 2018 22:14

It is a section on your post that makes code/logs to appear in a more readable way.

Code: Select all

Use the "</>" button 


Post Reply

Who is online

Users browsing this forum: Markies, moroen and 5 guests