Moon platform with moon phases pictures

how do i use other icons, this is my lovelance:

- type: entities
    title: Luna
    entities:
      - entity: sensor.moon

can anyone explain to me please how to use other moon phase icons?

I still use the method in post #2 of this thread.

Hope it’s of help.

ok i’ll try, thanks Akriss

Unfortunately I can’t get it to work, any other ideas?

post your efforts, and let us help you.
simply stating it doesnt work is meaningless

my code in configuration.yaml

moon:
    entity: sensor.moon
    friendly_name: 'Moon'
    value_template: '{{ states.sensor.moon.state }}'
    entity_picture_template: /local/MoonPhases/{{ states.sensor.moon.state }}.png

and this in lovelace

  - type: 'entity'
    name: Luna
    entity: sensor.moon

this is the result

it is not my intention to demand, I just politely asked for help

the link I posted was not about ‘demanding’ it was about providing information so we can see what your problem is.

With that new info you posted, I suspect you also have a sensor.moon_2 in your system, or maybe a sensor.template_moon. And probably startup errors in your log about that. You are naming that sensor identically to the core integration sensor…

Please show us a screenshot of the dev tools/state and type moon in the entity column
as already was said above, you should delete your Yaml section,

moon:
    entity: sensor.moon
    friendly_name: 'Moon'
    value_template: '{{ states.sensor.moon.state }}'
    entity_picture_template: /local/MoonPhases/{{ states.sensor.moon.state }}.png

and fully rely on the UI for Moon. see Moon - Home Assistant

next, you can create a template sensor, based on the state of that sensor.moon, and use that template for its picture.
but that too was also posted above, so please check that

btw, I just tested your yaml config, and it doesnt show an error… which is odd. It does nothing either, so you are simply seeing the core moon sensor in that card.

I suspect though that that piece of yaml is part of the now legacy format for template sensor:

sensor:

  - platform: template
    sensors:
      moon:
        entity: sensor.moon
        friendly_name: 'Moon'
        value_template: '{{ states.sensor.moon.state }}'
        entity_picture_template: /local/MoonPhases/{{ states.sensor.moon.state }}.png

and almost everything on that config is wrong…

so again, take it out and restart to get going as it should be done

Try with this updated code:

template:
    sensor:
       unique_id: my_moon_jpg
       name: 'My_Moon'
       state: "{{ states('sensor.moon_phase') }}"
       picture: /local/moon_phases/{{states('sensor.moon_phase') }}.png

I just tried on a fresh Hass.IO VM install and the moon sensor that standard in HA is being reported as “sensor.moon_phase

My currant Hass.IO that was first spin up many years ago and faithfully has been updated to the latest and greatest reports the standard moon sensor as just “sensor.moon

Once I made the sensor name change it worked as expected.

Strange the name change of the standard moon between installs, puzzling.

(edited for clarity)
Edit2:fixed mistake in code.
Edit3: replaced old style code in favor for newer
Edit4: corrected state line

let me just repeat one last time (even the community software complains I am over answering)

that is a bad and now legacy config.

Please dont point @UgoCo to that config, and you should update it yourself too.

if you follow my post above in the new template: format, you’re all set.

this legacy format is still possible in HA for downward compatibility, non breaking sake, but it is not the preferred way.

{{ states.sensor.moon_phase.state }}

is something all templates should avoid, at least make that

{{ states('sensor.moon_phase')}}

in both lines, to avoid startup issues the integration isnt yet intialized, see the template warnings in the documentation.

but better leave that config completely, and move to the template: format

OK I think I’ve converted that old legacy style sensor to the new way and seems to work well and that single startup warning is gone.

Just a weekend programmer here, so I’m not sure its %100, but it works.

template:
    sensor:
       unique_id: my_moon_jpg
       name: 'My_Moon'
       state: "{{ states('sensor.moon_phase') }}"
       picture: /local/moon_phases/{{states('sensor.moon_phase') }}.png

edit: corrected state line

fix that one too :wink:
btw, if you change the name to My Moon you dont have that ugly underscore in your frontend

state: '{{ states.sensor.moon_phase.state }}'

Try as I might I could not format that in a way that HA would except the syntax, so I left the older style.
Have a suggestion?

“My_moon” was on purpose. Big Gaudy name that make you want to change it.

I think it should just be state: {{ states('sensor.moon_phase') }} actually.

Maybe in quotes to force it to be string: state: "{{ states('sensor.moon_phase') }}" (not sure whether that is required).

1 Like

HA does not like that as well.
Error loading /config/configuration.yaml: mapping values are not allowed here in "/config/configuration.yaml", line 199, column 20

Line 199 is state: state: {{ states('sensor.moon_phase') }}

Oh well. Thank you however.

I got it. It’s double quotes, not singles.( /smack’s head )

template:
   - sensor:
       unique_id: my_moon_jpg
       name: 'My_Moon'
       state: "{{ states('sensor.moon_phase') }}"
       picture: /local/moon_phases/{{states('sensor.moon_phase') }}.png
1 Like

yep, see YAML Style Guide | Home Assistant Developer Docs

remember outside and inside quotes need to be different. It’s fairly easy once you see what it’s about.

way easier is using multi-line notation with >, and forget about those quotes.

state: >
  {{ states('sensor.moon') }}

same for the other template. all templates really
again: see my suggestion in the link you have

here I am, sorry mario I misunderstood.
so, i used the template that you showed me but i’m not getting in lovelance, here is the screen of the moon sensor, i have only one.

I get this response from the model