Moon platform with moon phases pictures

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

You’re changing the name of the sensor, I don’t think that will work, since that will also change its entity_id. The name should probably be something like “Moon phase”. Your entity will then be named sensor.moon_phase.

I’m not understanding anything anymore, I found this sensor in the overview tabSenza titolo5

I took the id and put it in lovelace

  - type: 'tile'
    name: Luna
    entity: sensor.asgrouwe_maan_unknown_2
    show_state: true

the result

and only if i click on the tab i see the png image, how can i see the image instead of the eye?Senza titolo7

Like I said, don’t set the name like this. The entity id will change with every state change of the moon.

As for the tile card, I think you need to set show_entity_picture: true instead.

do i need to change this name?

Yes. The ID is derived from the name of a template sensor. It’s extremely inconvenient if that changes based on the state of an entity…

That name looks more like something you could put in the state of your template sensor.

I also renamed the sensor to " sensor.fase_lunare" and added it to lovelance, it seems to work. last question, perhaps stupid… but to translate the phases of the moon into another language, just go to the template and replace the translated items?

UgoCo
dose you mean like this “translate to german”

sensor:
  - platform: template
    sensors:
      mond:
        entity_id: sensor.mond
        friendly_name: 'Mond'
        value_template: >
          {% if is_state('sensor.moon_phase', 'new_moon') %}
             Neumond
          {% elif is_state('sensor.moon_phase', 'waxing_crescent') %}
             Zuhnemender Sichelmond     
          {% elif is_state('sensor.moon_phase', 'first_quarter') %}
             Zunehmender Halbmond
          {% elif is_state('sensor.moon_phase', 'waxing_gibbous') %}
             Zuhnemender Dreiviertelmond
          {% elif is_state('sensor.moon_phase', 'full_moon') %}
             Vollmond
          {% elif is_state('sensor.moon_phase', 'waning_gibbous') %}
             Abnehmender Deiviertelmond
          {% elif is_state('sensor.moon_phase', 'last_quarter') %}
             Abnehmender Halbmond
          {% elif is_state('sensor.moon_phase', 'waning_crescent') %}
             Abnehmender Sichelmond
          {% endif %}
        entity_picture_template: /local/moon_phases/{{ states("sensor.moon_phase") }}.png

Yes, except this is an old style template sensor. So please don’t post variations of this anymore…

Kars,
I’m sorry about this, could you correct it to current version “sorry I don’t know how to do” or point me how to do

Something like this, I guess. This should generate a sensor with entity id sensor.mond:

template:
  - sensor:
    - name: 'Mond'
      unique_id: my_moon
      state: >
          {% if is_state('sensor.moon_phase', 'new_moon') %}
             Neumond
          {% elif is_state('sensor.moon_phase', 'waxing_crescent') %}
             Zuhnemender Sichelmond     
          {% elif is_state('sensor.moon_phase', 'first_quarter') %}
             Zunehmender Halbmond
          {% elif is_state('sensor.moon_phase', 'waxing_gibbous') %}
             Zuhnemender Dreiviertelmond
          {% elif is_state('sensor.moon_phase', 'full_moon') %}
             Vollmond
          {% elif is_state('sensor.moon_phase', 'waning_gibbous') %}
             Abnehmender Deiviertelmond
          {% elif is_state('sensor.moon_phase', 'last_quarter') %}
             Abnehmender Halbmond
          {% elif is_state('sensor.moon_phase', 'waning_crescent') %}
             Abnehmender Sichelmond
          {% endif %}
      picture: >
        {% set state = states('sensor.moon') %}
        /local/MoonPhases/{{state}}.png

Or use the mapper technique from the example of @Mariusthvdb:

template:
  - sensor:
    - name: 'Mond'
      unique_id: my_moon
      state: >
        {% 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}})
      picture: >
        {% set state = states('sensor.moon') %}
        /local/MoonPhases/{{state}}.png

I tried to translate into Italian, but I didn’t get any result, where am I wrong?

template:
  - sensor:
      - unique_id: moon_phases
        name: >
          {% set phase = states('sensor.moon') %}
          {% set mapper = {'new_moon':'Luna Nuova',
                           'waxing_crescent':'Luna Crescente',
                           'first_quarter':'Primo Quarto',
                           'waxing_gibbous':'Gibbosa Crescente',
                           'full_moon':'Luna Piena',
                           'waning_gibbous':'Gibbosa Calante',
                           'last_quarter':'Ultimo Quarto'} %}
          {{mapper.get(phase,'Luna Calante')}}
          ({{phase|replace('_',' ')|capitalize}})
        state: >
          {{states('sensor.moon').capitalize().replace('_',' ')}}
        picture: >
          {% set state = states('sensor.moon') %}
          /local/MoonPhases/{{state}}.png

you templated the name, not the state

the name is correctly set to Luna Calante (Waning crescent)?

maybe this is not your template sensor, but the system moon sensor

my model sensor is sensor.phase_moon, i replaced it but its not working

template:
  - sensor:
      - unique_id: moon_phases
        name: >
          {% set phase = states('sensor.fase_lunare') %}
          {% set mapper = {'new_moon':'Luna Nuova',
                           'waxing_crescent':'Luna Crescente',
                           'first_quarter':'Primo Quarto',
                           'waxing_gibbous':'Gibbosa Crescente',
                           'full_moon':'Luna Piena',
                           'waning_gibbous':'Gibbosa Calante',
                           'last_quarter':'Ultimo Quarto'} %}
          {{mapper.get(phase,'Luna Calante')}}
          ({{phase|replace('_',' ')|capitalize}})
        state: >
          {{states('sensor.fase_lunare').capitalize().replace('_',' ')}}
        picture: >
          {% set state = states('sensor.fase_lunare') %}
          /local/MoonPhases/{{state}}.png

yes, in fact the template says crescent moon, but in fact it is waning as also indicated on this site: Fase lunare di oggi | Ciclo lunare attuale per oggi e stanotte