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.
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.
###### 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
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:
more-info:
If I use this:
entity_picture_template: >
{{ states('sensor.moon_phases') }}
I get this:
After several tests. Finally! Iâve made it.
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.
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.
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
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.
I have it like that but without the capital N in front,
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!!
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!