🌘 Lunar Phase Integration for Home Assistant

@VietNgoc
thanks for letting me know that you’re aware of this bug/challenge. And I agree with @RickFurtado, building reliable automations require reliable sensors.

What do you think about create a service or action (since 2024.10) to reload the integration. We could schedule a regular reload and the sensors are updated, at least once a night.

You can definitely set up automation for reload integration, that will be the best option until I come up with a solution. :sweat_smile:

the command to reload the integration

action: homeassistant.reload_config_entry
data: {}
target:
  device_id: d64f95437572d8e12d2e92ea32b8dafc

you can get the device id from the integration url, or use template in automation, replace entity id with your sensor id

target:
  device_id: "{{ device_id('sensor.prague_moon_phase') }}" 

That’s what I did until/if there’s a resolution. Thank you for your attention to this @VietNgoc.

I do the same.
thanks @VietNgoc

Anyone else using this in the US? I’m using America/Denver time zone and Next Full Moon appears off by 1 day (11 and a half hours). According to Google Calendar Next Full Moon is 11/15 2:29pm, lunar phase integration says 11/16 1:58am

v1.6.0


New Features :tada:

The graph displays the altitude of the Moon throughout the day. It also includes moon phase information and moon rise/set times.
2024-10-26 04 14 59
If you enjoy these new features, consider giving the repo a :star: to show your support! :rocket:
Full Changelog: Comparing v1.5.0...v1.6.0 · ngocjohn/lunar-phase-card · GitHub

3 Likes

Same here in Europe, Zurich.
In integration next full moon is set for Nov 16, 8.58 am. But timeanddate.com as few other full moon calendars have next full moon already 10 hours earlier. Nov 15, 22.28 pm.

Same, Lunar Phase is late on the next full moon by 16.5 hours for me both in the card and the entity state.

@VietNgoc I love the concept of this integration, but I think you need to focus on functionality and accuracy before fancy new features. The new moon-to-horizen graph is cool and all that, but there’s no accesible data. And quite frankly considering other inconsistancies I won’t trust its accuracy. I’ll keep the integration for a bit in hopes that these issues can be resolved, but it’s not going to last if all it is is pretty and cool.

I appreciate your work on this and remain hopeful.

Hi @RickFurtado , the card is not using data from the integration. There I claim it is without problem. I’m still working on the integration bug. :weary: :smiling_face_with_tear:

Hi! Cool project, thank you!
Would like to print the next fullmoon on an oled display. How should I create the sensor in yaml (platform?)? I searched the suggestions from the code-editor but didn’t find anything moon-related :slight_smile: . Thanks for your help and best regards!

My lunar phase integration creates a sensor called sensor.christchurch_next_full_moon (Christchurch is my location). It contains the date and time of the next full moon.

How are you setting up your OLED? Assuming it is esphome.

If so you can import that sensor into esphome with Home Assistant Sensor — ESPHome

1 Like

Hey - thanks a lot for your reply! I think that’s more or less what I’ve tried yesterday, but currently the sensor seems not to receive any data.

Code for the sensor:

  - platform: homeassistant
    entity_id: sensor.schafisheim_next_full_moon
    id: next_fullmoon
    name: "Next FullMoon"

And for the oled:

