Giter Site home page Giter Site logo

astrolive's Introduction

AstroLive

Connector for the ASCOM Alpaca REST API designed to work with Home Assistant via MQTT.

alt text

The integration with Home Assistant is implemented via MQTT for sensor and camera entities and supports autodiscovery of Home Assistant for the devices.

alt text

AstroLive uses the nice ALPACA client implementation of the OCA Box classes which is used by the Araucaria Project.

Table of Content

How It Works

  • AstroLive connects via the ASCOM Alpaca API to your observatory.
  • For each configured and connected component a MQTT device configuration for sensors and if applicable camera is created below homeassistant/sensor/astrolive/ and homeassistant/camera/astrolive/ respectively.
  • As of now the following components are supported:
    • Telescope
    • Camera
    • Camera via File
    • Focuser
    • Switch
  • These configurations allow MQTT auto discovery in Home Assistant.
  • AstroLive then starts a seperate thread which queries the compenent status interval based according to the configuration and publishes the device state to MQTT.
  • If the component is of the type Camera the last captured FITS image is autostretched, downsized and published as a .jpg. This is the same for Camera via file where AstroLive watches a directory for new FITS images.

Slewing the telescope using the equatorial coordinate system, moving the focuser and some more commands are possible directly from Home Assistant.

AstroLive is designed to run as a container to be deployed on a dedicated host or next to Home Assistant. It does not require any custom integration for Home Assistant since communication is solely via MQTT.

Requirements

  • A windows (mini) pc/notebook controlling your scope
  • ASCOM Platform
  • ASCOMRemote.
  • Container runtime engine (e.g. Docker).
  • MQTT Broker (e.g. Mosquitto).
  • A recent version of Home Assistant with MQTT autodiscovery enabled.

My Personal Setup

To give you an idea how I did setup my observatory together with AstroLive and AstroWeather here's my setup:

  • Hardware
    • Telescope: Skywatcher Esprit 120ED
    • Mount: Skywatcher EQ6-R
    • Camera: QHY268c
    • Guide Camera: QHY5III462c
    • Off Axis Guider: OAG-M
    • Switch: PegasusAstro Ultimate Powerbox v2
    • Focuser: PegasusAstro Focus Cube
    • Mini PC: MeLE Quieter2 8GB 256GB Windows 10 Pro
  • Software:
    • NINA 2.0.0.9001
    • PHD2 2.6.11
    • ASCOM Platform 66
    • EQASCOM V200w
    • QHYCCD Win AllInOne 21.10.23.19
    • IOTLink 2.2.2
    • Polemaster 3.2.8
    • PegasusAstro Unity Platform 1.5.84.12
    • Dropbox

alt text

All off the software is running on the MeLE Quieter2 mini pc which I mounted on top of the scope. I configured NINA to store image files within a dedicated directory which is synced by Dropbox. This directory is then monitored by AstroLive to enable the image processing.

Since NINA does provide it's own drivers to interact with the QHY camera I did not connect the cameras to ASCOMRemote. During my tests with AstroLive I encountered problems while imaging if AstroLive uses the Camera API of ASCOMRemote. I need to investigate this further, but processing the resulting image stored on disk is working nicely for me and lowers the load on the mini pc anyways.

Usage

Ensure to have the ASCOM Platform deployed on your astro imaging server.

Installation and Configuration of ASCOM Remote Server

Download and install the latest version from here: ASCOMRemote

Show instructions

Add the devices you want to use in conjunction of AstroLive. The following screenshot show a connected Focuser, Telescope and Switch.

alt text

You need to press [Setup] for each configured device to connect it to the ASCOM Remote Server Configuration.

alt text

Set a name for the servers location (e.g. Backyard) and specify the Server IP Address. This is the IP the Remote Server is running on. Choose a port (default is 11111) and leave the rest to the defaults.

alt text

Press [OK]

Links:

Get and Configure AstroLive

Clone AstroLive

git clone https://github.com/mawinkler/astrolive

Now, create a default.cfg.yaml based on the supplied default.cfg.yaml.sample and modify it to your needs. The yaml should be pretty self explanatory :-)

