Openweathermap forecast freezing temperatures notification

Hi,
I received following code for above idea.
I have a valid API_Key.

The problem: I can’t get it running.
When I fill this in Developer Tools I get:
Error rendering template: UndefinedError: ‘None’ has no attribute ‘attributes’

My config.yaml looks like this:

weather:
  - platform: openweathermap
    api_key: 4xxxxxxxxxxxxxxxxxxxxx1
    name: MyStreetname
    mode: hourly
    
sensor:
  - platform: template
  sensors:
    min_temp_next_36h:
      friendly_name: Min Temperatur in den nächsten 36h
      value_template: >-
        {% set temperature = namespace(min=99) %}
        {% for item in states.weather.openweathermap.attributes.forecast[:11] %}
          {% if ((item.temperature | float) < temperature.min) %}
            {% set temperature.min = (item.temperature | float) %}
          {% endif %}
        {% endfor %}
        {{ temperature.min }}

I would be glad, if someone can help me getting this thing running :slight_smile:

Regards,
Jörg

Works for me with state_attr and darksky.

EDIT: Also works with:

{%- for item in states.weather.dark_sky.attributes.forecast[:11] -%}

I suspect that your weather entity has a different name than weather.openweathermap, probably weather.MyStreetname or something like that. I would use @VDRainer’s suggestion to use state_attr also. Check the warning here.

Hi,
I have a new status, but I am a little frustrated about the YAML use in HA.
It seems, that the problem is somewhere hidden in used or not used spaces/TABs etc.

  • I have deleted the section with the temperature forecast and it works all fine. The weather entity is available and the Template Checker returns a valid value if I paste the following code part
        {% set temperature = namespace(min=99) %}
        {%- for item in state_attr('weather.xxxxxx_owm', 'forecast')[:11] -%}
        {% if ((item.temperature | float) < temperature.min) %}
        {% set temperature.min = (item.temperature | float) %}
        {% endif %}
        {% endfor %}
        {{ temperature.min }} 

  • The next test I have done with the complete source block
# Example configuration.yaml entry
sensor:
  - platform: template
    sensors:
      min_temp_next_36h:
        friendly_name: Min Temperatur in den nächsten 36h
        value_template: >-
        {% set temperature = namespace(min=99) %}
        {%- for item in state_attr('weather.falenbek_owm', 'forecast')[:11] -%}
        {% if ((item.temperature | float) < temperature.min) %}
        {% set temperature.min = (item.temperature | float) %}
        {% endif %}
        {% endfor %}
        {{ temperature.min }}

But this returns directly NON AVAILABLE Entities in the front end and following error message:

while scanning for the next token
found character ‘%’ that cannot start any token
in “/config/configuration.yaml”, line 49, column 10
This is exactly the ‘%’ after value_template…before the ‘set’.

  • The mentioned fault I assume , is linked to YAML space/TAB issues as described here Github YAML issue
    I tried to check my configuration.yaml with Notepad++ functions to visualize all hidden characters etc. But the file contains only spaces…no TABS.

  • Next point I have done is copying the Template Sensor code from the Template HA documentation page - and it worked

  • afterwards I added only this part of the code

      min_temp_next_36h:
        friendly_name: Min Temperatur in den nächsten 36h
        value_template: >-
        {% set temperature = namespace(min=99) %}
        {%- for item in state_attr('weather.falenbek_owm', 'forecast')[:11] -%}
        {% if ((item.temperature | float) < temperature.min) %}
        {% set temperature.min = (item.temperature | float) %}
        {% endif %}
        {% endfor %}
        {{ temperature.min }}

But no success - all entities not available and the same fault as described before.

  • Last point was trying to type the complete line 49 manually new - but same error

I am reaching a dead-end now.
The following part was not part of the Template checker code and neither of the successful try with the Template sensor example (solar_angle).

     min_temp_next_36h:
        friendly_name: Min Temperatur in den nächsten 36h
        value_template: >-

Is here some last point I have not checked?
Please find the part of the config file attached.

Any help is appreciated.

Regards from the dead end :slight_smile:
Jörg
PS: Seems that YAML costs time - a lot


The complete configuration.yaml block - since I have no clue how to upload a yaml file here:

# Example configuration.yaml entry to enable the cloud component
cloud:

# Example configuration.yaml entry
sun:

# Example Openweathermap Configuration
weather:
  - platform: openweathermap
    api_key: 4caaaaaaaaaaaaaaaaaaaaaaf1
    name: xxxxx_owm

# Example configuration.yaml entry
sensor:
  - platform: template
    sensors:
      solar_angle:
        friendly_name: "Sun angle"
        unit_of_measurement: 'degrees'
        value_template: "{{ state_attr('sun.sun', 'elevation') }}"

      sunrise:
        value_template: "{{ state_attr('sun.sun', 'next_rising') }}"

      min_temp_next_36h:
        friendly_name: Min Temperatur in den nächsten 36h
        value_template: >-
        {% set temperature = namespace(min=99) %}
        {%- for item in state_attr('weather.xxxxx_owm', 'forecast')[:11] -%}
        {% if ((item.temperature | float) < temperature.min) %}
        {% set temperature.min = (item.temperature | float) %}
        {% endif %}
        {% endfor %}
        {{ temperature.min }}

# Example configuration.yaml entry
binary_sensor:
  - platform: workday
    country: DE
    workdays: [mon, tue, wed, thu]
    excludes: [fri, sat, sun]

# Text to speech
tts:
  - platform: google_translate

# Example configuration.yaml entry
alarm_control_panel:
  - platform: manual
    name: Home Alarm
    code: xxxx
    pending_time: 20
    delay_time: 20
    trigger_time: 4
    disarmed:
      trigger_time: 0
    armed_home:
      pending_time: 0
      delay_time: 0

The solution:
All lines with a curly bracket needs to be indented by 2 spaces.
Received some help in the german Home assistant forum
https://homeassistantforum.de/

      min_temp_next_36h:
        friendly_name: Min Temperatur in den nächsten 36h
        value_template: >-
          {% set temperature = namespace(min=99) %}
          {%- for item in state_attr('weather.xxxxx_owm', 'forecast')[:11] -%}
          {% if ((item.temperature | float) < temperature.min) %}
          {% set temperature.min = (item.temperature | float) %}
          {% endif %}
          {% endfor %}
          {{ temperature.min }}

Are there any changes? this code worked well but since few days the value is “unavailable”