Aurora sensor setup?

Has anyone got the aurora sensor working?

Mine just seems to sit there with no valid data, and there’s not exactly a lot of options to tweak.

where do you live?

Australia.

Is it limited geographically?

I don’t know, but do you have aurora in Australia? I think that In Europe is only in Norway/Finland so way north. In the austral hemisphere only extremely south

Yes, occasionally it reaches this far north - hence the interest.

I’m also interested if the sensor works at all. There was Aurora Borealis in my place two days ago, some people managed to take photos of it, however, my sensor was silent :frowning:

mine too, it shows 0% all the time, anyone got it working, i got the right set of coordinates and i am in Iceland. I just saw the auroras yesterday and the sensor said 0%

anyone?
maybe @AllHailJ, I see he mention it in an other post, can you be so kind nd help us with it?

Thanks!

In Colorado USA. Not very much chance of getting aurora here (I’ve only seen 1 here and it was awesome) so I haven’t been able to know if it works or not. The sun has been relatively quite lately.

Let me look into this tomorrow. I am wondering if NOAA changed the file format.

1 Like

Been digging in. The NOAA model rates the probability of an aurora based on the energy. You can see in this screenshot. The model uses the probability to predict y/n . I have not figured out the % yet. What do you have your slider bar on the integration configuration. Default it is 75%. Left is 0% on the slider and 100% is on the right. For Iceland, Greenland and Northern Canada I would drop this to 25%. As a test drop to 0% and see if you get anything. I did not but again I’m at 40 degrees north.

Here is the configuration.

Still working!

I am monitoring reykjavik iceland to see if it changes.

Learning more. NOAA runs the ovation model for every 5 minutes and produces this file.

https://services.swpc.noaa.gov/json/ovation_aurora_latest.json

This file contains the Long, Lat and % probability of an aurora at a given point comprising a 1 degree grid. So the probability covers 60 sq nautical miles. There are py scripts to plot the probability. I have no experience in python and it isn’t very clear to me at this point. I do know perl and I think I can write a perl script that will allow you to run automations that pull in the visibility and percentage every 5 minutes. The json file is just shy of 1mg. Moderate load of 290MB per day. Every 30 minutes OK?

I also think visibility should be more like

negligible,      1-11%
very low,       12-22%
low,            23-33%
medium low,     34-44%  
medium,         45-55%
medium high,    56-66% 
high,           67-77%
very high,      78-88%
Almost certain. 89-100%

Regards

EDIT - HERE IS HOW I MADE A WORK AROUND

I can’t fix the integration but I do have a work around. It is not clean but it works.

First I wrote a perl script that downloaded the ovation_aurora_latest.json file and save to the directory where the script is housed. Here is the script that I named aurora.pl

!/usr/lib/perl
#Written By JL. Gent
#Version 1.0

use strict;
use warnings;
use LWP::Simple;

my $longitude = -21.895;
my $latitude = 64.08;

if ($longitude < 0 ) {
  $longitude += 360;
}

$longitude = int($longitude + $longitude/abs($longitude*2 || 1));
$latitude = int($latitude + $latitude/abs($latitude*2 || 1));

my $index = $longitude * 181  + (90 + $latitude) ;

#print "Downloading file \n";

# variable to store the URL
my $url = 'https://services.swpc.noaa.gov/json/ovation_aurora_latest.json';
my $file = './ovation_aurora_latest.json';

# get the file
getstore($url, $file);

#print "File Downloaded \n";

#
#-------------------------------------------------------------------------------------------------------------------
#
# Open the error and output files
#
#-------------------------------------------------------------------------------------------------------------------
#

$file = './Error.txt';
open(ERROR, ">$file") || die print "Can't open error check $file \n" ;

$file = './value.csv';
open(OUT, ">$file") || die print "Can't open error check $file \n" ;

#
#
print ERROR "Starting the Read \n";
#print "Longitude= $longitude \n";
#print "Latitude= $latitude \n";

#
#-------------------------------------------------------------------------------------------------------------------
#
# Read the data from the json file
#
#-------------------------------------------------------------------------------------------------------------------
#
 my $line = '';
$file = './ovation_aurora_latest.json';
open(INPUT, "<$file") || die print ERROR "Can't open $file \n" ;
 $line = <INPUT> ;
 chomp $line;
close(INPUT);

