Custom Images not shown on moon sensor

that should be: fase_lunar_desconocida.jpg
I presume you have added images for all these in the same folder?

I’m not doing something right.
Here are my files with icons.
Crapetas_archivos_iconos
This is the template, as it is in my configuration.yaml file.

###### Fases de la Luna - Iconos y Nombres ######################
  - platform: template
    sensors:
      moon_phases:
        entity_id: sensor.moon
        friendly_name: Luna
        value_template: >
          {% set phases = { 'new_moon':'Luna nueva', 'waxing_crescent':'Luna creciente', 'first_quarter':'Cuarto creciente', 'waxing_gibbous':'Gibosa creciente', 'full_moon':'Luna llena', 'waning_gibbous':'Gibosa menguante', 'last_quarter':'Cuarto menguante', 'waning_crescent':'Luna menguante'} %}
          {% set phase = states('sensor.moon') %}
          {{ phases[phase] if phase in phases.keys() else 'fase lunar desconocida' }}
        entity_picture_template: >
          {% set state = states('sensor.moon_phases').replace(' ','_')|lower %}
          {{ '/local/luna/{}.jpg'.format(state) }}

There are no error messages, but the sensor shows this


I have carefully reviewed the texts, but I did not find the error.

I tried your template sensor and it produced the same result: entity_picture is unknown.jpg.

I changed the template to use sensor.moon instead of sensor.moon_phases and it works.

        entity_picture_template: >
          {{ '/local/luna/{}.jpg'.format(states('sensor.moon')) }}

However, to use this version, you will have to rename all of the jpg files you have from Spanish to English


EDIT
Or use the template @petro provided (below) and then you won’t need to rename the files.

:slight_smile:

1 Like
###### Fases de la Luna - Iconos y Nombres ######################
  - platform: template
    sensors:
      moon_phases:
        entity_id: sensor.moon
        friendly_name: Luna
        value_template: >
          {% set phases = { 'new_moon':'Luna nueva', 'waxing_crescent':'Luna creciente', 'first_quarter':'Cuarto creciente', 'waxing_gibbous':'Gibosa creciente', 'full_moon':'Luna llena', 'waning_gibbous':'Gibosa menguante', 'last_quarter':'Cuarto menguante', 'waning_crescent':'Luna menguante'} %}
          {% set phase = states('sensor.moon') %}
          {{ phases[phase] if phase in phases.keys() else 'fase lunar desconocida' }}
        entity_picture_template: >
          {% set phases = { 'new_moon':'Luna nueva', 'waxing_crescent':'Luna creciente', 'first_quarter':'Cuarto creciente', 'waxing_gibbous':'Gibosa creciente', 'full_moon':'Luna llena', 'waning_gibbous':'Gibosa menguante', 'last_quarter':'Cuarto menguante', 'waning_crescent':'Luna menguante'} %}
          {% set phase = states('sensor.moon') %}
          {% set name =  phases[phase] if phase in phases.keys() else 'fase lunar desconocida' }}
          {{ '/local/luna/{}.jpg'.format(name.replace(' ','_').lower()) }}

EDIT: Or rename the files to enlish as @123 said

1 Like

all I can see is it works just fine in my setup:

I use the state of the template_sensor always as base for the entity_picture of that sensor, (so not repeat the value_template) and it works without any issue.

something else must be wrong in the setup for the entity_picture_template to show unknown

@El_Viejo what does this result in in the dev-template:

{{states('sensor.moon_phases').replace(' ','_')|lower}} ?

The template using sensor.moon_phases also worked for me when I tested it in the Template Editor. However, when used in the template sensor, it produced ‘unknown’.

Any ideas what that ‘something else’ might be?

The entity_picture template refers to itself (sensor.moon_phases). It appears its state is ‘unknown’ at the time the template is evaluated.

Many thanks to all of you for your interest and patience.
Due to the time difference, I will try the solution tomorrow. I will keep you informed.
Good evening.

not yet, but that’s why I asked what the {{states('sensor.moon_phases').replace(' ','_')|lower}} results in.

if that’s ok, then your suggestion could very well be correct (though I haven’t had that happen in the cases I use this, maybe different types of initialization) and a small test could be builtin the entity_picture_template on the state being unknown, showing the fase_lunar_desconocida.jpg

