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

my guess would be your coordinates overlaps /or not continuing properly and therefore script can’t calculate it…

Can’t help here, I’ve played with my coordinates for a while in inkscape in order to get it right when I was doing my house.

my rotation seems correct and i have it mostly centered after a bunch of fiddling around, but its still a bit off, though not enough to trigger my OCD.

Hi everybody,

Awesome project - everything is running smoothly - SVG file generated and available at

/etc/openhab2/html

Following this

adapted with the above mentioned link to the SVG, but nothing is showing up in HABPanel - looked through the whole thread, but could not find any updated instructions. Any other way to integrate the SVG into HABPanel? Grateful for any advice.

Mischa

It seems to be a problem with too complex shapes. i simplified my house shape wich solved the shadow issue:

1 Like

This weekend, I had to re-install OpenHabian due to an SD card failure. I was able to restore all my programs and scripts (updating the new system with python3), however, when the rule runs in Openhabian, I am getting the error:

2020-06-27 06:22:41.589 [INFO ] [lipse.smarthome.model.script.Shaddow] - Traceback (most recent call last):
  File "/etc/openhab2/scripts/shaddow.py", line 8, in <module>
    import pytz
ImportError: No module named pytz

However, when I run shaddow.py from the command line, I get:


[06:20:39] openhabian@openhab:/etc/openhab2/scripts$ ./shaddow.py 
Sun azimuth: 68.35074972833864
Sun elevation: 11.094808231930188
Moon azimuth: 4.370689703196757
Moon elevation: -40.52892527060288
Done in 0:00:00.205927 seconds

Any ideas as to what I am missing?

Thanks,

~John

Hi John,

It looks like you’re missing pytz, is it possible that you have both python2 and python3 installed?
sudo pip3 install pytz

after that try
python3 ./shaddow.py update

@wllm,
I don’t think this has python 2 installed on it, It’s a new install of Openhabian Pi, I am pretty sure it has python 3 and python 3.7… I tried to install pytz with the command you suggested, this is what I got:

[09:31:02] openhabian@openhab:/etc/openhab2/scripts$ sudo pip3 install pytz
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Requirement already satisfied: pytz in /usr/local/lib/python3.7/dist-packages (2020.1)
[09:31:14] openhabian@openhab:/etc/openhab2/scripts$

I never did the python3 ./shaddow.py update, but when I did, then ran it, I am now getting this:

[09:33:44] openhabian@openhab:/etc/openhab2/scripts$ python3 ./shaddow.py update
Sun azimuth: 100.53358102885561
Sun elevation: 45.68926224664953
Moon azimuth: 48.57987073587743
Moon elevation: -35.340628199696575
Traceback (most recent call last):
  File "./shaddow.py", line 394, in <module>
    main()
  File "./shaddow.py", line 388, in main
    s.generateSVG()
  File "./shaddow.py", line 329, in generateSVG
    svg = svg + self.generatePath(LIGHT_COLOR,'none',[self.degreesToPoint(DEGS[(len(DEGS))/2],WIDTH/2+5), self.degreesToPoint(DEGS[(len(DEGS))/2],WIDTH/2+11)])
TypeError: list indices must be integers or slices, not float

however, when I run it from the command line, I am still getting:

[09:34:42] openhabian@openhab:/etc/openhab2/scripts$ ./shaddow.py 
Sun azimuth: 100.72156785315121
Sun elevation: 45.85388445111363
Moon azimuth: 48.80565971436513
Moon elevation: -35.223705606389714
Done in 0:00:00.215257 seconds
[09:35:37] openhabian@openhab:/etc/openhab2/scripts$ 

I am out of ideas… when it runs in OpenHAB, the log shows:

2020-06-28 09:36:17.792 [INFO ] [lipse.smarthome.model.script.Shaddow] - Traceback (most recent call last):
  File "/etc/openhab2/scripts/shaddow.py", line 8, in <module>
    import pytz

~Edit - forgot to include the OpenHAB log entry

It looks like python can’t find the module when it’s being run from openhab, it could be that the “search path” is not passed along correctly or some missing environment variables.

This might be a little bit cheating but you could try to add the following line below import sys in shaddow.py

