The moon integration

does anyone know an integration that gives me not only the moon phases but also rise and set times, location in the sky (alt/az), illumination (%) and so on? the integration i have installed only gives me the phases :frowning:

Can I ask what automation you’re planning for this? I’m genuinely curious. I’ve never really heard of someone automating something based on the position of the moon in the sky before

I bet 5 bucks on something with werewolves!

I’m with you. Notification to get to your cage and shackles an hour before the moon rises when full.

This has moon rise and set sensors:

1 Like

At astronomical dusk I check to see if the moon is down and the seeing (air transparency/stability/cloud cover) is good. If so I send an alert telling me that conditions are good to get my telescope out for some deep sky viewing.

This automation has not triggered for months :frowning:

3 Likes

check out the ipgeolocation astronomy-api: IP Geolocation API Astronomy API

I have a rest sensor and template sensors to extract the info. You can sign up for a free account and make api calls for free. I don’t think it has illumination % but has a number of other values.

The other day I came across something on github that should do the trick. Problem is, now I can’t find it. All I remember is that it was a library written in JavaScript, it could give me the moon data I want, and it was a part of a project.

Please share your code, want to try this out.

Sure, the following is my setup (with some info redacted)

I have a line in my secrets.yaml file like the following:

ipgeolocation_astronomy_resource: https://api.ipgeolocation.io/astronomy?apiKey=<apikey_goes_here>&lat=<latitude_goes_here>&long=<longitude_goes_here>

I have an astronomy.yaml file with the following content:

---
  # The Astronomy API provides the location-based rise and set times 
  # for the Sun and Moon along with the current position, distance from 
  # earth, and azimuth of the Sun and the Moon for a specific date
  # at the queried time.
  #
  # https://ipgeolocation.io/documentation/astronomy-api.html
  
  platform: rest
  scan_interval: 900
  resource: !secret ipgeolocation_astronomy_resource
  name: astronomy_api
  value_template: >
    {{ value_json.moonrise }}
  json_attributes:
    - date
    - current_time
    - sunrise
    - sunset
    - solar_noon
    - day_length
    - sun_altitude
    - sun_distance
    - sun_azimuth
    - moonrise
    - moonset
    - moon_altitude
    - moon_distance
    - moon_azimuth
    - moon_parallactic_angle
  
  

I have an astronomy_template.yaml file with the following content:

---
  # The Astronomy API provides the location-based rise and set times 
  # for the Sun and Moon along with the current position, distance from 
  # earth, and azimuth of the Sun and the Moon for a specific date
  # at the queried time.
  #
  # https://ipgeolocation.io/documentation/astronomy-api.html

  platform: template
  sensors:
    astronomy_moon_moonrise:
      friendly_name: "Moonrise"
      value_template: >-
        {{ state_attr('sensor.astronomy_api', 'moonrise') }}

    astronomy_moon_moonset:
      friendly_name: "Moonset"
      value_template: >-
        {{ state_attr('sensor.astronomy_api', 'moonset') }}
  
    astronomy_moon_altitude:
      friendly_name: "Moon Altitude"
      unit_of_measurement: "degrees"
      value_template: >-
        {{ state_attr('sensor.astronomy_api', 'moon_altitude') }}
      
    astronomy_moon_distance:
      friendly_name: "Moon Distance"
      unit_of_measurement: "km"
      value_template: >-
        {{ state_attr('sensor.astronomy_api', 'moon_distance') }}
  
    astronomy_moon_azimuth:
      friendly_name: "Moon Azimuth"
      unit_of_measurement: "degrees"
      value_template: >-
        {{ state_attr('sensor.astronomy_api', 'moon_azimuth') }}
      
    astronomy_moon_parallactic_angle:
      friendly_name: "Moon Parallactic Angle"
      unit_of_measurement: "degrees"
      value_template: >-
        {{ state_attr('sensor.astronomy_api', 'moon_parallactic_angle') }}
        
    astronomy_sun_sunrise:
      friendly_name: "Sunrise"
      value_template: >-
        {{ state_attr('sensor.astronomy_api', 'sunrise') }}

    astronomy_sun_sunset:
      friendly_name: "Sunset"
      value_template: >-
        {{ state_attr('sensor.astronomy_api', 'sunset') }}
  
    astronomy_sun_solar_noon:
      friendly_name: "Solar Noon"
      value_template: >-
        {{ state_attr('sensor.astronomy_api', 'solar_noon') }}
      
    astronomy_sun_day_length:
      friendly_name: "Day Length"
      value_template: >-
        {{ state_attr('sensor.astronomy_api', 'day_length') }}
  
    astronomy_sun_azimuth:
      friendly_name: "Sun Azimuth"
      unit_of_measurement: "degrees"
      value_template: >-
        {{ state_attr('sensor.astronomy_api', 'sun_azimuth') }}
      
    astronomy_sun_altitude:
      friendly_name: "Sun Altitude"
      unit_of_measurement: "degrees"
      value_template: >-
        {{ state_attr('sensor.astronomy_api', 'sun_altitude') }}

    astronomy_sun_distance:
      friendly_name: "Sun Distance"
      unit_of_measurement: "km"
      value_template: >-
        {{ state_attr('sensor.astronomy_api', 'sun_distance') }}
  

So a REST call is made every 15 minutes (max 96 times a day) and the template sensors are used to pull the individual data out. Works fine for me. You will need to sign up for the developer account with free access for up to 1K queries a day and 30k queries a month. Generate an API key with their developer dashboard and specify your longitude and latitude values. I just use one secret to hold the entire API call.

Hope this helps.

5 Likes

Hi all,

does anyone know, if you can also request the data for a specifig date and time? e.g. the azimute and altitude for the date: “2024-12-24” at “22:00”? How is the syntax of the api-call to ipgeolocation?
Spartacus