sjef86
(Christian)
March 7, 2018, 3:13pm
84
It sure worked better with the complete code
Thanks for the tip
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
1 Like
FredericMa
(Frederic Mariën)
March 8, 2018, 7:10am
85
Hi,
It looks like you forgot the “update” parameter.
Try this:
python /etc/openhab2/scripts/shaddow.py update
Greetings,
Frederic
sjef86
(Christian)
March 10, 2018, 10:58pm
86
sjef86
(Christian)
March 26, 2018, 5:50pm
87
Hi Vincent,
I finally got your solution up and running, with some help by you and some others here in this topic
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?
sjef86
(Christian)
March 26, 2018, 5:54pm
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))
vzorglub
(Vincent Regaud)
March 27, 2018, 5:57am
89
Looks like you could be an hour off. Try changing the ‘Europe/Oslo’ bit.
sjef86
(Christian)
March 27, 2018, 2:58pm
90
vzorglub:
WATFORD
Thanks for your reply
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?
vzorglub
(Vincent Regaud)
March 27, 2018, 3:01pm
91
Odd, I’ll need to dig into it.
Yes they are
vzorglub
(Vincent Regaud)
March 27, 2018, 3:17pm
92
Did you reboot your system since the daylight saving time change?
sjef86
(Christian)
March 27, 2018, 3:30pm
93
Yes, and did a reboot right now. Same results still
vzorglub
(Vincent Regaud)
March 28, 2018, 6:21am
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))
sjef86
(Christian)
March 30, 2018, 5:57am
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
vzorglub
(Vincent Regaud)
March 30, 2018, 6:08am
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
sjef86
(Christian)
March 30, 2018, 11:00am
98
I see I learn new stuff everytime i visit this forum. It’s great!!
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
vzorglub
(Vincent Regaud)
March 30, 2018, 11:07am
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
sjef86
(Christian)
March 30, 2018, 2:48pm
100
vzorglub:
print(utc_offset)
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
vzorglub
(Vincent Regaud)
March 30, 2018, 4:41pm
101
Very odd
I am starting to suspect there is a bug in astral
Let me sleep on it
sjef86
(Christian)
March 30, 2018, 4:55pm
102
okay. Thanks for your time and help.
Looking forward to hear from you, and possibly a clever solution
sjef86
(Christian)
April 1, 2018, 5:17pm
103
Hi Vincent. Not to push or anything, but I’m just curious if you’ve though some more on my little astral issue?
vzorglub
(Vincent Regaud)
April 1, 2018, 6:54pm
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?