Manage cover with sun position (elevation and azimuth)

@sirfalo @convicte

My fork of the work from @mougeat using shutter position instead of time.

BW

2 Likes

Hi Convicte,
Can you please share the code for node red ? FDor me this is also much more intuitive.
thanks in advance

Peter

I’m further trying to fine-tune optimize the blueprint. I’m still in a testing phase, but the following enjoys priority:

  • baseline is for sure still Mougeat’s code
  • implemented a second threshold
  • solved at least on my side the issue, that covers were not opening again

blueprint:
  name: sun protection v2
  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
          
    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

mode: parallel

trigger:
  - platform: time_pattern
    minutes: "/1"
  
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: "{{ (state_attr(weather_service, 'temperature') > outdoor_temp and state_attr(weather_service, 'temperature') <= 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: "{{ state_attr(weather_service, 'temperature') > 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) }}"
        sequence:
          - data_template:
              entity_id: "{{ cover_e }}"
              position: "{{ open_position }}"
            service: cover.set_cover_position
3 Likes

could you also add an optional setting for using outdoor light sensor and enabling setting only above a certain lux threshold? that way if it is too cloudy outside I wouldn’t be sitting in the dark

1 Like

Hi there!
Were you able to get past this?
I’m seeing the same issue!

Hello there (I know I am a day late for that one),

I had the solution from @Kosy running from here (Shutter automation with sun azimuth trigger and contact sensor - #3 by Kosy)
The great thing was that the shutters would not only close and open completely but would adjust the position accroding to the suns position. This way the rooms would not be completely dark (or only during noon).
And I somewhat loved it. Problem there was:
1.) No matter the weather the shutters would always move even during rain, this is also true for the temperature, even though it was winter with minus something degrees.
2.) There was no real way to interact with the automation, i could of course adjust the shutters manually, but i could not easily disable the automation for a given period of time.

As far as i understood the thread here, this solution takes into account the weather (temperature as well?) but shuts the shutters only completely? Is that right? How much work would it be to adjust it to have them opened adjusted to the suns position?
Thank you!

I had similar problem. In my case the name of the cover enitities were too long and consequently variables were not set correctly.

@mougeat configuration.yaml example here:

Manage cover with sun position (elevation and azimuth) - #31 by mougeat

If you trace the automation, on the open cover section make sure you have the entire variable name, if it’s cut, go on the device and just update it for something shorter. Also make sure it is stated on the configuration.yaml correctly.

Example of my configuration.yaml:

var:
  bedroom_curtain:
    friendly_name: "VAR COVER QUARTO"
    initial_value: 0
    icon: mdi:bed-empty
  blinders_lr_front:
    friendly_name: "VAR COVER SALA FRENTE"
    initial_value: 0
    icon: mdi:living-room

Hi guys,

I just don’t know where my error is.
For example I have a rollo that is called cover.rollo_badezimmer, so my variable looks like this:

cover_rollo_badezimmer:
friendly_name: “rollo Badezimmer”
initial_value: 0
icon: mdi:bathroom

this will end up with an entity called “var.cover_rollo_badezimmer”, that’s correct so far isn’t it?
and if I want an input_boolean for each room instead of the input_boolean.cover_manage_cover_with_sun, it should be enough if I change this accordingly in the input as well as under conditions or?

currently I have the problem that e.g. rollo_osten reacts accordingly, but same script and because rollo_badezimmer all the time remains down.

try rollo_badezimmer: instead cover_rollo_badezimmer:

Did anyone already think about using the forecast temperature as additional as the input parameter?

If I imagine a day with >30°C I would assume that closing the blinds once the temperature is above a threshold is already too late to keep the temperature low (i.e. closing them earlier be needed).

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…