rpitera
(Robert Pitera)
June 8, 2017, 2:52pm
4
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…
1 Like
^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?
rpitera
(Robert Pitera)
June 8, 2017, 3:02pm
6
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
fabaff
(Fabian Affolter)
June 8, 2017, 3:37pm
8
The proper way to do it would be to extent the frontend.
Erlend
March 9, 2018, 12:33pm
9
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.
1 Like
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
I have two sensors. One sensor can get on of two values, “true” or “false”.
How to dynamically hide/display the other sensor in the GUI, set hidden: to true or false?
sensor.moon:
hidden: {{ states.sensor.moonphases_gui_hide.state }} -> Gives Config Error
hidden: “{{ states.sensor.moonphases_gui_hide.state }}” -> Does not work
hidden: ‘{{ states.sensor.moonphases_gui_hide.state }}’ -> Does not work
I am a bit baffled that Hassio only have code statement for hiding groups. What about…
3 Likes
eugenelai
(Eugenelai)
March 21, 2018, 8:43am
12
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 ^^
Mike_R
(Mike Rosseel)
May 18, 2018, 1:09pm
15
Thanks, working great.
Some issues I had to fix:
indentation is wrong, moonphases is indented, and entity_id is indented under maanphases
all quotes should be replaced to ‘normal’ quotes, not fancy quotes
the entity_picture_template should have a ‘>’, not a ‘>-’ (not sure if this needs to be changed)
remember to copy the MoonPhases directory under your config/www directory
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!
tom_l
May 19, 2018, 3:58pm
18
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.
1 Like
maurizio53
(Maurizio Fabiani)
May 19, 2018, 4:14pm
19
Can you quote the correct template?
maurizio53
(Maurizio Fabiani)
May 19, 2018, 4:20pm
21
Ok thanks, but due to my poor english what are fancy sloped single quotes and vertical one?
Thanks a bunch Tom, that fixed it, i ought to pay more attention to details.
For the rest, i have corrected below.
- 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 %}
EDIT: i missed the double {{ }} on the value template, corrected now.
5 Likes