Code Monkey home page Code Monkey logo

ha_skyfield's Introduction

Live Sun, Moon, and Planets for Home Assistant

hacs_badge

This is a custom component for Home Assistant that makes a live polar sun path chart for your location. Besides the Sun, it also shows the Moon and a few major planets. Plus, it shows the Winter and Summer solstice sun paths so you can see where you are in the seasons!

Screenshot of the skyfield

This uses the skyfield library to do the computations.

To use:

  • Install this in your custom_components folder
  • Download the prerequisites: pip3 install skyfield matplotlib numpy (no longer necessary with hassio!)
  • Add the following to your home assistant config:
camera:
    platform: ha_skyfield
    show_constellations: false
  • Add a picture entity to your GUI with this camera. It will update live.

Optional configuration:

  • show_time add a timestamp to the plot
  • show_legend add a legend of the bodies
  • show_constellations enable or disable the constellations (default is True).
  • planet_list customize which planets are shown
  • constellations_list customize which constellations are shown (use names from here)
  • north_up (boolean) puts North at the top (useful in the Southern Hemisphere)
  • horizontal_flip (boolean) flips projection horizontally
  • image_type (string) Optional - provide image format extension. Tested options are png (default) and jpg.

Known Issues:

  • WARNING: High CPU usage! The underlying library is relatively long-running. Disable or limit constellations if you're using a smaller computer, like a Raspberry Pi. Even with them off, the CPU load may unacceptable. Options and more discussion in #4

  • Does not follow Theme because of matplotlib backend (see #5

  • More (maybe) at Issues

Inspiration comes from the University of Oregon Solar Radiation Monitoring Lab.

ha_skyfield's People

Contributors

bouwew avatar k3wio avatar linuxkidd avatar partofthething avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ha_skyfield's Issues

Option to Flip projection left to right

  • While lying on the ground with your head toward North and feet toward South, East is to your left, and West is to your right.
  • This is commonly the orientation of AllSky cameras as well.
  • Request making an option to Flip the projection to match this view.
  • Turns out, it's super easy to change:

Suggest changing:

ax.set_theta_direction(-1)

to

ax.set_theta_direction(1)

On line 170 in bodies.py

Get planet positions as sensors

Since this integration is already calculating the positions of the planets, it would be nice to have it provide sensors for the:

  • current visibility
  • current direction
  • current altitude
  • today's and next rise times and directions
  • today's and next meridian times and directions, and
  • today's and next set times and directions

of each planet, dwarf planet, the sun, and the moon.

An example would be something like this: https://www.timeanddate.com/astronomy/night/usa/new-york

Planet Information

Can't rotate image for my real nort positon..

I need some HELP, please!!! :(
How to rotate the position of the N to the E, like in this pic?
image

my config in cameras.yaml

 - platform: ha_skyfield
   show_constellations: false
   north_up: true
   show_time: true
   show_legend: true
#   planet_list: true

constellation issue : AttributeError: 'Sky' object has no attribute '_constellation_names'

I'm not able to use constellation

I set this configuration :

camera:
    platform: ha_skyfield
    show_constellations: true
    constellations_list:
        - UrsaMajor
        - Andromeda
        - Aquarius
        - Aquila
        - Ara
        - Aries
        - Auriga
        - Cancer
        - Capricornus
        - Carina
        - Cassiopeia
        - Centaurus
        - Circinus
        - Cygnus
        - Lynx
        - Lyra
        - Orion
        - Pegasus
        - Sagitta
        - Sagittarius
        - Scorpius
        - Taurus
        - Vela
        - Virgo

it's display moon and other Planets but it's not displaying any constellation

after putting the extension in debug mode, i saw this crash :

mai 17 11:59:57 rasp hass[14720]: 2022-05-17 11:59:57 ERROR (MainThread) [aiohttp.server] Error handling request
mai 17 11:59:57 rasp hass[14720]: Traceback (most recent call last):
mai 17 11:59:57 rasp hass[14720]:   File "/data/homeassistant/lib/python3.10/site-packages/aiohttp/web_protocol.py", line 435, in _handle_request
mai 17 11:59:57 rasp hass[14720]:     resp = await request_handler(request)
mai 17 11:59:57 rasp hass[14720]:   File "/data/homeassistant/lib/python3.10/site-packages/aiohttp/web_app.py", line 504, in _handle
mai 17 11:59:57 rasp hass[14720]:     resp = await handler(request)
mai 17 11:59:57 rasp hass[14720]:   File "/data/homeassistant/lib/python3.10/site-packages/aiohttp/web_middlewares.py", line 117, in impl
mai 17 11:59:57 rasp hass[14720]:     return await handler(request)
mai 17 11:59:57 rasp hass[14720]:   File "/data/homeassistant/lib/python3.10/site-packages/homeassistant/components/http/security_filter.py", line 60, in security_filter_middleware
mai 17 11:59:57 rasp hass[14720]:     return await handler(request)
mai 17 11:59:57 rasp hass[14720]:   File "/data/homeassistant/lib/python3.10/site-packages/homeassistant/components/http/forwarded.py", line 222, in forwarded_middleware
mai 17 11:59:57 rasp hass[14720]:     return await handler(request)
mai 17 11:59:57 rasp hass[14720]:   File "/data/homeassistant/lib/python3.10/site-packages/homeassistant/components/http/request_context.py", line 28, in request_context_middleware
mai 17 11:59:57 rasp hass[14720]:     return await handler(request)
mai 17 11:59:57 rasp hass[14720]:   File "/data/homeassistant/lib/python3.10/site-packages/homeassistant/components/http/auth.py", line 219, in auth_middleware
mai 17 11:59:57 rasp hass[14720]:     return await handler(request)
mai 17 11:59:57 rasp hass[14720]:   File "/data/homeassistant/lib/python3.10/site-packages/homeassistant/components/http/view.py", line 137, in handle
mai 17 11:59:57 rasp hass[14720]:     result = await result
mai 17 11:59:57 rasp hass[14720]:   File "/data/homeassistant/lib/python3.10/site-packages/homeassistant/components/camera/__init__.py", line 736, in get
mai 17 11:59:57 rasp hass[14720]:     return await self.handle(request, camera)
mai 17 11:59:57 rasp hass[14720]:   File "/data/homeassistant/lib/python3.10/site-packages/homeassistant/components/camera/__init__.py", line 754, in handle
mai 17 11:59:57 rasp hass[14720]:     image = await _async_get_image(
mai 17 11:59:57 rasp hass[14720]:   File "/data/homeassistant/lib/python3.10/site-packages/homeassistant/components/camera/__init__.py", line 174, in _async_get_image
mai 17 11:59:57 rasp hass[14720]:     if image_bytes := await camera.async_camera_image(
mai 17 11:59:57 rasp hass[14720]:   File "/data/homeassistant/lib/python3.10/site-packages/homeassistant/components/camera/__init__.py", line 581, in async_camera_image
mai 17 11:59:57 rasp hass[14720]:     return await self.hass.async_add_executor_job(
mai 17 11:59:57 rasp hass[14720]:   File "/usr/local/lib/python3.10/concurrent/futures/thread.py", line 58, in run
mai 17 11:59:57 rasp hass[14720]:     result = self.fn(*self.args, **self.kwargs)
mai 17 11:59:57 rasp hass[14720]:   File "/data/homeassistant/.homeassistant/custom_components/ha_skyfield/camera.py", line 145, in camera_image
mai 17 11:59:57 rasp hass[14720]:     self.sky.load(self._tmpdir)
mai 17 11:59:57 rasp hass[14720]:   File "/data/homeassistant/.homeassistant/custom_components/ha_skyfield/bodies.py", line 75, in load
mai 17 11:59:57 rasp hass[14720]:     self._run_initial_computations()
mai 17 11:59:57 rasp hass[14720]:   File "/data/homeassistant/.homeassistant/custom_components/ha_skyfield/bodies.py", line 94, in _run_initial_computations
mai 17 11:59:57 rasp hass[14720]:     self, self._constellation_names
mai 17 11:59:57 rasp hass[14720]: AttributeError: 'Sky' object has no attribute '_constellation_names'

It's running on a Rasberry Pi 4 on Debian 10 armv7l

CPU Usage 100% with Home Assistant 2022.10.2

With the new version 2022.10.2, Home Assistant is unusable if ha_skyfield is installed as the cpu usage is always 100%. (even without open a dashboard with ha_skyfield .

Previous version (2022.9.7), it's was working as expected.

Attached file is a record of py-spy of home-assistant pid
profile

Breaks on Home assistant 2022.04 with width issue

I got a report from a user with this traceback:

Logger: aiohttp.server
Source: components/camera/__init__.py:569
First occurred: April 25, 2022, 15:42:00 (113 occurrences)
Last logged: 20:17:32

Error handling request
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/aiohttp/web_protocol.py", line 435, in _handle_request
    resp = await request_handler(request)
  File "/usr/local/lib/python3.9/site-packages/aiohttp/web_app.py", line 504, in _handle
    resp = await handler(request)
  File "/usr/local/lib/python3.9/site-packages/aiohttp/web_middlewares.py", line 117, in impl
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/security_filter.py", line 60, in security_filter_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/forwarded.py", line 100, in forwarded_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/request_context.py", line 28, in request_context_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/ban.py", line 79, in ban_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/auth.py", line 219, in auth_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/view.py", line 137, in handle
    result = await result
  File "/usr/src/homeassistant/homeassistant/components/camera/__init__.py", line 724, in get
    return await self.handle(request, camera)
  File "/usr/src/homeassistant/homeassistant/components/camera/__init__.py", line 742, in handle
    image = await _async_get_image(
  File "/usr/src/homeassistant/homeassistant/components/camera/__init__.py", line 163, in _async_get_image
    if image_bytes := await camera.async_camera_image(
  File "/usr/src/homeassistant/homeassistant/components/camera/__init__.py", line 569, in async_camera_image
    return await self.hass.async_add_executor_job(
  File "/usr/local/lib/python3.9/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
TypeError: camera_image() got an unexpected keyword argument 'width'

System Info:

System Health
version: core-2022.4.7
installation_type: Home Assistant OS
dev: false
hassio: true
docker: true
user: root
virtualenv: false
python_version: 3.9.9
os_name: Linux
os_version: 5.10.103-v8
arch: aarch64
timezone: America/Detroit

High CPU usage

This component uses a LOT of CPU, especially when running with constellations (but even without). In profiling, we can see that the python-skyfield library computing positions is a lot of work. Here is the profiler trace with constellations:

prof

We could alternatively make a sun-only mode that uses the alternative library pysolar which would likely be much faster.

Javascript front end

Right now, the system uses matplotlib on the backend to make PNG images to be shown in the browser. This has some disadvantages in backend speed and theme matching.

A version of this with a javascript front-end might be really awesome.

Dark mode

Awesome plugin to HA for us space junkies....
Is there a dark mode picture that can be used for this?

Switch from PNG to JPG to conserve bandwidth

For this project, using PNG doesn't provide valuable visual benefit over a more highly compressed format like JPG.

The bandwidth savings is especially important for remote observatories with limited connectivity options.

-rw-r--r-- 1 root root  47K Jan 19 16:59 skyfield.jpg
-rw-r--r-- 1 root root 111K Jan 19 17:03 skyfield.png

Additionally, jpg compression is generally easier to perform on low power systems like the single board, ARM computers.

Documentation

This is great, just works out of the box. Thank you.

So that dopes like me can add it easily it I leave this note for future visitors: where it says "just add a gui picture", all that means is you add an entity in lovelace and in code view paste the following.
type: picture-entity
entity: camera.skyfield
camera_view: live

In terms of customisation I tried changing to north_up=True in bodies.py but that didn't work so I just hard coded it in camera.py under def setup_platform. (I could comment out planets my eyes can't see in bodies.py though, which may help on the processing load.)

I will watch with eagerness for a fix to the refresh rate so that the burden on the rpi is less.

Thank you again. A really excellent and welcome contribution.

constellations_list how to?

This is a nice one no question.
Since show_constellations: true resulted in heavy load I wanted to see how it might perform if only usra major being allowed as the one and only constellation. I would have continued evaluating if then adding ursa major would work aswell. Since 2-3 constellations surely make it somewhat easier to help around getting the correct location of a planet.
But I didn't manage to get it going. Any configuration help on constallations_list?
TIA

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.