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


(Marco Schnubel) #42

Hmmmm, i think thats not the expecting result :roll_eyes:
shaddow

Any ideas?


(Marco Schnubel) #43

Problem seems to be solved, patience was the key :wink:

But the sun position is not correct, i think its because of a wrong shape of the house. How do you create it? The basic form is correct, but it seems to be inverted. How do i align the shape correctly?

schatten

Edit: Problem solved…


(Marco Schnubel) #44

@pmpkk I have to give you a really big “Thank You” for your great theme and this script :heart_eyes::wink:


(Marco Schnubel) #45

@Max1968

Would you be so kind to tell my how and where in the shaddow.py you inserted the icons?


(SiHui) #47

Needs to be Sun_Elevation :innocent:


(Salexes) #48

I do not use hab panel yet but I want to add exactly this once I have my habpanel set up.

But in additon to that…what I currently try to do is to automate my rollershutters and I think it could be possible to realize with parts of your script.

What I wan to do is the following:
I want to automatically close the rollershutters if the sun is shining through the window.

So my question is how can I use this script to achive this? Could you lead me the right way ? I am quite new to python code and do not understand much of it.

kind regards,
salexes


(SiHui) #49

All you need for that task is the azimuth angle from the astro binding:

https://docs.openhab.org/addons/bindings/astro/readme.html


(Ralf Klüber) #50

Eventuell hilft das:

 
var Number diffToFasade = 30  // Quasi Abweichung von Nord deiner Hausausrichtung
rule "Update Fassade"
when
  Item Sun_Height_ext changed or
  Item Sun_Azimut_ext changed
then
	logDebug("Sun","Update Fassade")
	
	var height                = Sun_Height_ext.state
 	var azimut                = Sun_Azimut_ext.state

	var eastFasadeIn   = (  90 - 90 + diffToFasade )   //For example: -26.09 or 333,91 - because 0 and 360 is north
	var eastFasadeOut  = (  90 + 90 + diffToFasade )   //153,91
	var southFasadeIn  = ( 180 - 90 + diffToFasade )   //63,91
    var southFasadeOut = ( 180 + 90 + diffToFasade )   //243,91
    var westFasadeIn   = ( 270 - 90 + diffToFasade )   //153,91
    var westFasadeOut  = ( 270 + 90 + diffToFasade )   //333,9 
    var northFasadeIn  = ( 360 - 90 + diffToFasade )   //243,91
    var northFasadeOut = ( 360 + 90 + diffToFasade )   //386,09 or 63,91 -  because 360 and 0 is north
 
    postUpdate(Sun_Fasade_Illum_East,             if (azimut > (eastFasadeIn.remainder(360)) && azimut < (eastFasadeOut.remainder(360)) && height > 18) ON else OFF)
    postUpdate(Sun_Fasade_Illum_South,            if (azimut > (southFasadeIn.remainder(360)) && azimut < (southFasadeOut.remainder(360)) && height > 18) ON else OFF)
    postUpdate(Sun_Fasade_Illum_West,             if (azimut > (westFasadeIn.remainder(360)) && azimut < (westFasadeOut.remainder(360)) && height > 18) ON else OFF)
    postUpdate(Sun_Fasade_Illum_North,            if (azimut > (northFasadeIn.remainder(360)) && azimut < (northFasadeOut.remainder(360)) && height > 18) ON else OFF)

end

Auf die Änderungen der Sun_Fassade_Illum_* wird dann jeweils in einer Regel der/die Rolläden gefahren.


(SiHui) #51

Same here …

How did you solve it?


(Marco Schnubel) #52

I “inverted” my y-coordinate :wink:

100 - your “y” and then insert this into the shaddow.py


(Patrick) #53

Hi,

As others have said in order to manage your shutters you really just need to check the sun azimuth and elevation. I do this for my shutters and it works perfectly all year round!

Cheers,
Patrick


(SiHui) #54

Thx, that’s it! :grinning:


(John Sable) #55

I had some free time and started to play around with Habpanel. I installed the scripts and created the plot of my house shape two days ago and let it run to build up a persistence history (used the code to use OpenHAB persistence). This morning, I added the widget and am not getting it to work, I am getting just a blank space on the panel where the widget should be.

This is what I am seeing in my log:

2018-01-27 08:42:32.991 [INFO ] [lipse.smarthome.model.script.Shaddow] - Successfully got state from OpenHab: Sun_Azimuth

