Custom Images not shown on moon sensor

Fixed that mistake. Thank you very much.
But, now, another one appears:

Invalid config for [sensor.template]: [entity] is an invalid option for [sensor.template]. Check: sensor.template->sensors->moon_phases->entity. (See ?, line ?). Please check the docs at https://home-assistant.io/components/sensor.template/

Where’s the mistake?

not really sure, my eyes are dead for the moment (been updating my 84.3 to 94.4…)

this is what I use:

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

note the different approach on title versus capitalize.

also, be 100% positive about the files, names and location.

wait!: You have entity: sensor.moon

that is incorrect, should be entity_id: sensor.moon

as you can see, I don’t use that at all, because the HA instance can find entity_id in the template to use. So, first correct it, test, and if working, comment it out, and test again :wink:

1 Like

Corrected entity:id.
Now check config does not give error. But I don’t see the icons with the image of the phases of the moon.
I have a doubt.
JPG files are in HASSIO>config>www>luna
In the template file what should I write:

sensors:
  moon_phases:
    entity_id: sensor.moon

o

sensors:
  luna:
    entity_id: sensor.moon

Thank you very much for your interest

that doesn’t reply matter, it’s only the name of the sensor, (unless you use my example for friendly_name_template in which case it should be the same as the template of course, see my example)

if your files are in config/www/luna/, the template needs to be

{{ '/local/luna/{}.jpg'.format(state) }}

do you have any errors?

could you post the template in the dev-template page and make a screenshot of the output?

like this:

its important the files are case sensitive, so you need to have the template output exactly what the files are called. Or vice versa of course :wink:

1 Like

Thanks again.
This is what I see from dev-template page

ok that’s is good start,

you either need your image files to be WaningGibbous.jpg, or if you want only lowercase file names with an underscore between the words (like I do…) you’d need to change the template a bit.

Please show me a screen shot of your files, like this (with the path in view, so we can check the correct path in the template)

17

1 Like

Is this what you’re asking me to do?

Nombre_archivos
Perhaps you should name the files in Spanish. For example:
NWanninggibbous = NGibosamenguante

no, it’s clear. All files have a capital N in front of them. You rename the and take out the N of all files, and your template will work.

This is from files going over the web, where the N was meant for Northern Hemisphere. Since I didn’t need that I just took these out.

Thank you very much for your patience.
Now I change the names and restart Home Assistant

Realized the change, restarted H.A.
The moon icon does not show the image.
Icon_Luna_01
Now I have to leave it. Tomorrow I try it with your template.
Thank you

that is probably the sensor.moon, not sensor.moon_phases ?

you should add the sensor.moon_phases to a card or group to have it displayed in the front end

Changed sensor and success.
Icono_OK
Now I have to change the text from English to Spanish.
Wanning Gibbous = Gibosa menguante.

great!

not sure what will happen if you change the language. Is HA set to spanish?
no matter what, you want the name of the files to be the same as the state of the sensor.

That means you either adjust the names of the files (like you did now), or change the template to have an outcome you desire.
If you use the state of a regular sensor (so not a template sensor you make yourself) you have to use that, (and check it in the dev-state, because the frontend doens’t always show the state as is, it adapts it to eg a device_class, or language setting)

for example. A binary sensor is true/false, on/off etc etc. using a device_class: motion changes that to detected/clear…

my point being: anything is possible, just figure out what you want and adapt accordingly :wink:
we’re here to help!

I have HA configured in Spanish.
I tried renaming the image file WanningGibbous.jpg to GibosaMenguante.jpg and then the icon doesn’t appear.
Some time ago, thanks to the help of forum member 123, I had prepared this template.

###### Fases de la Luna ##########################
  -plataform: moon
# Nombre en español de Fases de la luna
  - plataform: template
    sensor:
      moon_phases
        fiendly_name: Luna
        entity: sensor.moon
        value_template: >
          {% set fases = { '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':'Lluna menguante'} %}
          {% set fase = states('sensor.moon') %}
            {{ fases[fase] if fase in fases.keys() else 'fase lunar desconocida' }}

I think it’s a little exaggerated, but I think it’ll work.
What do you think?

