Using template sensor to create custom weather entity

Hello,

I’ve been attempting to create a custom weather entity that pull data from dark sky and met.no, in case dark sky is unavailable.

So far I’ve been able to copy most of the attributes with no problem, however I’ve run into problems with copying the array inside the forecast attribute.

    forecast: >
      {% if is_state('weather.dark_sky', 'unavailable') %}
        {{ state_attr('weather.home', 'forecast') }}
      {% else %}
        {{ state_attr('weather.dark_sky', 'forecast') }}
      {% endif %}

That code copies, but not as an array. I am clearly doing something wrong and I can’t tell if it’s the syntax or the code structure.

I could also be using the wrong words to search for my problem, so please correct me.

Your guidance is appreciated.

The result of any template is always a string value.

In addition, the state value of any entity can only be a string. In contrast, an entity’s attributes can be other types like integer, list (array), datetime, etc.