Manage cover with sun position (elevation and azimuth)

Hello, I find you on blueprint great, however an improvement to be made, to have with the lux and the temperature inside the room of the shutters

Yes, this is the case for me too.

Hi,
Thanks for your work!
Iā€™m trying to get this running and have a question:
Can somebody tell me what the part in square brackets does?
cover_e[6:]

from

variables:
  var_e: "{{ 'var.' + cover_e[6:] }}"

Thank you!

The blueprint is very nice, but for me just a start. Although it looks like no new ā€˜featuresā€™ are being added I hope others can help.

Any ideas how to implement the above? Or is there another blueprint/automation which has all of this?

Hey, could anyone help me with this issue?

EDIT: got it

Nope, never had any chance I went down the NodeRed rabbit hole.

I use the codeā€¦just a few things I donā€™t understandā€¦

Do all conditions have to apply or just oneā€¦i.e. temperature or azimuth. When do the shutters go up again?

my variable shows eerverytime 0ā€¦see the picture

I have made a different version which in my opinion works better:

:sun_with_face: Automatic blinds / sunscreen control based on sun platform

It uses trigonometry to regulate the amount of natural light while keeping the blinds low enough to block the sun from hitting your eyes.

These are useful extensions for the blueprint, @erik7. Would be great, to see the logic for open doors in the blueprint.

At the moment I use a logic in addition to the shading to open or close my blinds in the morning and in the evening. The logic is based on the brightness and the time. Open the blinds when a certain lux value is reached or at the latest when it is e.g. 9:00 oā€™clock. The same in the evening. Close the blinds when a certain lux value is reached (it is dark) or when it is 21:00.
This is my basic logic, so to speak. The shading logic is then added, so that in the morning of a summer day, the blinds do not open fully, but move directly to the shading position.
Can something like this be added to the Blueprint?

1 Like

What exactly do I need the var for? Itā€™s always 0 for me in the course.

Is that correct?

maybe someone could explain itā€¦

Changed Al little bit the Blueprint with external TempSensorā€¦
In the line value_template: "{{ state_attr(cover_e, 'current_position') < open_position }}", the automation script is checking the current position of the shutter (retrieved by state_attr(cover_e, 'current_position')) against the predefined opening position (open_position). If the current position is less than the opening position, this implies that the shutter is not fully open and thus the action to open the shutter will be executed. Conversely, if the current position is equal to or more than the opening position, it means the shutter is already at the desired position, and the action to open the shutter will be skipped. This mechanism prevents the system from redundantly sending the signal to open the shutter when itā€™s already open.

blueprint:
  name: sun protection v3
  description: close cover when sun is shining and open when stops
  domain: automation
  source_url: https://gist.github.com/mougeat/bec9f93c723c8e7d1a9c64c2592fa471
  input:
    cover_entity:
      name: cover
      selector:
        entity:
          domain: cover
          
    sun_position_start:
      name: sun azimuth position start
      description: Sun azimuth. when sun is below this value, shutter could be triggered
      default: 89
      selector:
        number:
          min: 0
          max: 360
          unit_of_measurement: Ā°
          
    sun_position_end:
      name: sun azimuth position end
      description: Sun azimuth. when sun is over this value, shutter could be triggered
      default: 200
      selector:
        number:
          min: 0
          max: 360
          unit_of_measurement: Ā°
          
    sun_elevation_start:
      name: sun elevation to start
      description: Sun elevation. when sun is over this value, shutter could be triggered
      default: 32
      selector:
        number:
          min: -100
          max: 360
          unit_of_measurement: Ā°
          
    weather:
      name: Weather service
      selector:
        entity:
          domain: weather
          
    sensor:
      name: AuƟensensor
      selector:
        entity:
          domain: sensor
          
    outdoor_temp_1:
      name: Pos1 - Outdoor temperature (Low)
      description: Temperature above which the shutters will close
      default: 19
      selector:
        number:
          min: 0
          max: 30
          unit_of_measurement: Ā°C
          
    close_position_1:
      name: Pos1 - Intermediate Closing position for lower temperature
      description: Position at which the shutter should close
      default: 35
      selector:
        number:
          min: 0
          max: 100

    outdoor_temp_2:
      name: Pos2 - Outdoor temperature (High)
      description: Second temperature threshold above which the shutters will close
      default: 25
      selector:
        number:
          min: 0
          max: 30
          unit_of_measurement: Ā°C
          
    close_position_2:
      name: Pos2 - Maximum Closing Position for higher temperature
      description: Second position at which the shutter should close
      default: 18
      selector:
        number:
          min: 0
          max: 100
          
    open_position:
      name: Opening position
      description: Position at which the shutter should open
      default: 100
      selector:
        number:
          min: 0
          max: 100

variables:
    cover_e: !input cover_entity
    var_e: "{{ 'var.' + cover_e[6:] }}"
    protection_begin: !input sun_position_start
    protection_end: !input sun_position_end
    elevation_begin: !input sun_elevation_start
    outdoor_temp: !input outdoor_temp_1
    outdoor_temp_2: !input outdoor_temp_2
    close_position: !input close_position_1
    close_position_2: !input close_position_2
    open_position: !input open_position
    weather_service: !input weather
    sensor: !input sensor

mode: parallel

trigger:
  - platform: time_pattern
    minutes: "/5"
  
condition:
  - condition: sun
    before: sunset
    after: sunrise
    
