I’ve created a small python script that generates and SVG image to illustrate where the sun is currently positioned and which side of the house is facing the sun.
I wire the script up with a rule when the sun’s azimuth changes and then I include the SVG in my HABPanel like this:
It’s not very useful, but it looks cool on my HABPanel
Note, the script relies on InfluxDb as the persistence layer to retrieve the last days azimuth values per hour, etc.
It also requires the Astro binding and the following items:
Number Sun_Azimuth "Sun Azimuth" { channel="astro:sun:local:position#azimuth" }
Number Sun_Elevation "Sun Elevation" { channel="astro:sun:local:position#elevation" }
Number Sunrise_Azimuth
Number Sunset_Azimuth
This is the rule to capture the sun’s azimuth during sunset and sunrise and refreshes the SVG with every azimuth change:
rule "Shaddow SVG"
when
Item Sun_Azimuth received update
then
val resp = executeCommandLine("/usr/bin/python /etc/openhab2/scripts/shaddow.py update", 10000)
logInfo("Shaddow", "Updating Shaddow SVG")
logInfo("Shaddow", resp)
end
rule "Sunset Rule"
when
Channel 'astro:sun:local:set#event' triggered START
then
postUpdate(Sunset_Azimuth,Sun_Azimuth.state)
logInfo("Shaddow","Setting Sunset Azimuth.")
end
rule "Sunrise Rule"
when
Channel 'astro:sun:local:rise#event' triggered START
then
postUpdate(Sunrise_Azimuth,Sun_Azimuth.state)
logInfo("Shaddow","Setting Sunrise Azimuth.")
end
Once set up, you need to specify the shape of your house in 100 x 100 unit square at the top of the python file, for my house it’s:
# Shape of the house in a 100 by 100 units square
SHAPE = [{'x': 60.04, 'y': 12.52}, \
{'x': 89.15, 'y': 37.66}, \
{'x': 84.24, 'y': 43.36}, \
{'x': 87.19, 'y': 45.91}, \
{'x': 66.21, 'y': 70.02}, \
{'x': 63.15, 'y': 67.56}, \
{'x': 45.94, 'y': 87.48}, \
{'x': 32.70, 'y': 76.04}, \
{'x': 31.09, 'y': 77.90}, \
{'x': 10.85, 'y': 60.42}, \
{'x': 45.44, 'y': 20.36}, \
{'x': 49.93, 'y': 24.23}]
You can change the colors and filename in the pything script.
Scripts:
To add to HABPanel:
Add a template widget with this content:
<object data="/static/matrix-theme/shaddow.svg?{{itemValue('Sun_Azimuth')}}" type="image/svg+xml"></object>
The ?{{itemValue(‘Sun_Azimuth’)}} ensures that the SVG gets refreshed automatically as the azimuth changes.