How can I change the data of an automation each month?

Hi
I have the following automation and I would like to change the number 145 each month according to the below data. So October = 145 and November = 168 and so on. Can this be done?

- platform: numeric_state
      entity_id: sun.sun
      value_template: "{{ state_attr('sun.sun', 'azimuth') | float }}"
      above: 145
22/10/2020 145
22/11/2020 168
22/12/2020 165
22/1/2021 161
22/2/2021 157
22/3/2021 155
22/4/2021 127
22/5/2021 117
22/6/2021 111
22/7/2021 115
22/8/2021 127
22/9/2021 140

Not a full answer, more of a speculation:

What are you trying to accomplish?

So each month has a specific value?
If month = 10 (October) then AzMin (Azimuth minimum) = 145
If month = 11 then AzMin = 168
Then compare AzMin to sensor.sun_azimuth

That is close to what I need. How can I set though if month 10 AzMin=145?

Example that I use for air quality that has “IF” statements in Sensor. This is what you want I believe.

    purpleair_description:
      friendly_name: 'PurpleAir AQI Description'
      unique_id: purpleair_description
      value_template: >
        {% set aqi = states('sensor.purpleair_aqi')|float %}
        {% if aqi >= 401.0 %}
          Very Hazardous
        {% elif aqi >= 301.0 %}
          Hazardous
        {% elif aqi >= 201.0 %}
          Very Unhealthy
        {% elif aqi >= 151.0 %}
          Unhealthy
        {% elif aqi >= 101.0 %}
          Unhealthy for Sensitive Groups
        {% elif aqi >= 51.0 %}
          Moderate
        {% elif aqi >= 0.0 %}
          Good
        {% else %}
          undefined
        {% endif %}
      entity_id: sensor.purpleair
      availability_template: "{{ sensor.purpleair_available }}"

https://community.home-assistant.io/t/weekday-and-month-sensor/45678/5
‘{% if now().month in (1,) %} January……. {% endif %}’

One possibility is to set a sensor for your Minimum Az

{% set xxx = states('now().month')|float %} # xxx being the variable
{% if xxx = 9}
  145
{% if xxx = 10}
  168

or make a binary sensor if sensor.sun_azimuth is > AzMin
depends on what you want to do

I don’t know if the now.month starts at zero or one; but for being 0100 for me, that is the answer you get. Well past my bedtime.

1 Like

Thank you, that is a start for sure.

I am curious as to what you are trying to use this for.

To close some covers when sun approach my balcony. The truth is I have found that I need some more values ~3 or 4 for each month at least and now I am looking for a way to test them.

Why not use:
sensor.sun_elevation with sensor.sun_azimuth
then the month does not matter

With a compass and a protractor you should be able to easily figure out the conditions the sun hits where you don’t want it.

Let me see if I can find a post someone had on mapping shadows, that might be handy to you in this case; at least it can give you your experimental information.

I don’t know the values of elevation for each month
but I do know the values of azimuth for each day of the year

https://community.home-assistant.io/t/feature-create-svg-to-display-sun-shaddow-position-of-my-house/237916

This gives you more resources:
https://community.home-assistant.io/t/idea-sensor-to-calculate-direct-sunshine-times-at-coordinates-between-buildings/186782

1 Like

Very useful links thanks

I have made this sensor and it is working. Thanks for you help
(The numbers are dummy)

- platform: template
  sensors:
    makis_azimuth_permonth:
        friendly_name: makis azimuth per month
        value_template: >
          {% if now().month in (1,) %} 100
           {% elif now().month in (2,) %} 110
            {% elif now().month in (3,) %} 120
             {% elif now().month in (4,) %} 130
               {% elif now().month in (5,) %} 140
                 {% elif now().month in (6,) %} 150
                   {% elif now().month in (7,) %} 160
                     {% elif now().month in (8,) %} 170
                       {% elif now().month in (9,) %} 180
                         {% elif now().month in (10,) %} 140
                           {% elif now().month in (11,) %} 200
                             {% elif now().month in (12,) %} 210
                             {% endif %}

Now this is just personal preference:
I don’t like calling the same function multiple times when the value will not change.
now().month will not change during this run, so, I would use a variable; however, variables can be finicky in HA. Not that speed is much of an issue here but it would run faster not calling multiple times.
That being said, if it works, use it.

Thanks for your feedback. To be honest I tried as per yours example but I couldn’t make it work. :slight_smile:

No problem; I didn’t try it myself. I just thought it should work, and give you can example of what I use that does. Why reinvent the wheel every time when you can just plagiarize from someone else.

1 Like