NASA API and other Space integrations

Hi all,

Slight update on my nasa.yaml file. Today Astronomical Picture of the Day is a Video and the original Markdown Card didn’t show the image/video.

Also I was not happy on how was the sensor calling the API, beacuse the token was not as secret as I liked. Now I don’t need input_text and the token is kept secret in my secrets.yaml file.

The code now is as simple as this:

###
# NASA API collection
#
# Get API Token at: https://api.nasa.gov/index.html
###

# API APOD: NASA Astronomical Picture of the Day
sensor:
  - platform: rest
    resource: https://api.nasa.gov/planetary/apod
    name: nasa_apod
    value_template: "OK"
    params:
      api_key: !secret nasa_api_key
      thumbs: true
    json_attributes:
      - date
      - title
      - explanation
      - url
      - thumbnail_url
      - media_type

homeassistant:
  customize:
    sensor.nasa_apod:
      friendly_name: Astronomical Picture of the Day
      icon: mdi:image
  
###
# Clear recorder
###

recorder:
  exclude:
    entities:
      - sensor.nasa_apod

The card is now like this:

type: markdown
content: |
  ## {{ states.sensor.nasa_apod.attributes.title }} 
  _{{ states.sensor.nasa_apod.attributes.date }}_ 
  {%- if (states.sensor.nasa_apod.attributes.media_type == "video") %} 
    [![Image]({{ states.sensor.nasa_apod.attributes.thumbnail_url }})]({{ states.sensor.nasa_apod.attributes.url }}&autoplay=1&loop=1) 
  {%- else -%} 
    ![Image]({{ states.sensor.nasa_apod.attributes.url }})
  {% endif -%} 
  {{ states.sensor.nasa_apod.attributes.explanation }}

Now if media_type is “video” it then shows a thumbnail (included in the API). If it’s not a video and shows the original url.

If its a video it will open a new browser windows if you click the image (I really don’t like this, but I’m not yet an expert in card creation)