Is there a way to have the moon platform show as an icon? It currently shows as a badge with text in the circle providing the phase it is in. I would prefer an icon representing the phase like the sun platform.
My setup:
sensor:
- platform: moon
Is there a way to have the moon platform show as an icon? It currently shows as a badge with text in the circle providing the phase it is in. I would prefer an icon representing the phase like the sun platform.
My setup:
sensor:
Put it in a group and it will appear on a card with an icon.
group:
moon:
name: Moon
entities:
- sensor.moon
Ah, that worked. Thanks!
Looking at the code, it appears to support 8 phase states:
@property
def state(self):
"""Return the state of the device."""
if self._state == 0:
return 'New moon'
elif self._state < 7:
return 'Waxing crescent'
elif self._state == 7:
return 'First quarter'
elif self._state < 14:
return 'Waxing gibbous'
elif self._state == 14:
return 'Full moon'
elif self._state < 21:
return 'Waning gibbous'
elif self._state == 21:
return 'Last quarter'
else:
return 'Waning crescent'
I just found a set of eight moon phase icons; would be cool to use the icon template property to set the icon on the card to matchâŚ
^that would be better, Iâm surprised it doesnât already. I think Sun does. Maybe fire off the icons to whoever wrote the moon component?
I think that was @fabaff - but heâs a busy busy guy. Iâm going to take a look at doing this from a template perspective but itâs going to take me a bit of time.
Look forward to seeing what you come up with. I guess if it works well then we can leave the component as is and just update the component configuration page with a suggestion.
#LabourSaving
The proper way to do it would be to extent the frontend.
I have added a feature request for this, if anyone is interested in posting their vote in favor of it: https://community.home-assistant.io/t/moon-sensor-more-information/
I finished my template sensor with moon phase pictures, based on the sensor.moon, this evening.
Have to test out two automations hiding and displaying the sensor when sunrise and sunsett.
Ill post the code after testing for a couple of days.
Here is the sensor code for displaying lunar phases.
Create this folder structure and use your own icons or pictures. Attached are pictures for the northern hemisphere.
platform: moon
platform: template
sensors:
moonphases:
entity_id: sensor.moon
friendly_name: âMoonâ
value_template: â{{ states.sensor.moon.state }}â
entity_picture_template: >-
{% if is_state(âsensor.moonâ, âNew moonâ) %}
/local/MoonPhases/NNewMoon.jpg
{% elif is_state(âsensor.moonâ, âWaxing crescentâ) %}
/local/MoonPhases/NWaxingCrescent.jpg
{% elif is_state(âsensor.moonâ, âFirst quarterâ) %}
/local/MoonPhases/NFirstQuarter.jpg
{% elif is_state(âsensor.moonâ, âWaxing gibbousâ) %}
/local/MoonPhases/NWaxingGibbous.jpg
{% elif is_state(âsensor.moonâ, âFull moonâ) %}
/local/MoonPhases/NFullMoon.jpg
{% elif is_state(âsensor.moonâ, âWaning gibbousâ) %}
/local/MoonPhases/NWaningGibbous.jpg
{% elif is_state(âsensor.moonâ, âLast quarterâ) %}
/local/MoonPhases/NLastQuarter.jpg
{% elif is_state(âsensor.moonâ, âWaning crescentâ) %}
/local/MoonPhases/NWaningCrescent.jpg
{% endif %}
If you want the moon sensor do disappear when the sun is up, and display when the sun is under the horizon, use this code, with the following addon.
in your customize.yaml add:
###################################################
MOON PHASES GUI DISPLAY/HIDE
###################################################
sensor.moonphases:
templates:
hidden: âreturn (entities[âsun.sunâ].state === âabove_horizonâ);â
And use the add on CustomUI
This is fantastic you reckon you can package this all into a zip file?
Thank you very much. Your pic is so nice and clean ^^
Thanks, working great.
Some issues I had to fix:
Im trying to set this up, and i see some errors, i tried what youâve mentioned about indents and quotes, getting this error on running config check , im not able to find the error causing syntax issue.
Configuration invalid
Invalid config for [sensor.template]: invalid template (TemplateSyntaxError: unexpected char âââ at 15) for dictionary value @ data[âsensorsâ][âmoonphasesâ][âentity_picture_templateâ]. Got '{% if is_state(âsensor.moonâ, âNew moonâ) %} /local/MoonPhases/NNewMoon.jpg {% elif is_state(âsensor.moonâ, âWaxing crescentâ) %} /local/MoonPhases/NWaxingCrescent.jpg {% elif is_state(âsensor.moonâ, âFirst quarterâ) %} /local/MoonPhases/NFirstQuarter.jpg {% elif is_state(âsensor.moonâ, âWaxing gibbousâ) %} /local/MoonPhases/NWaxingGibbous.jpg {% elif is_state(âsensor.moonâ, âFull moonâ) %} /local/MoonPhases/NFullMoon.jpg {% elif is_state(âsensor.moonâ, âWaning gibbousâ) %} /local/MoonPhases⌠(See ?, line ?). Please check the docs at Template - Home Assistant
- platform: template
sensors:
moonphases:
entity_id: sensor.moon
friendly_name: 'Moon'
value_template: '{ states.sensor.moon.state }'
entity_picture_template: >
{% if is_state(âsensor.moonâ, âNew moonâ) %}
/local/MoonPhases/NNewMoon.jpg
{% elif is_state(âsensor.moonâ, âWaxing crescentâ) %}
/local/MoonPhases/NWaxingCrescent.jpg
{% elif is_state(âsensor.moonâ, âFirst quarterâ) %}
/local/MoonPhases/NFirstQuarter.jpg
{% elif is_state(âsensor.moonâ, âWaxing gibbousâ) %}
/local/MoonPhases/NWaxingGibbous.jpg
{% elif is_state(âsensor.moonâ, âFull moonâ) %}
/local/MoonPhases/NFullMoon.jpg
{% elif is_state(âsensor.moonâ, âWaning gibbousâ) %}
/local/MoonPhases/NWaningGibbous.jpg
{% elif is_state(âsensor.moonâ, âLast quarterâ) %}
/local/MoonPhases/NLastQuarter.jpg
{% elif is_state(âsensor.moonâ, âWaning crescentâ) %}
/local/MoonPhases/NWaningCrescent.jpg
{% endif %}
Figured it out, thanks to you all!
The single quotes around your if test statements are the wrong kind. Look closely at them and compare them to the single quotes around the value_template expression.
Can you quote the correct template?
Ok thanks, but due to my poor english what are fancy sloped single quotes and vertical one?