Successfully got state from OpenHab: Sun_Elevation

Successfully got state from OpenHab: Sunrise_Azimuth

Traceback (most recent call last):

  File "/etc/openhab2/scripts/shaddow.py", line 249, in <module>

    main()

  File "/etc/openhab2/scripts/shaddow.py", line 235, in main

    s = shaddow()

  File "/etc/openhab2/scripts/shaddow.py", line 44, in __init__

    self.sunrise_azimuth = float(self.oh.getState('Sunrise_Azimuth'))

ValueError: could not convert string to float: NULL

(Paul Hansen) #56

I had the same problem (among others). What is your item persistence like? Is the Sunrise_Azimuth rule being fired? The error is saying the item value is NULL, not a nice numerical value it can easily convert to a float.


(John Sable) #57

Looks like it is running successfully, and this error went away, but now I am getting errors like:

2018-01-29 07:20:19.912 [INFO ] [lipse.smarthome.model.script.Shaddow] - Successfully got state from OpenHab: Sun_Azimuth
Successfully got state from OpenHab: Sun_Elevation
Successfully got state from OpenHab: Sunrise_Azimuth
Successfully got state from OpenHab: Sunset_Azimuth
Successfully got data from Persistence
328.2649999999999863575794734060764312744140625
Traceback (most recent call last):
  File "/etc/openhab2/scripts/shaddow.py", line 250, in <module>
    main()
  File "/etc/openhab2/scripts/shaddow.py", line 244, in main
    s.generateSVG()
  File "/etc/openhab2/scripts/shaddow.py", line 218, in generateSVG
    svg = svg + self.generatePath(LIGHT_COLOR,'none',[self.degreesToPoint(DEGS[0],WIDTH/2+5), self.degreesToPoint(DEGS[0],WIDTH/2+11)])
  File "/etc/openhab2/scripts/shaddow.py", line 103, in degreesToPoint
    d2 = 180 - d
TypeError: unsupported operand type(s) for -: 'int' and 'unicode'

I am new to python so I am looking at the shadow.py in Atom. I didn’t change the shadow.py file except to add the code for the OpenHAB REST persistence call, which appears to be working. I am still showing my shaddow.svg as a 0 kb sized file.


(Frederic Mariën) #58

The error indicates that you are subtracting a int with text, which is off course impossible.
I also you previously had an issue with the conversion of string to float.
I guess the problem is originating from OpenHAB.

EDIT: The problem must occur while getting the persistence data from the influx database since the value of DEGS[0] is not numeric.Can you check the data that is in your database?

Greetings,
Frederic


(John Sable) #59

Thanks Frederic, I appreciate you taking the time to look at my issue. Right now, I am getting these values from OpenHAB:

Sunrise Azimuth = 114
Sunset Azimuth = 244.9900000000000090949470177292823791503906…
Sun Azimuth = 128.23 °
Sun Elevation = 11.49 °

I am pulling the data from the OpenHAB Persistence, not from Influx (I would prefer not to use influx, just don’t like it). I am guessing that the problem lies with the Sunset Azimuth, but I don’t know why that would be pulling so many decimal position…


(SiHui) #60

and


(John Sable) #61

Sihui,

I copied the code provided by Schmidmuc, and used his implementation for using OpenHAB persistence instead of Influx. I made the relevant changes to the code (only changing the names form SonnenaufgangAzimuth to Sunrise_Azimuth and SonnenuntergangAzimuth to Sunset_Azimuth)


(Frederic Mariën) #62

If the returned value from OpenHAB contains the degrees symbol in it then that will be the issue since parsing that to a float will definitely fail.
I would also double check the data you get while querying OpenHAB for the hostorical states.
Maybe add a print after every fetch so you get this:

        for h in xrange(0,24,HOURS):
            t = datetime.combine(date.today(), datetime.min.time()) + timedelta(hours=-utc_offset+h-24)
            tt = datetime.combine(date.today(), datetime.min.time()) + timedelta(hours=-utc_offset+h-23)
       	    a = self.oh.getStateHistoryFromPersistence('Azimuth',t.strftime('%Y-%m-%dT%H:%M:%S') + 'Z',tt.strftime('%Y-%m-%dT%H:%M:%S') + 'Z')
       	    if (a == None): a = 0
       	    DEGS.extend([a])
       	    print str(a)

When you see the result of the print it should become clear that there probably is a non-numerical character in the result.