sys.path.append("/usr/local/lib/python3.7/dist-packages")

I’m using the following rule to trigger the script:

rule "Shadow SVG"
when
    Item AstrometrySun_Position_Azimuth received update
then
if(SystemStarting.state == ON || SystemStarting.state == NULL) {
  logInfo("SVGTriggers", "SVGTriggers::ShadowSVG: PASS SYSTEM STARTUP IN PROGRESS!")
  return
}
  logInfo("SVGTriggers", "SVGTriggers::ShadowSVG: TRIGGERED")
  val resp =  executeCommandLine("/usr/local/bin/python3 /usr/local/etc/openhab2/scripts/azimuthsvg.py update", 10000)
  logInfo("Shaddow", "Updating Shadow SVG")
  logInfo("Shaddow", resp)
end

Edit: Added my rule
Edit2: fix typo

This is getting me closer, I edited my rule to reflect the path for the pytz packages, however in my log I am now getting:

Execution failed (Exit value: -559038737. Caused by java.io.IOException: Cannot run program "/usr/local/lib/python3.7/dist-packages" (in directory "."): error=13, Permission denied)

Looking at the permissions in the directory and all the files, they all seem to be “drwxrwsr-x”, so in my mind, it should run, but does not appear so with the openhab user or group

~John

From your latest error it looks like java is trying to execute /usr/local/lib/python3.7/dist-packages as a program, this is a directory.

I think that your rule was working fine because of the python output. the ‘sys.path.append…’ can be added to the shaddow.py script below ‘import sys’. However this is kind of a cheat because it should be done by the OS usually.

for example

from datetime import datetime, timedelta, date, time
import sys
sys.path.append("/usr/local/lib/python3.7/dist-packages")
import pytz
import pylunar

@wllm,

I did add that to my shaddow.py script, here is the top part of it:

from __future__ import print_function
import math
from datetime import datetime, timedelta, date, time
import sys
sys.path.append("/usr/local/lib/python3.7/dist-packages")
import pytz
import pylunar
from astral import Astral
from astral import Location

The rule has never worked properly since my server rebuild. However the script runs fine from the command line. It is only within OpenHAB and inside VS Code, that the script does not work…

~John

Hello, it didn’t work for me.

Please find attached my logfile

2020-07-14 13:10:25.860 [INFO ] [lipse.smarthome.model.script.Shaddow] - Updating Shaddow SVG

2020-07-14 13:10:25.865 [INFO ] [lipse.smarthome.model.script.Shaddow] - from: can’t read /var/mail/future

/etc/openhab2/scripts/shaddow.py: 2: /etc/openhab2/scripts/shaddow.py:

: not found

/etc/openhab2/scripts/shaddow.py: 3: /etc/openhab2/scripts/shaddow.py: import: not found

/etc/openhab2/scripts/shaddow.py: 4: /etc/openhab2/scripts/shaddow.py:

: not found

from: can’t read /var/mail/datetime

/etc/openhab2/scripts/shaddow.py: 6: /etc/openhab2/scripts/shaddow.py: import: not found

/etc/openhab2/scripts/shaddow.py: 7: /etc/openhab2/scripts/shaddow.py: import: not found

/etc/openhab2/scripts/shaddow.py: 8: /etc/openhab2/scripts/shaddow.py: import: not found

/etc/openhab2/scripts/shaddow.py: 9: /etc/openhab2/scripts/shaddow.py:

: not found

from: can’t read /var/mail/astral

from: can’t read /var/mail/astral

/etc/openhab2/scripts/shaddow.py: 12: /etc/openhab2/scripts/shaddow.py:

: not found

/etc/openhab2/scripts/shaddow.py: 13: /etc/openhab2/scripts/shaddow.py: WIDTH: not found

/etc/openhab2/scripts/shaddow.py: 14: /etc/openhab2/scripts/shaddow.py: HEIGHT: not found

/etc/openhab2/scripts/shaddow.py: 15: /etc/openhab2/scripts/shaddow.py: PRIMARY_COLOR: not found

/etc/openhab2/scripts/shaddow.py: 16: /etc/openhab2/scripts/shaddow.py: LIGHT_COLOR: not found