#
#-------------------------------------------------------------------------------------------------------------------
#
# clean up the unneeded stuff
#
#-------------------------------------------------------------------------------------------------------------------
#
my $i = 0;
my $j = 195480;

$line =~ s/^.+: \[//;
$line =~ s/\], ".+"\}//;
$line =~ s/\],/,/gm;
$line =~ s/\s+//gm;
$line =~ s/\[|\]//gm;
my @WA = split(/,/, $line);

my @long;
my @lat;
my @percent;

for ($i = 0; $i <= $j-2; $i += 3) {
  push @long, $WA[$i];
}

for ($i = 1; $i <= $j-1; $i += 3) {
  push @lat, $WA[$i];
}

for ($i = 2; $i <= $j; $i += 3) {
  push @percent, $WA[$i];
}

#print "Long = $long[$index],  Lat = $lat[$index], Percent = $percent[$index] \n";

my $chance = '';
if ($percent[$index] > 89) {
  $chance = "Almost certain";
} elsif ($percent[$index] > 78) {
  $chance = "Very high";
} elsif ($percent[$index] > 67) {
  $chance = "High";
} elsif ($percent[$index] > 56) {
  $chance = "Medium high";
} elsif ($percent[$index] > 45) {
  $chance = "Medium";
} elsif ($percent[$index] > 34) {
  $chance = "Medium low";
} elsif ($percent[$index] > 23) {
  $chance = "Low";
} elsif ($percent[$index] > 12) {
  $chance = "Very low";
} else {
  $chance = "Negligible";
}

#print "{\"percentage\": $percent[$index], \"chance\": \"$chance\"}\n";

print OUT "$percent[$index],$chance \n";
close(OUT);
close(ERROR);

I am using the VM version of home assistant on Ubuntu 20.04. I have set up samba in HA to share the directories on my network. I also have ssh set up to HA and to all of my servers.

I use a script and crontab to run the update every 10 minutes. The file is updated every 5 minutes. Here are my script and crontab. Bash script is named aurora.sh

#!/bin/bash
#full pathnames are best when calling scripts from crontab
cd /home/jonny/aurora
perl /home/jonny/aurora/aurora.pl
cp /home/jonny/aurora/value.csv /home/jonny/haconfig/value.csv

I created the directory aurora in my home directory on the vm. I mounted the samba directories in /etc/fstab as given below.

# Home Assistant config directory
//192.168.1.161/config /home/jonny/haconfig cifs uid=0,credentials=/home/jonny/.haconfig,iocharset=utf8,vers=3.0,noperm 0 0

You may need to install cifs on your host machine (linux).

apt install cifs-utils

I went into crontab (crontab -e) and set the job to run once every 10 minutes. Again notice full path descriptions.

*/10 * * * * /home/jonny/aurora.sh

Lastly I set up two sensors in my sensors.yaml (sensors: !include sensors.yaml set in my configuration.yaml).

# Aurora Sensors

- platform: command_line
  name: percent
  command: "cat /config/value.csv"
  value_template: '{{ value.split(",")[0] }}'
  scan_interval: 600
  
- platform: command_line
  name: chance
  command: "cat /config/value.csv"
  value_template: '{{ value.split(",")[1] }}'
  scan_interval: 600

Here are my sensors showing Reykjavik Iceland.

Screenshot from 2022-01-07 16-05-23

if you want more than 1 location you need to modify the code. I will add that later. I know this updates because the sensor went from 7 to 8 while typing this. If you need help send me a message.

@Dingin, @Molodex, @anon35356645, @sane - This is the best I could do. I think this could put heavy load on raspberry pi so wouldn’t recommend if you are using.

1 Like

Thanks for your help, ill give it a try!

I fixed the perl script so you could easily add additional locations. You can add as many as you want. You need to add sensors as appropriate.

#!/usr/lib/perl
#Written By JL Gent
#Version 1.0

use strict;
use warnings;
use LWP::Simple;

my $longitude = -21.895;
my $latitude = 64.08;

my $longitude1 = -104;
my $latitude1 = 39;

my $index = Index($longitude, $latitude);
my $index1 = Index($longitude1, $latitude1);

#print "Downloading file \n";

# variable to store the URL
my $url = 'https://services.swpc.noaa.gov/json/ovation_aurora_latest.json';
my $file = './ovation_aurora_latest.json';     

