Sun elevation and cover/blinds angle

Sorry, itā€™s probably just a language thing, but Iā€™m not sure what you mean by this. Can you try explaining with a little more detail?

Iā€™m sorry, Iā€™m not a native speaker and Iā€™m using G Translator ā€¦ :smiley:
The point is that the state of the sun changes every minute. If I use this automation, the blinds will tilt every second with the sun.
Ideal would be if they dove at a major event. Perhaps five degrees each time.

Ok, we can do that by adding another condition to the automation. Oh, and I just noticed there was a typo in what I suggested before. So here is the new trigger and condition parts:

  trigger:
    platform: state
    entity_id: sun.sun
  condition:
  - above: 25
    below: 30
    condition: numeric_state
    entity_id: sensor.teplota_obyvak
  - above: 0
    below: 4
    condition: numeric_state
    entity_id: sensor.yr_symbol
  - condition: template
    value_template: >
      {% if trigger.from_state is not none %}
        {% set old_el = trigger.from_state.attributes.elevation %}
      {% else %}
        {% set old_el = 0 %}
      {% endif %}
      {% set el = state_attr('sun.sun', 'elevation')|float(0) %}
      {% set az = state_attr('sun.sun', 'azimuth')|float(360) %}
      {{ el > 5 and az < 235 and (el//5 - old_el//5)|abs > 0 }}

Let me know if you have any questions.

1 Like

Thatā€™s amazing! Thank you very much! It went without a fault. See you on Saturday, under real sun conditions.

Can you please explain what it really means? I would like to learn and possibly adjust it. Once Iā€™ve verified everything, Iā€™ll send the entire code so they can inspire others. :slight_smile:

Sure.

First, in the condition and action parts of an automation there is a variable automatically created named trigger. For a state trigger it has both trigger.from_state and trigger.to_state, which represent what the state it was before it changed and the new state after it changed. Itā€™s possible either might be None, so I have to check for that. So basically, when sun.sun changes, and triggers the automation, Iā€™m getting what the elevation was before the change and what it now is. Then I use the // operator, which is an integer divide, on the before and after elevation values. The result if the //5 will change whenever a multiple of 5 is crossed. Then I subtract them, and the (absolute value) of the difference is zero if the before and after values are in the same multiple of 5, or something other than zero if they are in different multiples of 5.

I hope you can follow that explanation, especially with the language difference. It is harder to put into words than writing it in the first place. :slight_smile:

I tried to edit some parameters and works almost perfectly! :slight_smile:
As the sun shifts to 5 degrees in elevation, the blinds are pulled and the tilt starts.
I have only one complication with that inclination. When the sun was at an angle of 15 degrees, the tilt turned to 55 (40 + 15), but when the sun was at an angle of 20 degrees, the tilt should change to 60 (40 + 20), but it changed to 58. :open_mouth:

Thank you for your help.

1 Like

You may consider a hysteresis. Operating the blinds on every 5 degree change of sun elevation is probably not good for the durability of the motorized blinds, at least in summer.

Just my 2 cents.

I have limited azimuth and elevation. so in winter it only works until it stops on a particular side of the light and in the summer the windows cover me the overhang of the roof, so it does not fall out of time at all. In addition, the maximum is 90 degrees and it covers more than 5 degrees.

In addition, now in the winter is the movement of five degrees about an hour and only when there are no clouds. Then it would make eight moves all day. In the summer, it will be only five tilts than it covers the overhang of the roof, and as soon as the sun goes down it will no longer shine on the side with the blinds.

Can you look please?

Iā€™m sorry. Look at what?

Can you post your automation as it exists now?

Yes, here is it. :slight_smile:

- id: '1546263622138'
  alias: Žaluzie (zatĆ”hnout JV) - teplota/slunce/azimut
  trigger:
    platform: state
    entity_id: sun.sun
  condition:
  - above: 25
    below: 30
    condition: numeric_state
    entity_id: sensor.teplota_obyvak
  - above: 0
    below: 4
    condition: numeric_state
    entity_id: sensor.yr_symbol
  - condition: template
    value_template: "{% if trigger.from_state is not none %}\n  {% set old_el = trigger.from_state.attributes.elevation\
      \ %}\n{% else %}\n  {% set old_el = 0 %}\n{% endif %} {% set el = state_attr('sun.sun',\
      \ 'elevation')|float(0) %} {% set az = state_attr('sun.sun', 'azimuth')|float(360)\
      \ %} {{ el > 5 and az < 235 and (el//5 - old_el//5)|abs > 0 }}\n"
  action:
  - data:
      entity_id: cover.francouzke_okno_2
    service: cover.close_cover
  - data_template:
      entity_id: cover.francouzke_okno_2
      tilt_position: '{{ (states.sun.sun.attributes.elevation + 40)|int }}'
    service: cover.set_cover_tilt_position
  - data:
      message: Nastavuji JV okna na zĆ”kladě teploty, slunce a azimutu
    service: notify.domaci_asistent
  - data:
      entity_id: cover.navstevnicky_pokoj_2
    service: cover.close_cover
  - data_template:
      entity_id: cover.navstevnicky_pokoj_2
      tilt_position: '{{ (states.sun.sun.attributes.elevation + 40)|int }}'
    service: cover.set_cover_tilt_position
  - data:
      entity_id: cover.mateo_2
    service: cover.close_cover
  - data_template:
      entity_id: cover.mateo_2
      tilt_position: '{{ (states.sun.sun.attributes.elevation + 40)|int }}'
    service: cover.set_cover_tilt_position

The condition only lets the actions run when the elevation changes from one multiple of 5 to another multiple of 5. For example, if, on its way up, it was 18 (i.e., >= 15 and < 20) then changed to 22 (i.e., >= 20 and < 25), or if, on its way down, it was 22 then changed to 18. So, if it changed from >= 20 to, say 18, then it would set the tilt angle to 18 + 40, or 58. Could it be something like this that happened?

You say the elevation was 20 when the tilt angle was changed to 58. Exactly how do you know that? To be absolutely sure, youā€™d have to look in the logs to verify the exact sequence of events.

Do you want the tilt angle only to be multiples of 5 as well? The automation I suggested only changes the tilt angle when the sunā€™s elevation crosses a multiple of 5, but then sets the tilt angle to whatever the sunā€™s elevation is, plus 40. That would not guarantee the tilt angle is always a multiple of 5.

Oh, I understand that. Anyway, I watched it on the suncalk. When the sun was at 15 degrees, the tilt turned to 55 when it was 20 degrees, the slope was 58. Unfortunately I can not find a log. :frowning:

Anyway, now I have come to another crucial thing. Each time the sun rises, the blinds are always closed and then the correct angle is set. Is it sort of a solution?
For example, close the blinds if the current_position is greater than 0 (0 = fully down, 100 = full up).

Sorry, what is the suncalk? (Translation problem??? :slight_smile: )

Some information may be in the Logbook, but mostly you need to look in the file home-assistant.log. It is in the same directory as configuration.yaml. Depending on what you have for the logger: configuration, there may be a LOT of detail. Look for state_changed events for sun.sun and your cover entities.

When the automation is triggered, do all three covers change at the same time? Or is there some time between when the first one starts changing and the second one starts changing, etc.?

I donā€™t use cover entities, so Iā€™m not sure. In general trying to change something to a state that is already in is not a problem and results in no extra ā€œwork.ā€ For example, typically turning a light off that is already off causes no side effects. It would be possible to only close each cover if it was not already closed. Let me know if you would really want, and need, to do that.

Suncalc https://www.suncalc.org/ :slight_smile: Show where sun elevation and azimuth.

The difference is only a few seconds.

I need something in the sense:
If current_position> 0, set_cover_position = 0 else do nothing and call tilt.

Tilt template is great and no need change.

  - data:
      entity_id: cover.mateo_2
    service: cover.set_cover_position
    position: '0'
  - data_template:
      entity_id: cover.mateo_2
      tilt_position: '{{ (states.sun.sun.attributes.elevation + 40)|int }}'
    service: cover.set_cover_tilt_position

Ah. Well, that doesnā€™t necessarily agree with what HAā€™s sun.sun entity thinks. And since sun.sun is what is driving this automation, you should be looking at that.

These are computes weā€™re talking about. Seconds is a long time! :wink: You may need to change state_attr('sun.sun', 'elevation') to trigger.to_state.attributes.elevation (and same thing for azimuth) to make sure the condition template, and each step of the automation action, use the same value (since it is possible, although maybe unlikely, for sun.sun to change between the time the automation is triggered and the last steps of the action complete.) But, for now, I wouldnā€™t worry about it.

Ok. Iā€™m running out of time now, but Iā€™ll get back to you with a suggestion hopefully later today. If not, then probably Monday.

Maybe i do it! :slight_smile: It works but I just had to add unnecessary cover.stop_cover because without elseif it did not work and I could not leave it blank.

  action:
  - entity_id: cover.francouzke_okno_2
    service_template: '{% if is_state("cover.francouzke_okno_2", "open") %}cover.close_cover{% else %}cover.stop_cover{% endif %}'
  - data_template:
      entity_id: cover.francouzke_okno_2
      tilt_position: '{{ (states.sun.sun.attributes.elevation + 40)|int }}'
    service: cover.set_cover_tilt_position
1 Like

Dear all,

Iā€™m new in Home Assistant and I have a lot of problems to understand the programing languaje used for automationsā€¦ Iā€™m engineer and i know C languaje, assember, etc, but with home assistant languaje I have a lot of problems.

I have an eedomus controller, and my roller shutter fibaro to control my awning use with a script in php that I make. I want to down the awning according with the sun elevation, and additionally I want to put the awning in Manual, Semi Automatic, and Automatic operation. Then there are a lot of conditions, but in php is very easy with a switch/case instruction. The scipt is:

<?php
function sdk_MueveToldo ($equipo, $data )
{
	setValue($equipo, $data);
};

$Toldo = 1090079;
$ModoToldo = 1092530;
$AlarmaToldoCompleta = getValue("1092379");
$ToldoModo = getValue($ModoToldo);
$azimut = getValue('915991');
$inclinacion = getValue('915992');
$azimut_p1 = getValue('1092378');
$azimut_p2 = getValue('1092540');
$inclinacion_p1 = getValue('1092547');
$inclinacion_p2 = getValue('1092549');
$PosicionToldo = getValue($Toldo);

//Todas las instrucciones con echo son para tareas de depruaciƃĀ³n
// echo "AlarmaToldoCompleta=";
// echo $AlarmaToldoCompleta['value'];
// echo "  PosicionToldo=";
// echo $PosicionToldo['value'];
// echo "  ToldoModo=";
// echo $ToldoModo['change'];

// Las instrucciones a continuaciƃĀ³n miran el tiempo pasado entre el ƃĀŗltimo cambio del modo de funcionamiento del toldo
// Solo se evalua en el caso del case 0 que es cuando se ha activado el modo manual.
// Si el modo manual se activa mientras se vuelve a modo automƃĀ”tico pasadas 2 horas.

$Today = date('Y-m-d H:i:s');
$Dif_seconds = strtotime($Today)-strtotime($ToldoModo['change']);
$Dif_minuts = $Dif_seconds/60;
$Dif_hours = $Dif_minuts/60;


if ($AlarmaToldoCompleta['value'] == 0) {
	switch ($ToldoModo['value'])
	{ 
		case 0:    //Modo Manual
			if ($PosicionToldo['value'] != 100)
			{
				if ($Dif_hours > 2) setValue($ModoToldo, '2');
				else break;
			}
			else break;
		case 1:    //Modo Semiautomatico. Se cierra el toldo al 100% a partir de un azimut y elevaciƃĀ³n del sol. Y luego se abre al 100% cuando no se cumplen esas condiciones
			if (($azimut['value'] > $azimut_p1['value']) && ($azimut['value'] < $azimut_p2['value']) && ($inclinacion['value'] < $inclinacion_p1['value'] ) && ($inclinacion['value'] > $inclinacion_p2['value'])) sdk_MueveToldo($Toldo,0);
			else sdk_MueveToldo($Toldo,100);
		case 2:   //Modo totalmente automƃĀ”tico. Se va abriendo dependiendo de la evoluciƃĀ³n del azimut y elevaciƃĀ³n del toldo.
			

			if (($azimut['value'] > $azimut_p1['value']) && ($azimut['value'] < $azimut_p2['value']) && ($inclinacion['value'] < $inclinacion_p1['value'] ) && ($inclinacion['value'] > $inclinacion_p2['value']))
			{
				if (($inclinacion['value'] <= $inclinacion_p1['value']) && ($inclinacion['value'] > ($inclinacion_p1['value'] - 12.4))) sdk_MueveToldo($Toldo,70);
				if (($inclinacion['value'] < ($inclinacion_p1['value'] - 12.4+0.1)) && ($inclinacion['value'] > ($inclinacion_p1['value'] - 24.8))) sdk_MueveToldo($Toldo,60);
				if (($inclinacion['value'] < ($inclinacion_p1['value'] - 24.8+0.1)) && ($inclinacion['value'] > ($inclinacion_p1['value'] - 37.2))) sdk_MueveToldo($Toldo,20);
				if (($inclinacion['value'] < ($inclinacion_p1['value'] - 37.2+0.1)) && ($inclinacion['value'] > ($inclinacion_p1['value'] - 49.6))) sdk_MueveToldo($Toldo,0);
				if (($inclinacion['value'] < ($inclinacion_p1['value'] - 49.6+0.1)) && ($inclinacion['value'] > ($inclinacion_p1['value'] - 62))) sdk_MueveToldo($Toldo,0);
			}
			else
			{
				// echo "14";
				sdk_MueveToldo($Toldo,100);
			}
	}
}
else
{
	if ($PosicionToldo['value'] != 100) sdk_MueveToldo($Toldo,100);
}

?>

How I can develop in Home assistant something similar?