/etc/openhab2/scripts/shaddow.py: 17: /etc/openhab2/scripts/shaddow.py: BG_COLOR: not found

/etc/openhab2/scripts/shaddow.py: 18: /etc/openhab2/scripts/shaddow.py: SUN_COLOR: not found

/etc/openhab2/scripts/shaddow.py: 19: /etc/openhab2/scripts/shaddow.py: SUN_RADIUS: not found

/etc/openhab2/scripts/shaddow.py: 20: /etc/openhab2/scripts/shaddow.py:

: not found

/etc/openhab2/scripts/shaddow.py: 21: /etc/openhab2/scripts/shaddow.py: MOON_COLOR: not found

/etc/openhab2/scripts/shaddow.py: 22: /etc/openhab2/scripts/shaddow.py: MOON_RADIUS: not found

/etc/openhab2/scripts/shaddow.py: 23: /etc/openhab2/scripts/shaddow.py: STROKE_WIDTH: not found

/etc/openhab2/scripts/shaddow.py: 24: /etc/openhab2/scripts/shaddow.py: FILENAME: not found

/etc/openhab2/scripts/shaddow.py: 25: /etc/openhab2/scripts/shaddow.py:

: not found

/etc/openhab2/scripts/shaddow.py: 26: /etc/openhab2/scripts/shaddow.py: LATITUDE: not found

/etc/openhab2/scripts/shaddow.py: 27: /etc/openhab2/scripts/shaddow.py: LONGITUDE: not found

/etc/openhab2/scripts/shaddow.py: 28: /etc/openhab2/scripts/shaddow.py: ALTITUDE: not found

/etc/openhab2/scripts/shaddow.py: 29: /etc/openhab2/scripts/shaddow.py: TIMEZONE: not found

/etc/openhab2/scripts/shaddow.py: 30: /etc/openhab2/scripts/shaddow.py: TOWN: not found

/etc/openhab2/scripts/shaddow.py: 31: /etc/openhab2/scripts/shaddow.py:

: not found

/etc/openhab2/scripts/shaddow.py: 33: /etc/openhab2/scripts/shaddow.py: SHAPE: not found

/etc/openhab2/scripts/shaddow.py: 34: /etc/openhab2/scripts/shaddow.py: {x:: not found

/etc/openhab2/scripts/shaddow.py: 35: /etc/openhab2/scripts/shaddow.py: {x:: not found

/etc/openhab2/scripts/shaddow.py: 36: /etc/openhab2/scripts/shaddow.py:

: not found

/etc/openhab2/scripts/shaddow.py: 37: /etc/openhab2/scripts/shaddow.py: HOURS: not found

/etc/openhab2/scripts/shaddow.py: 38: /etc/openhab2/scripts/shaddow.py: DEGS: not found

/etc/openhab2/scripts/shaddow.py: 39: /etc/openhab2/scripts/shaddow.py:

: not found

/etc/openhab2/scripts/shaddow.py: 41: /etc/openhab2/scripts/shaddow.py: Syntax error: “(” unexpected

can someone please upload again all thinks, rules and scripts i need? i try since a few days to geht this work… :frowning:

everything you need is already here, just take your time to elaborate

What was your imagination? Finding a ready-to-use version for any of the innumerable possible scenarios in the ‘home automation’ ecosystem? (which OH offers a lot btw.)

If that is, what you are looking for, an open-source project which depends on the work of a lot of voluntary contributors might not be a good decision in the first place.
There is no way around dealing with things you want to implement. - Sometimes you are lucky and there is already a soloution from someone else who invests his spare-time, sometimes not - and then its your chance to give something back.

And IMO, you won’t find any alternatives with this mindset anyway. If it´s paid software or an open-source project - there are always limits.

4 Likes

funny … OH is the coolest way how to automate anything, you just suck in learning and want everything to be done by others… well guess what, that’s not the way how world is working.

anyway my elaboration on sun position script is complete and even rewritten to python3, you are just being lazy to follow posts and guides.

5 Likes

How can I add the wind position as in your project?Can you share the code pls?

Hi,
have you found a solution to your problem? I am having the same issues. The script works in the command line but not from within openhab.
The missing module is the astral.

how hard it can be to follow simple guidelines…?