action:
  - choose:
      ##########################################################.
      # close cover - second temperature threshold
      ##########################################################
      - conditions:
          - condition: template
            value_template: "{{- is_state('input_boolean.cover_manage_cover_with_sun', 'on') -}}"
          - condition: template
            value_template: "{{ states(var_e) != '1' }}"
          - condition: template
            value_template: "{{ state_attr('sun.sun', 'azimuth') > protection_begin and state_attr('sun.sun', 'azimuth') < protection_end and state_attr('sun.sun', 'elevation') > elevation_begin }}"
          - condition: or
            conditions:
              - condition: template
                value_template: "{{ states(weather_service) == 'partlycloudy' }}"
              - condition: template
                value_template: "{{ states(weather_service) == 'sunny' }}"
          - condition: template
            value_template: "{{ states(sensor) |float > outdoor_temp and states(sensor) |float <= outdoor_temp_2 }}"
        sequence:
          - data_template:
              entity_id: "{{ cover_e }}"
              position: "{{ close_position_2 }}"
            service: cover.set_cover_position

      ##########################################################
      # close cover - first temperature threshold
      ##########################################################
      - conditions:
          - condition: template
            value_template: "{{- is_state('input_boolean.cover_manage_cover_with_sun', 'on') -}}"
          - condition: template
            value_template: "{{ states(var_e) != '1' }}"
          - condition: template
            value_template: "{{ state_attr('sun.sun', 'azimuth') > protection_begin and state_attr('sun.sun', 'azimuth') < protection_end and state_attr('sun.sun', 'elevation') > elevation_begin }}"
          - condition: or
            conditions:
              - condition: template
                value_template: "{{ states(weather_service) == 'partlycloudy' }}"
              - condition: template
                value_template: "{{ states(weather_service) == 'sunny' }}"
          - condition: template
            value_template: "{{ states(sensor) |float > outdoor_temp_2 }}"
        sequence:
          - data_template:
              entity_id: "{{ cover_e }}"
              position: "{{ close_position }}"
            service: cover.set_cover_position

      ##########################################################
      # open cover
      ##########################################################
      - conditions:
          - condition: template
            value_template: "{{- is_state('input_boolean.cover_manage_cover_with_sun', 'on') -}}"
          - condition: sun
            before: sunset
            after: sunrise
          - condition: template
            value_template: "{{ (state_attr('sun.sun', 'azimuth') < protection_begin or state_attr('sun.sun', 'azimuth') > protection_end or  state_attr('sun.sun', 'elevation') < elevation_begin) }}"
          - condition: template
            #value_template: "{{ is_state(cover_e, 'open') == false }}"
            value_template: "{{ state_attr(cover_e, 'current_position') < open_position }}"
        sequence:
          - data_template:
              entity_id: "{{ cover_e }}"
              position: "{{ open_position }}"
            service: cover.set_cover_position

@Ivydree Have you got passed this? I am at the same place here.

Is there any integration that you use, which provides the Azimuth start position, and so on? trying to make this even more automated during the summer.

Suggestions for improvement would be to support multiple covers at the same time. If anyone has any suggestions on how to accommodate that change, please share your findings.

Finally, kudos to the @mougeat, after setting everything up, it is working as expected.

When i try to add var in config it says

Invalid config for [var]: [cover_cover.sunilus_io] is an invalid option for [var]. Check: var->var->cover_cover.sunilus_io. (See /config/configuration.yaml, line 56).

Would this Blueprint be dependent on the northern hemisphere?

I had set this up yesterday, however at sunset nothing happened and again this morning nothing happened with my cover.

I have checked, current_position is available.

Only thing I can think of is the Sun position is reversed for me here in the Southern Hemisphere:
Sunrise is at 87Ā° @ 06:24 then it drops down all the way to 0Ā° at mid-day, then it jumps to 360Ā° and continues to go down from there until sunset at 270Ā° @ 18:24

Now in the Northern Hemisphere, you guys donā€™t go past 0/360Ā° and thus the Blueprint probably needs some tweaking for Southern Hemisphereā€¦

works great. and just the thing iwaslooking for- one thing i miss.
The possibility to choose an exception. Could be a door or window sensor, so that the cover will stay open if door/window is openā€¦

When I manually open or close a blind the state of the cover_e is updated live.
So, being no real programmer, Iā€™m a bit puzzled by the use and function of the var_e variable in combination with the cover_e. Could you shed some light on this?

Hello,
I used to have this blueprint working like a charm, but recently not working anymore. When troubleshooting the automation, realize that I am getting an error at:

conditions/5

Error : In ā€˜templateā€™ condition: UndefinedError: ā€˜stateā€™ is undefined which correspond to the following line:

  • condition: template
    value_template: >-
    {{ state_attr(ā€˜sun.sunā€™, ā€˜azimuthā€™) > protection_begin and
    state_attr(ā€˜sun.sunā€™, ā€˜azimuthā€™) < protection_end and
    state_attr(ā€˜sun.sunā€™, ā€˜elevationā€™) > elevation_begin }}

When running the template with numeric values, I am gettig same issue:
value_template: >-
{{ state_attr(ā€˜sun.sunā€™, ā€˜azimuthā€™) > 71 and state_attr(ā€˜sun.sunā€™,
ā€˜azimuthā€™) < 285 and state_attr(ā€˜sun.sunā€™, ā€˜elevationā€™) > 15 }}
But when using the same in developpment tool-> Model, the result is true (no errors).
Any clue where could be the issue ?
Thanks,

Hello, I have problems with the weather service: which weather service provides the attributes required by the blueprint?

@mikemc I assume any weather service that can return the following states:

ā€˜sunnyā€™
ā€˜cloudyā€™
ā€˜partlycloudyā€™
etc:

What does your give? check state in developer tools?