A question of both Maths and Code to measure sun

Hi all,

Around the start of June I wrote this;

alias: Close Kitchen Patio Blinds with PM sun and 25 degrees
  initial_state: True
  trigger:
    platform: numeric_state
    entity_id: sun.sun
    value_template: '{{ state.attributes.elevation }}'
    below: 58 
  condition:
    condition: and
    conditions:
      - condition: time
        after: '14:00:00'
        before: '18:00:00'
      - condition: numeric_state
        entity_id: sensor.yr_temperature
        above: 24.0
  action:
    - service: cover.set_cover_position
      data_template:
        entity_id:
          - cover.kitchen_patio_blind_level
        position: 30

which was in response to the sun shining through the kitchen window.

It works exactly as I wanted it to, and the elevation of 58 was based on trial and error over a couple of days.

The problem/challenge is that nature is not simple, and the reality now in August is that I need to determine when the blind comes down based on azimuth as well as elevation.

Does anyone have even the most basc idea of how to do this???

I thought I could avoid this by giving the automation a different trigger elevation dependant on the week, or fornnight, but I am not sure how that code would look, eg: “if it is week 26, then lower blind when elevation <58, if it is week 27, then lower blind when elevation <56 etc…”, otherwise, is there some way to build a look-up table combining elevation and azimuth that wuld allow the automation to trigger when a combination of those two values are met.

I hope you can see my problem and my ambition to solve it, sorry it’s complicated!

Thanks in advance
John.

You can add a factor for the azimuth like this

{{ state.attributes.elevation + ((state.attributes.azimuth - MY_WINDOW_DIRECTION) / UNKNOWN FACTOR}}'

The direction your window faces will make the factor zero when the azimuth is the same as your window direction.
It will be negative on one side of that location, and positive on the other.
There may be some scientific method to determine what the unknown factor is, but it will take someone smarter than me to figure it out. This might be another case for trial and error.

Thanks for replying.

My window faces 285, so I’m going to use your approach and see what I get.

I have two data points of when (time wise) the blind needs to come down, 1st June, as I remember from when I firstset this up, and today, from looking out of the window. I also have (through the power of the internet) the elevation/azimuth data for all of this year at this location, so I should be able to make a start on the division factor from those two days alone.

As always, I’ll report back!

John.

Hi @SethKins , were you able to solve your problem? I would like to do the same thing myself with my shutters

Short answer is yes, although I will have to monitor it for a few weeks to make sure the logic keeps up with the changing path of the sun throughout the year. Here is the automation, bear in mind the number “285” is the direction my window faces.

- id: OldO
  alias: Close Kitchen Blind with PM sun and 25 degrees
  initial_state: True
  trigger:
    platform: numeric_state
    entity_id: sun.sun
    value_template: '{{ state.attributes.elevation + ((state.attributes.azimuth - 285)/ 0.7)}}'
    above: 0
  condition:
    condition: and
    conditions:
      - condition: time
        after: '14:00:00'
        before: '18:00:00'
      - condition: numeric_state
        entity_id: sensor.yr_temperature
        above: 24.0
      - condition: numeric_state
        entity_id: sensor.yr_cloudiness
        below: 35        
  action:
    - service: cover.set_cover_position
      data_template:
        entity_id:
          - cover.kitchen_patio_blind_level
        position: 30

Thanks for replying.

In your case the azimuth of 285 is when the sun starts to hit the window?
How did you find the unknown factor value?

No, 285 is the direction the window faces, so the sun creeps round at 285 - 90.

The factor is pure observation, I looked at the moment t by email sun came through and then grabbed the azimuth and elevation from HA and derived the factor for that moment

Sorry but i don’t understand

for example in my case i observed that with an elavation of 48 and an azimuth of about 244 i would need to set my shutter position to 15. So my vaule should be 244?

Bearing in mind I’m not promising this works (I’m still testing) then for your equation to match mine you need to have;

{{ state.attributes.elevation + ((state.attributes.azimuth - 285)/ 0.7)}}

285, in your version, will be the direction your window faces.

Wait until unwanted sun starts to come into your window, and at that moment get the current elevation and azimuth values from HA. Put these two into the equation and then work out what your “factor” (mine being 0.7) needs to be to make the equation sum to zero.

Does that make more sense?

i can’t understand what you mean when you say “the direction your window faces”

how did you find that 285?

Ok, I understand.

The direction my window faces is 285 degrees, just a little north of West.

I found this using a compass app on my phone.

Hi @SethKins,

I’m testing this formula, but it doesn’t work for me…

What about you?

Doesn’t work in the sense the blinds don’t come down at all or that they come down at the wrong time?

They come down at the correct time the first day, then always later.