Show Current Sun Position and Shadow of House (Generate SVG)


(Christian) #84

It sure worked better with the complete code :smiley:
Thanks for the tip :+1: :smiley:

I can now execute the script, and get the following result:

openhabian@openHABianPi:~$ python /etc/openhab2/scripts/shaddow.py
248.001879033
7.46388516439
No parameters specified
Done in 0.668642044067 seconds

But no SVG is being generated. I created a empty svg in folder html. But the script doesn’t update it.
Any Ideas on this matter?

thanks
Chris


(Frederic Mariën) #85

Hi,

It looks like you forgot the “update” parameter.
Try this:

python /etc/openhab2/scripts/shaddow.py update

Greetings,
Frederic


(Christian) #86

Wow, now i feel stupid! :blush:
Adding the update parameter solved my problems :slight_smile:
thanks Frederic :+1:

And thanks to Vincent for this great script! Great work :+1:


(Christian) #87

Hi Vincent,

I finally got your solution up and running, with some help by you and some others here in this topic :slight_smile:
I just have one question though. I see that the script is running and updating the svg, but returns the wrong azimut values. I have edited the script with my LONG_LAT coordinates of course.

This is my log output for the script:

2018-03-26 19:38:26.681 [INFO ] [lipse.smarthome.model.script.Shaddow] - Updating Shaddow SVG

2018-03-26 19:38:26.686 [INFO ] [lipse.smarthome.model.script.Shaddow] - 299.595063593

-13.7071667235

Done in 0.952764987946 seconds

and this is the output from the AstoSunData:

2018-03-26 19:38:24.228 [vent.ItemStateChangedEvent] - Sun_Azimuth changed from 271.81 to 272.89

2018-03-26 19:38:24.233 [vent.ItemStateChangedEvent] - AstroSunData_Position_Azimuth changed from 271.81 to 272.89

Any idea what could be wrong?


(Christian) #88

This is what I’ve changed in your python script:

FILENAME = '/etc/openhab2/html/shaddow.svg'
LATITUDE = XX.5525
LONGITUDE = XX.9779
ALTITUDE = 17.0000

# Shape of the house in a 100 by 100 units square
SHAPE = [{'x': 75.00, 'y': 22.00}, \
		{'x': 81.00, 'y': 60.00}, \
		{'x': 24.00, 'y': 73.00}, \
		{'x': 18.00, 'y': 34.00}]
self.l = Location(('HOME', 'XXXXX', LATITUDE, LONGITUDE, 'Europe/Oslo', ALTITUDE))

(Vincent Regaud) #89

Looks like you could be an hour off. Try changing the ‘Europe/Oslo’ bit.


(Christian) #90

Thanks for your reply :slight_smile:
I tried to change the timezone, but without any change in the results. I checked the astral library, and it seems to support Oslo as a City.

self.l = Location(('HOME', 'XXXXX'

Are these two parameters optional and not taken into consideration of the geo data?


(Vincent Regaud) #91

Odd, I’ll need to dig into it.

Yes they are


(Vincent Regaud) #92

Did you reboot your system since the daylight saving time change?


(Christian) #93

Yes, and did a reboot right now. Same results still :frowning:


(Vincent Regaud) #95

Let’s test, print the time variable ts to check you have the right time in the script
I know you have the right time in openHAB but maybe the javascript returns something else…

Change shaddow.py as follow:

class shaddow(object):
	"""
	Shaddow Object
	"""
	def __init__(self):

		self.debug = False 
		self.oh = openhab()
		self.astr = Astral()
		self.l = Location(('HOME', 'WATFORD', LATITUDE, LONGITUDE, 'Europe/London', ALTITUDE))
		self.sun = self.l.sun()
		ts = time.time()
                print(ts)
		self.azimuth = float(self.astr.solar_azimuth(datetime.fromtimestamp(ts), LATITUDE, LONGITUDE))

(Christian) #96

Hi Vincent,

Just updated the script with the “print (ts)”, and here’s the log output:

python /etc/openhab2/scripts/shaddow.py update
1522389308.06
120.558989318
21.6981129979
Done in 0.64107298851 seconds


(Vincent Regaud) #97

Ok, now compare the 1522389308 with the actual time
This number is a unix timestamp, you can paste it in

https://www.unixtimestamp.com/

Do it again with a “fresh” value


(Christian) #98

I see :slight_smile: I learn new stuff everytime i visit this forum. It’s great!! :slight_smile:

So, I pasted a fresh value in the link provided.

My value= 1522407311.87
Converted = 03/30/2018 @ 10:55am (UTC)
Local time when executed= 12:55am

So It seems I’m 2 hours behind in the astral setup.

Thanks
Chris


(Vincent Regaud) #99

Cool, 2 hours…
Now change the script as follow a little bit further down in the code:

                ...
		self.sunrise_azimuth = float(self.astr.solar_azimuth(self.sun['sunrise'], LATITUDE, LONGITUDE))
		self.sunset_azimuth = float(self.astr.solar_azimuth(self.sun['sunset'], LATITUDE, LONGITUDE))
		utc_offset = (datetime.fromtimestamp(ts) - datetime.utcfromtimestamp(ts)).total_seconds()/3600
		print(utc_offset)
		for h in xrange(0,24,HOURS):
			t = datetime.combine(date.today(), datetime.min.time()) + timedelta(hours=-utc_offset+h-24)
                ...

add the print(utc_offset) to check it. It should be 2 in your case but I suspect, it’s only 1


(Christian) #100

Here are my results after adding the “print(utc_offset)”

python /etc/openhab2/scripts/shaddow4.py update
1522421206.59
263.313925336
9.08693431761
2.0
Done in 0.615770101547 seconds

(Vincent Regaud) #101

Very odd
I am starting to suspect there is a bug in astral
Let me sleep on it


HABPanel RELOADED - Modern THEME / SKIN + Custom Widgets
(Christian) #102

okay. Thanks for your time and help.
Looking forward to hear from you, and possibly a clever solution :slight_smile:


(Christian) #103

Hi Vincent. Not to push or anything, but I’m just curious if you’ve though some more on my little astral issue? :slight_smile:


(Vincent Regaud) #104

Sorry, easter week-end and all.
I was wondering, perhaps wrongly, but just to make sure…
From your post #84, there is 30d difference betwwen what astral gives you and what OH astro binding gives.
30 degrees is 2 hours of sun movement, give or take.
So either astral is wrong or OH is wrong…
So I have checked in suncalc.org for the 26/03/2018 at 19:38 and it appears that astral is wrong… Mmmmmh… By 2 hours… Mmmmmmmmmmhhhhh…

So let’s try to cheat astral
change that…

		self.debug = False 
		self.oh = openhab()
		self.astr = Astral()
		self.l = Location(('HOME', 'WATFORD', LATITUDE, LONGITUDE, 'Europe/London', ALTITUDE))
		self.sun = self.l.sun()
		ts = time.time() - (2 * 86400)
		self.azimuth = float(self.astr.solar_azimuth(datetime.fromtimestamp(ts), LATITUDE, LONGITUDE))
		print(self.azimuth)
		self.elevation = float(self.astr.solar_elevation(datetime.fromtimestamp(ts), LATITUDE, LONGITUDE))
		print(self.elevation)

We basically take 2 hours off the time we inject into astral
What happens?