well, if it works for you, its fine by me :wink:

but, this is simply a name mapper, and not the sensor for your images.

If you’d want that sensor to check this sensor for spanish names, you need to adjust that.

its getting a bit complex like this, but so you understand what you’re doing:

1- create this name mapper, called sensor.moon_phases, which has as state, the names of the moon phases in spanish.

2 take that sensor as base for you image sensor to follow the spanish names, and adjust the file names accordingly.

or am I misunderstanding you now?

After consulting the documentation and examples of templates and several attempts I have not succeeded.
First I changed the name of a file from WaningGibbous.jpg to GibosaMenguante.jpg. So, in the card appears the name in Spanish, but, disappears the icon.
Then I tried with my template and the name is still in English.
Check config is valid and, apparently, the template is fine


But this error appears in the log:
Log Details (WARNING)
Tue Jun 25 2019 09:59:05 GMT+0200 (hora de verano de Europa central)
Your configuration contains extra keys that the platform does not support.
Please remove [sensor]. (See /config/configuration.yaml, line 137).
Offending data: {“platform”: “template”, “sensors”: “”, “sensor”: {“moon_phases”: {“fiendly_name”: “Luna”, “entity_id”: “sensor.moon”, “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’:‘Lluna menguante’} %} {% set phase = states(‘sensor.moon’) %} {{ phases[phase] if phase in phases.keys() else ‘fase lunar desconocida’ }}\n”}}}

This is the templates section of my configuration file:

#################################################################
# Comienza TEMPLATES
#################################################################
###### Fases de la Luna ##########################
# Iconos de Fases de la luna
  - platform: template
    sensors:
      moon_phases:
        entity_id: sensor.moon
        friendly_name: 'Luna'
        value_template: >
          {{ states('sensor.moon').title().replace('_',' ') }}
        entity_picture_template: >
          {% set state = states('sensor.moon').title().replace('_','') %}
            {{ '/local/luna/{}.jpg'.format(state) }}
            
# Nombres de las Fases de la Luna en castellano ###################
    sensor:
      moon_phases:
        fiendly_name: Luna
        entity_id: sensor.moon
        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':'Lluna menguante'} %}
          {% set phase = states('sensor.moon') %}
          {{ phases[phase] if phase in phases.keys() else 'fase lunar desconocida' }}
###################################################################
# Finaliza TEMPLATES
###################################################################

I have come to the conclusion, I do not know if it is correct, that, instead of two templates, only one template is needed, which serves for both things, icons and names. Unfortunately, my lack of knowledge of programming languages and my difficulties with English, make me unable to find the right syntax for the template.
Again, abusing your patience and generosity, I am forced to ask for your help. Thank you.

try this:

  sensor:
      moon_phases:
        fiendly_name: Luna
        entity_id: sensor.moon
        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':'Lluna 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) }}

fyi the last line could also be:

{{ '/local/luna/' + state + '.jpg'}}

and have the names of the images use only lower case and use a _ between words:

fase_lunar_desconocida.jpg
lluna_menguante.jpg

etc etc.

what this entity picture does is take the state of your template sensor moon phases, (which are the moon phases translated to spanish) and then simply replaces the space with a _ and turns lower case…

hope this works

Again, thank you very much for your patience and help. But before I start, I have a question. What syntax is the right one:

#################################################################
# Comienza TEMPLATES
#################################################################
###### Fases de la Luna - Iconos y Nombres#######################
  - platform: template
    sensors:
      moon_phases:
        entity_id: sensor.moon
        friendly_name: Luna

o, esta otra

#################################################################
# Comienza TEMPLATES
#################################################################
###### Fases de la Luna - Iconos y Nombres#######################
  - platform: template
    sensor:
      moon_phases:
        entity_id: sensor.moon
        friendly_name: Luna

The difference is sensor: or sensors:

no problem,
see Template - Home Assistant

I’ve tried both alternatives for the last line. In both cases the text of the moon phase is correct, but the icon with the image does not appear.
There are no error messages in the log and this is the script check.


A clarification: I don’t have an image for unknown moon-phase.