Moon-Phases

I had moon-phases working with YAML Configuration prior to the latest upgrade.
Has YAML Configuration been removed for moon-phases?

The configuration of the Moon integration changed from YAML to UI in the April 2022 release of Home Assistant.

OK 
 YAML was more flexible than UI 
 no value added with the change

For the Moon integration, what was more flexible about YAML configuration?

no value added with the change

One advantage is that you don’t have to restart Home Assistant to install the Moon integration (or restart to remove the Moon integration).

I had in YAML following 


      moon_phases:
        friendly_name: ' '
        value_template: >-
          {% set phases = {'first_quarter': 'Tilltagande halvmÄne', 'full_moon': 'FullmÄne',
                           'last_quarter': 'Avtagande halvmÄne', 'new_moon': 'NymÄne',
                           'waning_crescent': 'Avtagande mÄnskÀra', 'waning_gibbous': 'Avtagande gibbousmÄne',
                           'waxing_crescent': 'Tilltagande mÄnskÀra', 'waxing_gibbous': 'Tilltagande gibbousmÄne'} %}
          {% set phase = states('sensor.moon') %}
          {{ phases[phase] if phase in phases.keys() else 'Error' }}

How can I get them to UI?

Maybe Custom-UI can help out?

What you posted isn’t the Moon integration. It’s a Template Sensor that references sensor.moon.

You’re confusing YAML configuration of the Moon integration with YAML configuration of a Template Sensor. Currently there’s no support for Template Sensor configuration via the UI, only via YAML.

I read the documentation for Templates 
 still confused but at a higer level.

I translated moon phases to swedish with replace (as below) and it worked OK
Now I want to use mdi: icon but don’t see how.


  • platform: template
    sensors:

    moon_phases:
    friendly_name: ‘’
    value_template: >-
    {{ states (‘sensor.moon_phase’) | replace(“first_quarter”, “Tilltagande halvmĂ„ne”) | replace(“full_moon”, “FullmĂ„ne”) 

    icon_template: mdi:moon-???


Take ‘full-moon’ as an example.
The mdi site tells me that the name is ‘moon-full’ but when I check with dev tool in HA it gives me for sensor.moon_phases following:

options:

  • first_quarter
  • full_moon
  • last_quarter
  • new_moon
  • waning_crescent
  • waning_gibbous
  • waxing_crescent
  • waxing_gibbous

Clearly there is a difference in names ‘full_moon’ and ‘moon-full’.
How should icon_template: mdi:moon-??? look like?

I suggest you create a Template Sensor in modern format (not legacy format).

Example:

template:
  - sensor:
      - name: MĂ„nfaser
        state: >
          {% set phase = states('sensor.moon_phase') %}
          {{ { 'new_moon': 'NymÄne',
               'waxing_crescent': 'Tilltagande mÄnskÀra',
               'first_quarter': 'Tilltagande halvmÄne',
               'waxing_gibbous': 'Tilltagande gibbousmÄne',
               'full_moon': 'FullmÄne',
               'waning_gibbous': 'Avtagande gibbousmÄne',
               'last_quarter': 'Avtagande halvmÄne', 
               'waning_crescent': 'Avtagande mÄnskÀra' }.get(phase, phase) }}
        icon: >
          mdi:moon-{{ states('sensor.moon_phase').replace('_', '-').replace('-moon', '') }}

NOTE

In the future, it may not be necessary to create a Template Sensor to translate the Moon sensor (sensor.moon_phase). What is missing is for someone to translate the English moon phases into Swedish and submit it to Home Assistant’s translation tables.

For more information refer to the following:

2 Likes

Thanks for your support 
 it works like a Swiss clock

2 Likes

You’re welcome!

Please consider marking my post above with the Solution tag. It will automatically place a check-mark next to the topic’s title which signals to other users that this topic has been resolved. This helps users find answers to similar questions.

For more information about the Solution tag, refer to guideline 21 in the FAQ.