'None' has no attribute 'state' when rendering

Hello, I´m trying to clear my log. After every restart I have got this warning.

Template variable warning: 'None' has no attribute 'state' when rendering '{{ "/local/icons/pirateweather/" ~ states.sensor.pirateweather_icon_0d.state ~ ".png"}}'

Sensor looks like below:

- platform: template
  sensors: 
    forecast_0:
      friendly_name: Today
      value_template: >
        {{states.sensor.pirateweather_daytime_high_temperature_0d.state|round(0)}}°/{{states.sensor.pirateweather_overnight_low_temperature_0d.state|round(0)}}°/{{states.sensor.pirateweather_precip_probability_0d.state|round(0)}}%
      entity_picture_template: >-
        {{ '/local/icons/pirateweather/' ~ states.sensor.pirateweather_icon.state ~ '.png'}}

It works without problem, but this is last warning I have in my log and have no idea, how to solve it.

Can you please help me with this issue?

Thank you very much for help
M.

From the templating doc

You’re doing exactly what its telling you not to do. And so you’re getting the error it warned you about.

1 Like

@CentralCommand was faster than me, so I will focus in another point…

Why don’t you use new templating?

Something like this:

template:
  - sensor:
    - name: Today
      unique_id: forecast_0
      states: >-
        {{ states('sensor.pirateweather_daytime_high_temperature_0d') | round(0)}}°/{{states('sensor.pirateweather_overnight_low_temperature_0d') | round(0)}}°/{{states('sensor.pirateweather_precip_probability_0d') | round(0)}}%
      picture: >-
        {{ '/local/icons/pirateweather/' ~ states('sensor.pirateweather_icon') ~ '.png'}}

@CentralCommand @EdwardTFN Many thanks to both. Now everything looks without problem. Again - thank you very much for your help!

1 Like