Sensor to identify sun's entry into window - blind trigger

Tags: #<Tag:0x00007fc3fb00b290>

I have been trying to work out a formula that would give me data on when to close my blinds to stop the sun entering my living room… and I think I might have it.

After a refresher on high school trig and taking measurements of height, overhang and alignment with true north, Excel gave me a formula that looks right. I have modelled it in Fusion 360 and compared it to the handful of actual observations I have - and it looks pretty close. For example at azimuth 340-degrees, the sun needs to be lower than 58.8-degree elevation to enter. Today at azimuth 340 it was over 68-degrees elevation.

I then converted that to something for the configuration.yaml.

I have set up a new sensor that looks at the current azimuth and elevation and compares that with the elevation for the current azimuth that would allow the sun to enter my living room. It will countdown to zero - and then go negative. When the actual elevation is equal too the “entry” elevation for that azimuth, the sensor.suntriggerliving will have a numeric state of zero, so can be used to trigger the blinds to close.

This is the code I have placed in my configuration.yaml

  - sensor:
        name: SunTriggerLiving
        state_class: measurement
        icon: mdi:blind
        state: >
            {{(state_attr('sun.sun','elevation')) - (atan(2250/(650/(sin((pi/180)*(360 + 8.5 - (state_attr('sun.sun','azimuth')))))))*(180/pi))}}

(there might be too many brackets there - I will have to check)

KEY - just replace with your measurements

  • 2250 = distance vertically from bottom of the window to overhang
  • 650 = width (horizontal) of overhang from sun entry point
  • 8.5 = angle of window/wall from true north (in my case 8.5-degrees to the east of TN - would be negative if to the west)

I’m guessing in the northern hemisphere, the 360 would become 180???
I now have to work out the sensor to tell me when the sun has gone off my eastern facing window so I can have the blind open.

1 Like

That’s clever! A great example of what you can do with HA.

Admittedly, I haven’t fully followed the math. A 'For Dummies" write-up would be interesting. I love it when astronomical calculations are used in practical solutions like this. Sort of like navigating; it requires a basic understanding of where you are on this planet. Something too many people are completely unaware of.

I hope my logic pans out - and maybe a person more skilled in maths can point out any error. You can also test the formula if you go to “Developer Tools” and “Template” in your HA instance.

It took me a while to realise, but after doing some modelling in Fusion, someone suggested trig would help. The Fusion drawings helped get it clear in my mind that I was dealing with two interconnected right-angled triangles - one horizontal and one vertical - sharing a common side.

The 1st drawing shows the azimuth (350°) - 10° off the true north line and the house is 8.5° to the east of true north. The first triangle (marked yellow) was created by the azimuth on the left and the window on the right. The base was formed by the width of the overhang - 650mm coming off the window until it intersects with the azimuth.

  • So now we know the length of one side (650mm) and an angle besides the 90 - 18.5° (10+8.5).

  • From there trig comes in and sin gives you the length of the hypotenuse - 2048.504mm. (650/sin(pi/180)*18.5).

Now we run a vertical line from where the base (650mm line) intersects with the azimuth line and take that up to the overhang which gives us the shadow/sunlight angle for that azimuth.

The hypotenuse (green highlight) of the horizontal triangle now becomes the base of vertical 90° triangle.

  • We know the length of two sides - the base (2048.504mm from above) and the vertical side (2250mm window to overhang).

  • Now using those two numbers, inverse tan (atan(2250/2048.504)*(180/pi)) gives us the angle from the bottom of the window to the point on the overhang at which sun would enter, for that azimuth. In this case (azimuth 350°) if the elevation is above 47.68°, the sun will not enter the window.

As the sun moves to the west and the azimuth decreases, the angle between the azimuth and house increases and the minimum elevation at which the sun will enter increases and vice versa. So in summer when the sun’s elevation is high, the sun’s azimuth will need to be closer to the west (ie a lower number) for the sun to enter. In winter, when the sun’s elevation is low, the sun will enter with a higher azimuth number.

I then look at the current elevation for the current azimuth and compare it to my calculation.

  • (state_attr(‘sun.sun’,‘elevation’) - calculation from above.

  • If the current elevation is above my calculated entry elevation (ie no sun enters), the sensor will have a positive number. If the current elevation is lower than my calculated elevation, (ie sun can enter) the sensor will be negative.

This will need azimuth tweaks for the northern hemisphere or if you want to work when the sun will be off a window on the eastern side.

The calculation for sun coming off my east side window is:

> {{(state_attr('sun.sun','elevation')) - (atan(2250/(1150/(sin((pi/180)*((state_attr('sun.sun','azimuth')-8.5))))))*(180/pi))}}

The overhang here is 1150mm and the trigger is when the number goes above zero.

1 Like