cp astrolive/default.cfg.yaml.sample astrolive/default.cfg.yaml

Note: If you are using drivers provided with the sequencer software, using ASCOM remote in parallel will mess up the imaging session when accessing the camera API. Tested with QHY and N.I.N.A./PHD2. For that reason, I'm always using the camera_file component witch checks for the latest FITS-file published within a given directory tree.

Show YAML
default:
  include: backyard

backyard:
  observatory:
    # Name of the observatory
    comment: Backyard Scope
    # Longitude
    lon: <LONGITUDE>
    # Lattitude
    lat: <LATTITUDE>
    # Elevation
    elev: <ELEVATION>
    # Communication protocol
    protocol: alpaca
    # Address of the ASCOM Remote server
    address: http://<IP OF ASCOMRemote>:11111/api/v1

    components:
      telescope:
        # Kind of the device
        kind: telescope
        comment: <NAME OF YOUR SCOPE>
        # Device number as configured in ASCOM Remote
        device_number: 0
        # Name prefix of the created sensor in MQTT
        friendly_name: <NAME OF YOUR SCOPE>
        # Update interval in seconds
        update_interval: 15
        # List of components belonging to the telescope
        components:
          # Note to ASCOM:
          # If you are using drivers provided with the sequencer software,
          # using ASCOM remote in parallel will mess up the imaging session.
          # Tested with QHY and N.I.N.A./PHD2.
          
          # Valid device kinds are
          #   telescope: Telescope
          #   dome: Dome (NYI)
          #   camera: Camera
          #   filterwheel: Filter Wheel (NYI)
          #   focuser: Focuser
          #   rotator: Rotator (NYI)
          #   switch: Switch
          #   safetymonitor: SafetyMonitor (NYI)
          #   camera_file: Camera File, reads and processes the latest image within
          #     from a configured location.

          # camera:
          #   # Kind of the device
          #   kind: camera
          #   # Device number as configured in ASCOM Remote
          #   device_number: 0
          #   # Name prefix of the created sensor in MQTT
          #   friendly_name: <NAME OF YOUR IMAGING CAMERA>
          #   # Get image via ASCOM remote. If false, process sensors only
          #   image: true
          #   # Update interval in seconds
          #   update_interval: 60

          # guiding_camera:
          #   kind: camera
          #   device_number: 1
          #   friendly_name: <NAME OF YOUR GUIDING CAMERA>
          #   image: true
          #   update_interval: 60

          camera_file:
            kind: file
            friendly_name: <NAME OF YOUR IMAGING CAMERA>
            # Monitoring directory for new image files
            # Only FITS files are supported
            monitor: '/fits'
            update_interval: 60

          focuser:
            kind: focuser
            friendly_name: <NAME OF YOUR FOCUSER>
            update_interval: 15

          switch:
            kind: switch
            friendly_name: <NAME OF YOUR SWITCH>
            update_interval: 30

    # MQTT configuration
    mqtt:
      # Address of the MQTT broker
      broker: <IP OF YOUR BROKER>
      # Listen port of the MQTT broker
      # defaut 1883 or 8883 for tls
      port: 1883
      # Client name for astrolive
      client: astrolive
      # Username
      username: ''
      # Password
      password: ''
      # TLS insecure
      tls:
        enabled: False
        insecure: True
        # The certification authority certificate which signed the MQTT server certicate
        ca: /certs/ca.crt

Run

AstroLive checks recursively within the configured directory for new FITS files if you configured camera_file. By default it checks within the directory /fits.

If you want to use TLS for the connection to the MQTT broker you need to provide the certificate of the certification authority which signed the MQTT server certificate (defaults to /certs/ca.crt).

Run with Python

Ensure to have the dependencies installed

pip3 install -r requirements.txt

Start AstroLive

python3 run.py

Build & Run as a container

This is the way :-).

| [T]  
| | |√  <••>  
| ( )   (  )  

Build

docker build --tag astrolive .

Run

# As a container
docker run \
  --volume /fits:/fits:ro \
  --name astrolive \
  --rm \
  astrolive