# get the file
getstore($url, $file);

#print "File Downloaded \n";

#
#-------------------------------------------------------------------------------------------------------------------
# Open the error and output files
#-------------------------------------------------------------------------------------------------------------------
#

$file = './Error.txt';
open(ERROR, ">$file") || die print "Can't open file: $file \n" ;

$file = './value.csv';
open(OUT, ">$file") || die print ERROR "Can't open file: $file \n" ;

#
#print ERROR "Starting the Read \n";
#print "Longitude= $longitude \n";
#print "Latitude= $latitude \n";

#
#-------------------------------------------------------------------------------------------------------------------
# Read the data from the json file
#-------------------------------------------------------------------------------------------------------------------
#
 my $line = '';
$file = './ovation_aurora_latest.json';

open(INPUT, "<$file") || die print ERROR "Can't open $file \n" ;
 $line = <INPUT> ;
 chomp $line;
close(INPUT);

#
#-------------------------------------------------------------------------------------------------------------------
# Make it one long single dimension array and push it in
#-------------------------------------------------------------------------------------------------------------------
#
my $i = 0;
my $j = 195480;

$line =~ s/^.+: \[//; #remove the starting bits
$line =~ s/\], ".+"\}//; #remove the ending bits
$line =~ s/\],/,/gm;  # clean up som misc stuff
$line =~ s/\s+//gm; #remove all the space
$line =~ s/\[|\]//gm; #remove the brackets
my @WA = split(/,/, $line);

#
#-------------------------------------------------------------------------------------------------------------------
# Push each third element into the proper array.  The index will be the correct value for the given lat long.
#-------------------------------------------------------------------------------------------------------------------
#

my @long;
my @lat;
my @percent;

for ($i = 0; $i <= $j-2; $i += 3) {
  push @long, $WA[$i];
}    

for ($i = 1; $i <= $j-1; $i += 3) {
  push @lat, $WA[$i];
}

for ($i = 2; $i <= $j; $i += 3) {
  push @percent, $WA[$i];
}   

#print "Long = $long[$index],  Lat = $lat[$index], Percent = $percent[$index] \n"; #debugging prints

#
#-------------------------------------------------------------------------------------------------------------------
# Populate the chance of seeing an Aurora
#-------------------------------------------------------------------------------------------------------------------
#

my $chance = Chance($percent[$index]);
my $chance1 = Chance($percent[$index1]);

#print "{\"percentage\": $percent[$index], \"chance\": \"$chance\"}\n"; # debugging prints

print OUT "$percent[$index],$chance,$percent[$index1],$chance1 \n";  #Print the file

close(OUT);
close(ERROR);

#subroutine to find index
sub Index { # pass longitude, latitude

  my $longitude = $_[0];
  my $latitude = $_[1];

  if ($longitude < 0 ) { 
    $longitude += 360; 
  }

  $longitude = int($longitude + $longitude/abs($longitude*2 || 1));
  $latitude = int($latitude + $latitude/abs($latitude*2 || 1));

  my $index = $longitude * 181  + (90 + $latitude) ;

  return $index;
}

#subroutine to get chance text
sub Chance { # pass percentage from json file

  my $percent = $_[0];
  my $chance = '';

  if ($percent > 89) {
    $chance = "Almost certain";
  } elsif ($percent > 78) {
    $chance = "Very high";
  } elsif ($percent > 67) {
    $chance = "High";
  } elsif ($percent > 56) {
    $chance = "Medium high";
  } elsif ($percent > 45) {
    $chance = "Medium";
  } elsif ($percent > 34) {
    $chance = "Medium low";
  } elsif ($percent > 23) {
    $chance = "Low";
  } elsif ($percent > 12) {
    $chance = "Very low";
  } else {
    $chance = "Negligible";
  }

  return $chance;
}

Thanks. Probability of Aurora calculation is clear and, if im not mistaken, was implemented in the official integration.
To me the remaining question is still whether the official integration is functional or not?

I do not know. The python makes no sense to me. I am thinking the location of file has changed or the format has changed.

The official integration seems to always show 0 and I’ve had it installed a couple of years. It seems a lot of github issues have been raised about it and then closed down.

If you could fix the original integration that would be awesome for us noobs which would benefit from a one click solution? :smiley:

I may not be able to fix as they have changed the website. I will take a look and see what I can do.