Solcast API Limits keep being exceeded

I wonder if anyone can assist on this. I am a complete newbie on HA and not a programmer. I have installed the Solcast integration and it is working. Following the instructions carefully I know that there is a limit of 10 calls to the API and there was an example of an Automation which I have used (see below). The problem is the limit is hit by approx 11:44 every day. I turned on logging and I can see clearly that it is duplicating the call each time it calls the api (at least within a few seconds of each other) hence I assume why I am hitting the buffer. Can anyone help YAML code below

alias: Solcast update
description: “”
trigger:

  • platform: template
    value_template: >-
    {% set nr = as_datetime(state_attr(‘sun.sun’,‘next_rising’)) | as_local %}
    {% set ns = as_datetime(state_attr(‘sun.sun’,‘next_setting’)) | as_local
    %} {% set api_request_limit = 10 %} {% if nr > ns %}
    {% set nr = nr - timedelta(hours = 24) %}
    {% endif %} {% set hours_difference = (ns - nr) %} {% set interval_hours =
    hours_difference / api_request_limit %} {% set ns = namespace(match =
    false) %} {% for i in range(api_request_limit) %}
    {% set start_time = nr + (i * interval_hours) %}
    {% if ((start_time - timedelta(seconds=30)) <= now()) and (now() <= (start_time + timedelta(seconds=30))) %}
    {% set ns.match = true %}
    {% endif %}
    {% endfor %} {{ ns.match }}
    condition:
  • condition: sun
    before: sunset
    after: sunrise
    action:
  • delay:
    seconds: “{{ range(30, 360)|random|int }}”
  • data: {}
    action: solcast_solar.update_forecasts
    mode: single

Unfortunately that is unreadable.

Do not copy and paste from your mobile.

And when you copy from your PC, format it properly after you paste it here, see: https://community.home-assistant.io/t/how-to-help-us-help-you-or-how-to-ask-a-good-question/114371#oneone-format-it-properly-16

Hi Graham, although this is already better then what you posted first, it’s not what is written in the link that Tom posted…

Hi Nick,
Really? Oh crikey what have I done then? Ok so sorry I’ll go back and check as all I thought I did was copy and paste.
Graham

@tom_l Ok understood.

I actually think I have found the issue. On further reading of the notes I realised that I hadn’t changed the (api_request_limit = 5) as I have two elevations/accounts.

Sio sorry I have amend the YAML code and hopefully that will have solved the issue.

Thanks