# As a detached container
docker run \
  --volume /fits:/fits:ro \
  --name astrolive \
  --rm -d \
  astrolive
If using TLS
# As a container
docker run \
  --volume /fits:/fits:ro \
  --volume /certs:/certs:ro \
  --name astrolive \
  --rm \
  astrolive

# As a detached container
docker run \
  --volume /fits:/fits:ro \
  --volume /certs:/certs:ro \
  --name astrolive \
  --rm -d \
  astrolive

Integrate with Home Assistant

Effectively, there is no configuration required if you just want to monitor your observatory. Simply creating your Lovelace UI using the generated sensors and camera(s) would do the trick.

Devices and Sensors

The following devices with the sensors attached are created in Home Assistant based on the example default.cfg.yaml from above:

Telescope Camera Switch Focuser
At home Image Type Max switch Position
At park Exposure Duration Switch 0 Is moving
Altitude Time of observation Switch 1
Azimuth X axis binning Switch ...
Declination Y axis binning
Declination rate Gain
Guiderate declination Offset
Right ascension Pixel X axis size
Right ascension rate Pixel Y axis size
Guiderate right ascension Imaging instrument
Side of pier CCD temperature
Site elevation Filter
Site Latitude Sensor readout mode
Site Longitude Sensor Bayer pattern
Slewing Telescope
Focal length
RA of telescope
Declination of telescope
Altitude of telescope
Azimuth of telescope
Object of interest
RA of imaged object
Declination of imaged object
Rotation of imaged object
Software

My personal Lovelace configuration from the screenshot above using mushroom-entity-card, button-card, grid and picture-entity:

Sending Commands

Sending commands to the observatory is implemented by the use of input texts and the mqtt publisher service of Home Assistant. To not accidentaly park/slew the scope or power of the camera during an imaging session I'm intentionally using dedicated buttons to send a command.

Input Texts

The initial values of RA and DEC are pointing to Polaris

Show YAML
astrolive_target_ra_h:
  name: Target RA h
  min: 0
  max: 24
  initial: 02

astrolive_target_ra_m:
  name: Target RA m
  min: 0
  max: 60
  initial: 59

astrolive_target_ra_s:
  name: Target RA s
  min: 0
  max: 60
  initial: 58.71

astrolive_target_dec_d:
  name: Target DEC d
  min: -90
  max: 90
  initial: 89

astrolive_target_dec_m:
  name: Target DEC m
  min: 0
  max: 60
  initial: 21

astrolive_target_dec_s:
  name: Target DEC s
  min: 0
  max: 60
  initial: 30.5

astrolive_focuser_position:
  name: Focuser Position
  min: 0
  max: 35000
  initial: 10000

Scripts

Sending a single command like park and unpark.

Show YAML
alias: AstroLive - Send Command
sequence:
  - service: mqtt.publish
    data:
      topic: astrolive/command
      payload_template: >
        {{ '{{ "component": "{}", "command": "{}" }}'.format( component,
        command) }}
mode: single

Slewing the telescope.

Show YAML
alias: AstroLive - Send Command Slew
sequence:
  - service: mqtt.publish
    data:
      topic: astrolive/command
      payload_template: >
        {{ '{{ "component": "{}", "command": "slew", "ra": "{}", "dec": "{}"
        }}'.format( component | trim, ra | trim, dec | trim ) }}
mode: single

Moving the focuser.

Show YAML
alias: AstroLive - Send Command Focuser Move
sequence:
  - service: mqtt.publish
    data:
      topic: astrolive/command
      payload_template: >
        {{ '{{ "component": "{}", "command": "move", "position": "{}"
        }}'.format( component | trim, position | trim ) }}
mode: single

Turning on or off a port on the switch.

Show YAML
alias: AstroLive - Send Command Switch On/Off
sequence:
  - service: mqtt.publish
    data:
      topic: astrolive/command
      payload_template: >
        {{ '{{ "component": "{}", "command": "{}", "id": "{}" }}'.format(
        component | trim, command | trim, id | trim ) }}
mode: single

Lovelace UI

Using button-card, entities and the mushroom-entity-card cards.

astrolive's People

Contributors

mawinkler avatar

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.