Skip to content

A live bird collage card for your Home Assistant dashboard.

starting this to get some help

mcguirepr89cdbadbb45c73
diff --git a/birdnet.conf-defaults b/birdnet.conf-defaults
index e75cda14..e53af20c 100644
--- a/birdnet.conf-defaults
+++ b/birdnet.conf-defaults
@@ -60,7 +60,8 @@ RTSP_STREAM=
APPRISE_NOTIFICATION_TITLE="New BirdNET-Pi Detection"
APPRISE_NOTIFICATION_BODY="A \$sciname \$comname was just detected with a confidence of \$confidence"
-APPRISE_NOTIFY_EACH_DETECTION=false
+APPRISE_NOTIFY_EACH_DETECTION=0
+APPRISE_NOTIFY_NEW_SPECIES=0
#---------------------- Flickr Images API Configuration -----------------------#
diff --git a/homepage/views.php b/homepage/views.php
index 4dbd247d..33f46219 100644
--- a/homepage/views.php
+++ b/homepage/views.php
@@ -250,10 +250,6 @@ if(isset($_GET['view'])){
'sudo systemctl restart spectrogram_viewer.service',
'sudo systemctl disable --now spectrogram_viewer.service',
'sudo systemctl enable --now spectrogram_viewer.service',
- 'sudo systemctl stop pushed_notifications.service',
- 'sudo systemctl restart pushed_notifications.service',
- 'sudo systemctl disable --now pushed_notifications.service',
- 'sudo systemctl enable --now pushed_notifications.service',
'stop_core_services.sh',
'restart_services.sh',
'sudo reboot',
diff --git a/scripts/config.php b/scripts/config.php
index 78f0055e..8b13084c 100644
--- a/scripts/config.php
+++ b/scripts/config.php
@@ -16,10 +16,10 @@ if(isset($_GET['apprise_notify_each_detection'])) {
} else {
$apprise_notify_each_detection = 0;
}
-if(isset($_GET['apprise_notify_each_species'])) {
- exec('sudo systemctl start pushed_notifications.service');
+if(isset($_GET['apprise_notify_new_species'])) {
+ $apprise_notify_new_species = 1;
} else {
- exec('sudo systemctl stop pushed_notifications.service');
+ $apprise_notify_new_species = 0;
}
// logic for setting the date and time based on user inputs from the form below
@@ -46,6 +46,7 @@ $contents = preg_replace("/BIRDWEATHER_ID=.*/", "BIRDWEATHER_ID=$birdweather_id"
$contents = preg_replace("/APPRISE_NOTIFICATION_TITLE=.*/", "APPRISE_NOTIFICATION_TITLE=\"$apprise_notification_title\"", $contents);
$contents = preg_replace("/APPRISE_NOTIFICATION_BODY=.*/", "APPRISE_NOTIFICATION_BODY=\"$apprise_notification_body\"", $contents);
$contents = preg_replace("/APPRISE_NOTIFY_EACH_DETECTION=.*/", "APPRISE_NOTIFY_EACH_DETECTION=$apprise_notify_each_detection", $contents);
+$contents = preg_replace("/APPRISE_NOTIFY_NEW_SPECIES=.*/", "APPRISE_NOTIFY_NEW_SPECIES=$apprise_notify_new_species", $contents);
$contents = preg_replace("/FLICKR_API_KEY=.*/", "FLICKR_API_KEY=$flickr_api_key", $contents);
@@ -56,6 +57,7 @@ $contents2 = preg_replace("/BIRDWEATHER_ID=.*/", "BIRDWEATHER_ID=$birdweather_id
$contents2 = preg_replace("/APPRISE_NOTIFICATION_TITLE=.*/", "APPRISE_NOTIFICATION_TITLE=\"$apprise_notification_title\"", $contents2);
$contents2 = preg_replace("/APPRISE_NOTIFICATION_BODY=.*/", "APPRISE_NOTIFICATION_BODY=\"$apprise_notification_body\"", $contents2);
$contents2 = preg_replace("/APPRISE_NOTIFY_EACH_DETECTION=.*/", "APPRISE_NOTIFY_EACH_DETECTION=$apprise_notify_each_detection", $contents2);
+$contents2 = preg_replace("/APPRISE_NOTIFY_NEW_SPECIES=.*/", "APPRISE_NOTIFY_NEW_SPECIES=$apprise_notify_new_species", $contents2);
$contents2 = preg_replace("/FLICKR_API_KEY=.*/", "FLICKR_API_KEY=$flickr_api_key", $contents2);
@@ -144,8 +146,8 @@ https://discordapp.com/api/webhooks/{WebhookID}/{WebhookToken}
<input name="apprise_notification_title" type="text" value="<?php print($config['APPRISE_NOTIFICATION_TITLE']);?>" /><br>
<label for="apprise_notification_body">Notification Body (use variables $sciname, $comname, or $confidence): </label>
<input name="apprise_notification_body" type="text" value="<?php print($config['APPRISE_NOTIFICATION_BODY']);?>" /><br>
- <input type="checkbox" name="apprise_notify_each_species" <?php $output = shell_exec("service pushed_notifications status"); if (!strpos($output, 'dead') !== false && filesize($home."/BirdNET-Pi/apprise.txt") != 0) { echo "checked"; } ?>>
- <label for="apprise_notify_each_species">Notify each new species</label><br>
+ <input type="checkbox" name="apprise_notify_new_species" <?php if($config['APPRISE_NOTIFY_NEW_SPECIES'] == 1 && filesize($home."/BirdNET-Pi/apprise.txt") != 0) { echo "checked"; };?> >
+ <label for="apprise_notify_new_species">Notify each new species</label><br>
<input type="checkbox" name="apprise_notify_each_detection" <?php if($config['APPRISE_NOTIFY_EACH_DETECTION'] == 1 && filesize($home."/BirdNET-Pi/apprise.txt") != 0) { echo "checked"; };?> >
<label for="apprise_notify_each_detection">Notify each new detection</label><br><br>
<h3>Bird Photos from Flickr</h3>
diff --git a/scripts/install_config.sh b/scripts/install_config.sh
index e74ac560..daab6881 100755
--- a/scripts/install_config.sh
+++ b/scripts/install_config.sh
@@ -74,6 +74,7 @@ RTSP_STREAM=
APPRISE_NOTIFICATION_TITLE="New BirdNET-Pi Detection"
APPRISE_NOTIFICATION_BODY="A \$sciname \$comname was just detected with a confidence of \$confidence"
APPRISE_NOTIFY_EACH_DETECTION=0
+APPRISE_NOTIFY_NEW_SPECIES=0
#---------------------- Flickr Images API Configuration -----------------------#
diff --git a/scripts/install_services.sh b/scripts/install_services.sh
index 093047bc..1d038b9c 100755
--- a/scripts/install_services.sh
+++ b/scripts/install_services.sh
@@ -91,22 +91,6 @@ EOF
systemctl enable extraction.service
}
-install_pushed_notifications() {
- cat << EOF > $HOME/BirdNET-Pi/templates/pushed_notifications.service
-[Unit]
-Description=BirdNET-Pi Pushed.co Notifications
-[Service]
-Restart=on-success
-RestartSec=3
-Type=simple
-User=$USER
-ExecStart=/usr/local/bin/species_notifier.sh
-[Install]
-WantedBy=multi-user.target
-EOF
- ln -sf $HOME/BirdNET-Pi/templates/pushed_notifications.service /usr/lib/systemd/system
-}
-
create_necessary_dirs() {
echo "Creating necessary directories"
[ -d ${EXTRACTED} ] || sudo -u ${USER} mkdir -p ${EXTRACTED}
@@ -436,7 +420,6 @@ install_services() {
install_recording_service
install_custom_recording_service # But does not enable
install_extraction_service
- install_pushed_notifications
install_spectrogram_service
install_chart_viewer_service
install_gotty_logs
diff --git a/scripts/restart_services.sh b/scripts/restart_services.sh
index 98993af9..ad4e9f37 100755
--- a/scripts/restart_services.sh
+++ b/scripts/restart_services.sh
@@ -9,7 +9,6 @@ sudo pkill server.py
sudo systemctl stop birdnet_recording.service
services=(web_terminal.service
spectrogram_viewer.service
-pushed_notifications.service
livestream.service
icecast2.service
extraction.service
@@ -22,6 +21,6 @@ sudo systemctl restart "${i}"
done
until grep 5050 <(netstat -tulpn 2>&1);do
sudo systemctl restart birdnet_server.service
-sleep 30
+sleep 45
done
sudo systemctl restart birdnet_analysis.service
diff --git a/scripts/server.py b/scripts/server.py
index 35833e13..627b1a07 100755
--- a/scripts/server.py
+++ b/scripts/server.py
@@ -243,6 +243,32 @@ def sendAppriseNotifications(species,confidence):
title=title,
)
+ if str(str(str([i for i in this_run if i.startswith('APPRISE_NOTIFY_NEW_SPECIES')]).split('=')[1]).split('\\')[0]) == "1":
+ try:
+ con = sqlite3.connect(userDir + '/BirdNET-Pi/scripts/birds.db')
+ cur = con.cursor()
+ cur.execute("SELECT DISTINCT(Com_Name) FROM detections")
+ known_species = cur.fetchall()
+ sciName,comName = species.split("_")
+
+ print("\ncomName: ",comName)
+ print("\nknown_species: ",known_species)
+ if comName not in known_species:
+ apobj = apprise.Apprise()
+ config = apprise.AppriseConfig()
+ config.add(userDir + '/BirdNET-Pi/apprise.txt')
+ apobj.add(config)
+
+ apobj.notify(
+ body=body.replace("$sciname",species.split("_")[0]).replace("$comname",species.split("_")[1]).replace("$confidence",confidence),
+ title=title,
+ )
+
+ con.close()
+ except:
+ print("Database busy")
+ time.sleep(2)
+
def writeResultsToFile(detections, min_conf, path):
print('WRITING RESULTS TO', path, '...', end=' ')
diff --git a/scripts/service_controls.php b/scripts/service_controls.php
index 8abde5e2..e81952b3 100644
--- a/scripts/service_controls.php
+++ b/scripts/service_controls.php
@@ -73,13 +73,6 @@
<button type="submit" name="submit" value="sudo systemctl disable --now spectrogram_viewer.service">Disable</button>
<button type="submit" name="submit" value="sudo systemctl enable --now spectrogram_viewer.service">Enable</button>
</form>
- <form action="" method="GET">
- <h3>Pushed Notifications</h3>
- <button type="submit" name="submit" value="sudo systemctl stop pushed_notifications.service">Stop</button>
- <button type="submit" name="submit" value="sudo systemctl restart pushed_notifications.service">Restart</button>
- <button type="submit" name="submit" value="sudo systemctl disable --now pushed_notifications.service">Disable</button>
- <button type="submit" name="submit" value="sudo systemctl enable --now pushed_notifications.service">Enable</button>
- </form>
<form action="" method="GET">
<button type="submit" name="submit" value="stop_core_services.sh">Stop Core Services</button>
</form>