if (id(next_fullmoon).has_state()) {
        it.printf(64,63, id(font1), TextAlign::BOTTOM_CENTER , "%d.%B %Y", id(next_fullmoon).state);

my sensor:
sensor.schafisheim_next_full_moon

I’ve not tried to used entity-id instead of entity, but as far as I understood both should be possible. Will try anyway…

I wasn’t sure about the “platform” I should reference to and therefore tried “homeassistant”. Do you think this is correct or do you maybe see another mistake I made?
I can successfully print time, date, temperature, humidity and WiFi-status to this display, communication seems to work fine.
Thanks you and best regards!

Could you please let me know what you see in the esphome log regarding this?

I think on reflection that you need to import it as a text sensor

I changed my code to a text_sensor:

text_sensor:
  - platform: homeassistant
    entity_id: sensor.schafisheim_next_full_moon
    id: next_fullmoon
    name: "Next FullMoon"

This is what the display is currently showing (left display, bottom line)

I checked the logs on the device-api, the sensor is not mentioned there. The only thing I could find about lunar-phases is in the core-log:

Logger: homeassistant.helpers.frame
Source: helpers/frame.py:189
First occurred: November 13, 2024 at 7:46:38 PM (1 occurrences)
Last logged: November 13, 2024 at 7:46:38 PM

Detected that custom integration 'lunar_phase' calls async_forward_entry_setup for integration, lunar_phase with title: Schafisheim and entry_id: 01JCKDJP373R9GH0Z0DKZ1J1TC, which is deprecated and will stop working in Home Assistant 2025.6, await async_forward_entry_setups instead at custom_components/lunar_phase/__init__.py, line 50: await hass.config_entries.async_forward_entry_setup(config_entry, "sensor"), please create a bug report at https://github.com/ngocjohn/lunar-phase/issues

And after installing the new code, the device seems to have connection-issues. When I start the log-output in esphome it takes longer to connect to the device and after a few seconds the connection breaks. Submitting sensor-values seems to work fine so far.

Do you think the sensor-syntax should work like that? Is there another place to search logs?
Thanks for your help and have a great day - cheers!

Sorry mate, I have no idea how ESP Home works. But the sensor has a timestamp class. Isn’t there any way to calculate the state to the normal date in esphome?

something like this?

edit:
After a quick look at how esphome works, I thought you could create a new sensor using the helper that only shows the state from integration as ‘text’. So you can then simply import it into esphome as a normal text sensor.

Thanks a lot for your time and help! And not a very used coder, I’m learning day by day.
What I don’t understand: why do I need this helper-sensor? Is it not possible to use the sensor lunar-phases creates?
I’ve found this
Publish timestamp into text_sensor - ESPHome - Home Assistant Community

and therefore tried the following - without success so far:

text_sensor:
  - platform: homeassistant
    entity_id: sensor.schafisheim_next_full_moon
    id: next_fullmoon
    name: "Next FullMoon"
    device_class: timestamp 

I still guess that platform is wrong.
However, I’m not really used with templates. Thanks to your screenshot I managed to create the sensor, now I’ll try to get the string to my display.
Will report progress, thank you very much!

I find dates and times very bloody confusing.

This

text_sensor
  - platform: homeassistant
    entity_id: sensor.christchurch_next_full_moon
    id: nfm 
    name: "Next Full Moon"

does get the date and time into esphome. You can see it in the esphome log

'sensor.christchurch_next_full_moon': Got state '2024-11-16T08:58:14+00:00'
[23:20:26][D][text_sensor:064]: 'Next Full Moon': Sending state '2024-11-16T08:58:14+00:00'

By the way, your log is not the esphome log, it is the HA log.

Because HA uses datime object. above are examples how to convert to local or custom format via template. Then you can use in esp as ‘text’

1 Like

Hey guys
thanks a lot for your help, I finally got it sorted! And I learned a lot about using the template-editor for testing and importing sensors to my ESP32-configs. I managed to import a binary sensor myself which feels like I climbed the Mount Everest :slight_smile:
For some reason before esphome didn’t know anything about the imported textsensor. After restarting from scratch I could reproduce nickrout’s results. I then started to understand what a text-sensor delivers and that the string-output from sensor.schafisheim_next_full_moon is too long for my display. From this point I was able to follow VietNgoc’s explanations and to format the string as desired. Thank you so much guys, huge learning to the weekend start! :sunglasses:

3 Likes

That looks cool, I think I’ll try to create something with esp. I’ve got some boards lying around :smiley: Thanks for inspiration :love_you_gesture: