Moon platform with moon phases pictures

The moon integration is installed, otherwise no entry in a yaml refers to the moon phase.
The template result:

seems there’s no sensor.moon? it defaults to the default, in stead of mapping the state.

what does {{states('sensor.moon')}} return in dev templates

you sure you have this in your integrations:

Scherm­afbeelding 2022-11-11 om 11.30.42

your template should return:

1 Like

The integration is installed.
moon_4

{{states('sensor.moon')}} returns:

I am very confused.

clicking that entity in the integration panel, what entity is shown?

also, please show the sensor.moon in dev states

and lo and behold, I now see that same device_class: moon__phase, whihc cant be right.

lets find out about that
seems intended, though I figure its a typo: core/sensor.py at 6517e3e21e5828a317ea8b814d0345f2536b9170 · home-assistant/core · GitHub

1 Like

How can I show the sensor.moon in dev states?

ok, thats what I figured… you dont have a sensor.moon, but sensor.moon_phase. this is completely new to me (my entity is from before the move to the ui integration, so that probably causes that entity_id)

change the template to use that entity_id, and you’re set.

{% set phase = states('sensor.moon_phase') %}

its what you did here: Moon platform with moon phases pictures - #29 by noob6741

and I hadn’t suspected that to be the new entity_id of the core integration…
on the device_class: moon__phases, Ive just learned:

It’s a custom device class that sensors can define to have translation for the states, and it’s intended

see also Backend Localization | Home Assistant Developer Docs

also:

New entities should get an entity_id like sensor.moon_phase from what I can read in the code. We’ve set the entity to follow our new entity naming guidelines.

so thats all by design.

1 Like

First of all thank you very much for your help.
I modified the templates.yaml as follows:

#Sunrise and Sunset
    - sensor:
        - name: next sunrise
          state: >
            {{as_timestamp(state_attr('sun.sun','next_rising'))| timestamp_custom('%H:%M') }}
          icon: mdi:weather-sunset-up
        - name: next sunset
          state: >
            {{as_timestamp(state_attr('sun.sun','next_setting'))| timestamp_custom('%H:%M') }}
          icon: mdi:weather-sunset-down

#Moon Phases
        - unique_id: moon_phases
          name: >
            {% set phase = states('sensor.moon_phase') %}
            {% set mapper = {'new_moon':'Neumond',
                             'waxing_crescent':'zunehmender Mond',
                             'first_quarter':'Erstes Viertel',
                             'waxing_gibbous':'Halbmond',
                             'full_moon':'Vollmond',
                             'waning_gibbous':'Abnehmender Mond',
                             'last_quarter':'Letztes Viertel'} %}
            {{mapper.get(phase,'Aschgrauer Mond')}}
            ({{phase|replace('_',' ')|capitalize}})
          state: >
            {{states('sensor.moon_phase').capitalize().replace('_',' ')}}
          picture: >
            {% set state = states('sensor.moon_phase') %}
            /local/moonphases/{{state}}.png

template result:

Unfortunately still no moon_phases sensor

great, your template is working .

what’s probably happening, is that the entity_id of the new sensor is not containing ‘moon’, but the state, waning_gibbous.

try searching for that in the entity filter in dev states. Although, Ive just added the German sensor, and see

it all depends on whether you had this sensor before, on the unique_id you give it, and maybe if you had already edited the entity_id (to take out the ‘template’ bit) .
it must be there (if you at least did a Reload Templates), now just got to find it :wink:

because we set the unique_id, you can edit all of these in the UI clicking the Info icon

1 Like

Found by searching for moon in attributes


Was the name generated by line 23 in templates.yaml?

I changed the name of the sensor in the UI.
moon_11

Looks very good.
Thank you

1 Like

the entity_id was created upon first load of that entity. It is henceforth attached to the unique_id, so wont change anymore, no matter the name/state template changes you do after that.

As said, you can easily change it, as you have done.
great it’s working for you now.

1 Like

I hope my last question:
Can I delete the translation in brackets?

sure, just adjust the template, and take out ({{phase|replace('_',' ')|capitalize}})

1 Like

hi, i have this error, can you tell me how to fix it?

‘Platform error binary_sensor.Moon - Integration ‘Moon’ not found.’

despite the integration moon is present

Do you use the yaml or UI integration? The yaml is deprecated.

yes I use yaml integration

Delete it and use the UI integration (Settings->Integration).

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.