After adding the above component & grouping the same I see the status of the moon as follows:
Question:
**I want to display a card in Home Automation Panel which says something like ** "XX Days to Full Moon This Month" "XX Days to New Moon This Month"
How do I achieve it? Please help with sample code.
I use REST to pull the data from the US Naval Observatory API into a group of sensors, then the days until a particular phase can be found with a template. I have no idea whether the REST API will be available to users outside the US.
rest:
- authentication: basic
scan_interval: 5400
resource_template: |-
https://aa.usno.navy.mil/api/moon/phases/date?date={{now().date()|string}}&nump=4
sensor:
- name: "Next Moon Phase Date"
unique_id: next_moon_phase_date_0001
value_template: |
{% set x = value_json.phasedata[0] %}
{{x.year}}-{{x.month if x.month > 9 else '0'~x.month|string}}-{{x.day if x.day > 9 else '0'~x.day|string}}
json_attributes_path: "$.phasedata[0]"
json_attributes:
- "phase"
- "time"
- name: "Next but One Moon Phase Date"
unique_id: next_1_moon_phase_date_0001
value_template: |
{% set x = value_json.phasedata[1] %}
{{x.year}}-{{x.month if x.month > 9 else '0'~x.month|string}}-{{x.day if x.day > 9 else '0'~x.day|string}}
json_attributes_path: "$.phasedata[1]"
json_attributes:
- "phase"
- "time"
- name: "Next but Two Moon Phase Date"
unique_id: next_2_moon_phase_date_0001
value_template: |
{% set x = value_json.phasedata[2] %}
{{x.year}}-{{x.month if x.month > 9 else '0'~x.month|string}}-{{x.day if x.day > 9 else '0'~x.day|string}}
json_attributes_path: "$.phasedata[2]"
json_attributes:
- "phase"
- "time"
- name: "Next but Three Moon Phase Date"
unique_id: next_3_moon_phase_date_0001
value_template: |
{% set x = value_json.phasedata[3] %}
{{x.year}}-{{x.month if x.month > 9 else '0'~x.month|string}}-{{x.day if x.day > 9 else '0'~x.day|string}}
json_attributes_path: "$.phasedata[3]"
json_attributes:
- "phase"
- "time"
template:
- sensor:
- name: Days Until Full Moon
unit_of_measurement: days
state: >
{% set s_list = ['sensor.next_but_three_moon_phase_date','sensor.next_but_two_moon_phase_date',
'sensor.next_but_one_moon_phase_date','sensor.next_moon_phase_date'] %}
{% set next_full = expand(s_list) | selectattr('attributes.phase', 'eq', 'Full Moon')
| map(attribute='state') | join | as_datetime | as_local %}
{{ (next_full - today_at()).days }}
I found a website that appears to work for the whole world:
When you select a location the Next New Moon and Next Full Moon are shown in a table on the left.
When the URL is extended with the correct latitude, longtitude and current date and time it immediately returns the correct moon data.
So I have been trying to create a Scrape sensor to collect these date time values, but did not succeed up to now.
This is what I have now (for Paris):
scrape:
- resource: https://www.mooncalc.org/#/48.8583,2.2945,17/2023.09.20/10:10/1/2
sensor:
- name: Next full moon
select: "span.moontext.vollmond"
But it returns three dots …
Can someone with better Scrape skills have go with this?