as an example for this way of templating to work alright:

      day_phase:
        friendly_name: 'Day Phase'
        entity_id: sensor.time
        value_template: >
          {% if now() > now().replace(hour=6).replace(minute=0).replace(second=0) and
                now() < now().replace(hour=12).replace(minute=0).replace(second=0) %}
          Morning
          {% elif states('sun.sun') == 'above_horizon' or 
              now() > now().replace(hour=12).replace(minute=0).replace(second=0) and
              now() < now().replace(hour=18).replace(minute=0).replace(second=0) %}
          Day
          {% elif states('sun.sun') == 'below_horizon' or 
              now() >  now().replace(hour=18).replace(minute=0).replace(second=0) and
              now() < now().replace(hour=23).replace(minute=59).replace(second=59) %}
          Evening
          {% else %}
          Night
          {% endif %}
        icon_template: >
          {% if is_state('sensor.day_phase','Morning') %} mdi:weather-sunset-up
          {% elif is_state('sensor.day_phase','Day') %} mdi:weather-sunny
          {% elif is_state('sensor.day_phase','Evening') %} mdi:weather-sunset-down
          {% else %} mdi:weather-night
          {% endif %}

or with a template using the state directly

      utc_offset:
        friendly_name: Utc offset
        entity_id: sensor.time
        value_template: >
          {{ now().utcoffset().total_seconds()/3600 }}
        icon_template: >
          mdi:numeric-{{ states('sensor.utc_offset')|int|abs }}

also, just gave it another whirl an restarted using this (note even the friendly_name_template uses the state of itself…):

      moon_phases:
        friendly_name_template: >
          {{states('sensor.moon_phases')}}
        value_template: >
          {{states('sensor.moon').capitalize().replace('_',' ')}}
        entity_picture_template: >
          {% set state = states('sensor.moon_phases') %}
          {{ '/local/weather/moonphases/{}.jpg'.format(state).replace(' ','_')|lower }}

and it is showing nicely: 14

more-info: 36

If I use this:

        entity_picture_template: >
          {{ states('sensor.moon_phases') }}

I get this:
Screenshot%20from%202019-06-25%2016-33-47

After several tests. Finally! I’ve made it. :smiley::smiley::smiley:
Luna_exito

I am using the proposal of @123, changing the names of the image files, again, to English.
The other attempts, in my case, did not pass the check config.
Thank you very much for your help. For a 78 year old man it is a great satisfaction to find people willing to devote their time to a matter that is really of little importance.

4 Likes

Hola @El_Viejo,

Estoy intentando ponerlo con la foto pero no lo consigo,

¿podrías poner el código que has utilizado entero? ¿toda la configuración excepto las imágenes las has puesto en configuration.yaml?

Muchas gracias de antemano,

Un saludo!

I hope that the rest of the participants, for once, will excuse us for using Spanish. :wink:
Aquí tienes el código de mi archivo de configuración configuration.yalm

################################################################
# Comienza TEMPLATES
#################################################################
###### Fases de la Luna - Iconos y Nombres#######################
  - platform: template
    sensors:
      moon_phases:
        entity_id: sensor.moon
        friendly_name: Luna
        value_template: >
          {% set phases = { 'new_moon':'Luna nueva', 'waxing_crescent':'Luna creciente', 'first_quarter':'Cuarto creciente', 'waxing_gibbous':'Gibosa creciente', 'full_moon':'Luna llena', 'waning_gibbous':'Gibosa menguante', 'last_quarter':'Cuarto menguante', 'waning_crescent':'Luna menguante'} %}
          {% set phase = states('sensor.moon') %}
          {{ phases[phase] if phase in phases.keys() else 'fase lunar desconocida' }}
        entity_picture_template: >
          {{ '/local/luna/{}.jpg'.format(states('sensor.moon')) }}

Las imágenes las he ubicado aquí:
RED>HASSIO>config>www>luna.
Espero que pueda servirte.

Disculpad por el español,

Una pregunta ¿Y las imágenes al final en inglés o español? solo consigo que me aparezca esto

image

The names of the images in English. For example: first_quater.jpg

But I don’t get that I can find the image,

What can I select?

You need to have eight JPG files with the images of the different phases.

Carpetas_config

Carpetas_config_01

I have it like that but without the capital N in front,
image

and in configuration.yaml I have the same code as you.

What do I have to put in the summary tab to read me with the images?

Do I have to use another type of card?

Thanks you very much!!

This is the configuration of my Entities Card. Look at Lovelace “Entities Card”.

I forgot to warn you that the names of your image files are correct.
One of my first problems was due to that N in the names of the image files. I inadvertently sent you an image from an old file.

I’m going to try and tell you,

Do you have any images when the moon phase is unknown?

The images with the code have taken them directly, right?

thank you!