#I'm just a bit inexperienced here, so I'

1 messages · Page 1 of 1 (latest)

deep narwhal
#

This is how I would do it:

{#Setup your look up table based on the day of the year of the start date#}
{% set y_day_azi = {
168:
  {"north": [55,106],        
  "east": [51,128],
  "south": [51,207], 
  "west": [202,308]},
182:
  {"north": ["?","?"],        
  "east": ["?","?"],
  "south": ["?","?"], 
  "west": ["?","?"]},
350: 
  {"north": none,        
  "east": none,
  "south": [126,207], 
  "west": [202,232]}
} %}

{# Set up a macro so you can pull the data you need from the table #}
{% macro directional_azi(direction, current_azimuth) %}
{% set yd = now().timetuple().tm_yday %}
{% set keys = y_day_azi.keys() | list %}
{% set start_ind = ((keys + [yd])|sort).index(yd) - 1 %}
{% set dir_dict = y_day_azi.get(keys[start_ind]) %}
{% set dir_list = dir_dict.get(direction) %}
{{ false if dir_list is none else current_azimuth|int 
in range(dir_list[0], dir_list[1]) }}
{% endmacro %}
reef light
#

Didgeridrew,
thank you very much for your support,
forgive me for the late reply, in Germany it is just morning...
I have a question, do I understand the table correctly, it defines the 365 days of the year, so I could take the trouble to determine this for each individual day?
Or am I completely wrong and not interpreting this correctly.

reef light
#

I followed up your instruction, unfortunately I'm not able to read the values, may I did something wrong.

#

I added to custom_template folder

#

this file ```directional_azi.jinja````

#

with the following content

#
{% set y_day_azi = {
1:
  {"north": none,
  "east": none,
  "south": [126,207],
  "west": [202,232]},
13:
  {"north": none,
  "east": none,
  "south": [123,207],
  "west": [202,236]},
312:
  {"north": none,
  "east": [120,128,
  "south": [124,207],
  "west": [202,239]},
325:
  {"north": none,
  "east": [124,128],
  "south": [124,207],
  "west": [202,234]},
338:
  {"north": none,
  "east": none,
  "south": [127,207],
  "west": [202,232]},
351:
  {"north": none,
  "east": none,
  "south": [126,207],
  "west": [202,232]},
} %}
{% macro directional_azi(direction, current_azimuth) %}
{% set yd = now().timetuple().tm_yday %}
{% set keys = y_day_azi.keys() | list %}
{% set start_ind = ((keys + [yd])|sort).index(yd) - 1 %}
{% set dir_dict = y_day_azi.get(keys[start_ind]) %}
{% set dir_list = dir_dict.get(direction) %}
{{ false if dir_list is none else current_azimuth|int 
in range(dir_list[0], dir_list[1]) }}
{% endmacro %}
#

after HA reboot I try to import on template editor as follow...

#
{% from 'directional_azi.jinja' import directional_azi %}
{{ directional_azi('direction, current_azimuth') }}```
#

and get this error
TemplateSyntaxError: expected token ',', got ':'

#

Maybe you could support me again.
Yes, I admit that as a carpenter I find it difficult to understand these programming things, but I am still interested in improving.

#

FYI
, in the macro above I created the values ​​for every 13th day, unfortunately discord does not allow so many characters

deep narwhal
#

The template then gets the current day of the year and adds it to a list with the all the days of the year keys, sorts them and gets the value of the "previous" day of the year it finds.

You will need to supply the values for direction and current_azimuth, based on your previous posts that would be something like:

{% from 'directional_azi.jinja' import directional_azi %}
{{ directional_azi('north', states('sensor.sonne_solar_azimuth')) }}
reef light
#

alredy this line
{% from 'directional_azi.jinja' import directional_azi %}```` get the expected token ',', get ':'```error

deep narwhal
#

You are probably just missing a comma between entries in the look up table. If you copy the content of the directional_azi.jinja file to a code share like https://dpaste.org/ I'll give it a look.

reef light
#

Ok got it, I'm on the way now, will do later.... but first will have a look my self, may I found it... 😉