Created
May 22, 2015 14:43
-
-
Save Elwell/8cc09d26cb1a0ece3a1a to your computer and use it in GitHub Desktop.
Sunrise / Sunset calculation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
andrew@mythic:~$ cat bin/get_sunrise.py | |
#!/usr/bin/python | |
# calculate sunrise/sunset times for location | |
# Andrew Elwell <[email protected]> 2013-09-02 | |
import ephem | |
import ConfigParser | |
import paho.mqtt.client as mqtt | |
config = "/home/andrew/solarmon.cfg" | |
settings = ConfigParser.RawConfigParser() | |
settings.read(config) | |
home = ephem.Observer() | |
home.lat = settings.get('general', 'lat') | |
home.lon = settings.get('general', 'lon') | |
#print home.lat, home.lon | |
sunrise = ephem.localtime(home.next_rising(ephem.Sun())) | |
sunset = ephem.localtime(home.next_setting(ephem.Sun())) | |
#print "sunrise: %s, sunset: %s" % (sunrise, sunset) | |
# lets publish to broker | |
broker = settings.get('mosquitto', 'broker') | |
client = mqtt.Client() | |
client.connect(broker) | |
client.publish("sunrise", sunrise.strftime("%Y-%m-%d %H:%M"), qos=0, retain=True) | |
client.publish("sunset", sunset.strftime("%Y-%m-%d %H:%M"), qos=0, retain=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; config file for home | |
[general] | |
lat = 51.50081 | |
lon = -0.14258 | |
[mosquitto] | |
broker = 192.0.2.10 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment