Sensor not displaying correct icons

I have this sensor template to show different icons related to moon phases, but the frontend doesn’t shows any icon…

- platform: template
  sensors:
    moonphases:
      entity_id: sensor.moon
      friendly_name: 'Moon'
      value_template: '{{ states.sensor.moon.state }}'
      entity_picture_template: >
        {% if is_state('sensor.moon', 'New moon') %}
         /local/moonphases/NNewMoon.jpg
        {% elif is_state('sensor.moon', 'Waxing crescent') %}
          /local/moonphases/NWaxingCrescent.jpg
        {% elif is_state('sensor.moon', 'First quarter') %}
          /local/moonphases/NFirstQuarter.jpg
        {% elif is_state('sensor.moon', 'Waxing gibbous') %}
          /local/moonphases/NWaxingGibbous.jpg
        {% elif is_state('sensor.moon', 'Full moon') %}
          /local/moonphases/NFullMoon.jpg
        {% elif is_state('sensor.moon', 'Waning gibbous') %}
          /local/moonphases/NWaningGibbous.jpg
        {% elif is_state('sensor.moon', 'Last quarter') %}
          /local/moonphases/NLastQuarter.jpg
        {% elif is_state('sensor.moon', 'Waning crescent') %}
          /local/moonphases/NWaningCrescent.jpg
        {% endif %}

The path to the icons is correct…
Where is the error?

This template should handle both states, old and new:

  moonphases:
    entity_id: sensor.moon
    friendly_name: 'Moon'
    value_template: >
      {{ states('sensor.moon').title().replace('_',' ').replace(' ','') }}
    entity_picture_template: >
      {% set state = states('sensor.moon').title().replace('_','').replace(' ','') %}
      {{ '/local/moon_phases/N{}.jpg'.format(state) }}

EDIT: It also doesn’t have crazy if statements…

3 Likes

Hey that’s a pretty sweet alternative.