A live bird collage card for your Home Assistant dashboard.
adding more customization
ehpersonal3898de55bf4e16
diff --git a/birdnet.conf-defaults b/birdnet.conf-defaultsindex e0e38a2d..61b33f5d 100644--- a/birdnet.conf-defaults+++ b/birdnet.conf-defaults@@ -68,6 +68,11 @@ RTSP_STREAM=PUSHED_APP_KEY=PUSHED_APP_SECRET=+#----------------------- Apprise Miscellanous Configuration -------------------#++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#################################################################################-------------------------------- Defaults ----------------------------------#diff --git a/scripts/config.php b/scripts/config.phpindex f9d0abaa..fa8c204b 100644--- a/scripts/config.php+++ b/scripts/config.php@@ -10,6 +10,9 @@ $birdweather_id = $_GET["birdweather_id"];$pushed_app_key = $_GET["pushed_app_key"];$pushed_app_secret = $_GET["pushed_app_secret"];$apprise_input = $_GET['apprise_input'];+$apprise_notification_title = $_GET['apprise_notification_title'];+$apprise_notification_body = $_GET['apprise_notification_body'];+$apprise_notify_each_detection = $_GET['apprise_notify_each_detection'];$contents = file_get_contents("/etc/birdnet/birdnet.conf");$contents = preg_replace("/LATITUDE=.*/", "LATITUDE=$latitude", $contents);@@ -17,6 +20,10 @@ $contents = preg_replace("/LONGITUDE=.*/", "LONGITUDE=$longitude", $contents);$contents = preg_replace("/BIRDWEATHER_ID=.*/", "BIRDWEATHER_ID=$birdweather_id", $contents);$contents = preg_replace("/PUSHED_APP_KEY=.*/", "PUSHED_APP_KEY=$pushed_app_key", $contents);$contents = preg_replace("/PUSHED_APP_SECRET=.*/", "PUSHED_APP_SECRET=$pushed_app_secret", $contents);+$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);+$contents2 = file_get_contents("./scripts/thisrun.txt");$contents2 = preg_replace("/LATITUDE=.*/", "LATITUDE=$latitude", $contents2);@@ -105,7 +112,15 @@ if (!isset($_SERVER['PHP_AUTH_USER'])) {<p><a target="_blank" href="https://pushed.co/quick-start-guide">Pushed iOS Notifications</a> can be setup and enabled for New Species notifications. Be sure to "Enable" the "Pushed Notifications" in "Tools" > "Services" if you would like to use this feature. Sorry, Android users, this only works on iOS.</p><label for="apprise_input">Apprise Notifications Configuration: </label>- <textarea cols="140" name="apprise_input" type="text" ><?php print($apprise_config);?></textarea>+ <textarea style="vertical-align: top" name="apprise_input" cols="140" type="text" ><?php print($apprise_config);?></textarea><br><br>+ <label for="apprise_notification_title">Notification Title: </label>+ <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" value="true" disabled checked>+ <label for="apprise_notify_each_species">Notify each new species</label><br>+ <input type="checkbox" name="apprise_notify_each_detection" value="<?php print($config['APPRISE_NOTIFY_EACH_DETECTION']);?>">+ <label for="apprise_notify_each_detection">Notify each new detection</label><br><p><a target="_blank" href="https://github.com/caronc/apprise/wiki">Apprise Notifications</a> can be setup and enabled for New Species notifications.</p><label for="language">Database Language: </label>diff --git a/scripts/install_config.sh b/scripts/install_config.shindex 0ad72eb4..94f7ca31 100755--- a/scripts/install_config.sh+++ b/scripts/install_config.sh@@ -81,16 +81,11 @@ RTSP_STREAM=PUSHED_APP_KEY=PUSHED_APP_SECRET=-#------------------- Browser Notifications via Notify.run -------------------#-#________________The variable below enables browser notifications______________#-#________________________See https://notify.run/ to get________________________#-#_________________ __these subscription URL for your device.___________________#+#----------------------- Apprise Miscellanous Configuration -------------------#-# Keep these EMPTY if haven't setup a Notify.run Channel yet. #--## Notify.run Channel ID--NOTIFY_RUN_CHANNEL_ID=+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#################################################################################-------------------------------- Defaults ----------------------------------#diff --git a/scripts/server.py b/scripts/server.pyindex b81f13ec..c367a1be 100755--- a/scripts/server.py+++ b/scripts/server.py@@ -205,15 +205,21 @@ def analyzeAudioData(chunks, lat, lon, week, sensitivity, overlap,):return detectionsdef sendAppriseNotifications(species,confidence):- apobj = apprise.Apprise()- config = apprise.AppriseConfig()- config.add(userDir + '/BirdNET-Pi/apprise.txt')- apobj.add(config)-- apobj.notify(- body='A '+species+' was just detected with a confidence of '+confidence,- title='New BirdNET-Pi Detection',- )+ if os.path.getsize(userDir + '/BirdNET-Pi/apprise.txt') > 0:+ with open(userDir + '/BirdNET-Pi/scripts/thisrun.txt', 'r') as f:+ this_run = f.readlines()+ title = "." + str(str(str([i for i in this_run if i.startswith('APPRISE_NOTIFICATION_TITLE')]).split('=')[1]).split('\\')[0])+ body = "." + str(str(str([i for i in this_run if i.startswith('APPRISE_NOTIFICATION_BODY')]).split('=')[1]).split('\\')[0])++ 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,+ )def writeResultsToFile(detections, min_conf, path):@@ -224,7 +230,7 @@ def writeResultsToFile(detections, min_conf, path):for d in detections:for entry in detections[d]:if entry[1] >= min_conf and ((entry[0] in INCLUDE_LIST or len(INCLUDE_LIST) == 0) and (entry[0] not in EXCLUDE_LIST or len(EXCLUDE_LIST) == 0) ):- if os.path.getsize(userDir + '/BirdNET-Pi/apprise.txt') > 0:+ if str(str(str([i for i in this_run if i.startswith('APPRISE_NOTIFY_EACH_DETECTION')]).split('=')[1]).split('\\')[0]) == "true":sendAppriseNotifications(str(entry[0]),str(entry[1]));rfile.write(d + ';' + entry[0].replace('_', ';') + ';' + str(entry[1]) + '\n')rcnt += 1diff --git a/scripts/species_notifier.sh b/scripts/species_notifier.shindex 99638aeb..bad7a98d 100755--- a/scripts/species_notifier.sh+++ b/scripts/species_notifier.sh@@ -20,10 +20,6 @@ if ! diff ${IDFILE} ${lastcheck} &> /dev/null;thenecho "Sending the following notification:${NOTIFICATION}"- if [ ! -z ${NOTIFY_RUN_CHANNEL_ID} ];then- curl https://notify.run/${NOTIFY_RUN_CHANNEL_ID} -d ${NOTIFICATION}- fi-if [ ! -z ${PUSHED_APP_KEY} ];thencurl -X POST \--form-string "app_key=${PUSHED_APP_KEY}" \diff --git a/scripts/update_birdnet_snippets.sh b/scripts/update_birdnet_snippets.shindex 88a9bc43..107feb5b 100755--- a/scripts/update_birdnet_snippets.sh+++ b/scripts/update_birdnet_snippets.sh@@ -12,6 +12,15 @@ fiif ! grep PRIVACY_MODE /etc/birdnet/birdnet.conf &>/dev/null;thensudo -u$USER echo "PRIVACY_MODE=off" >> /etc/birdnet/birdnet.conffi+if ! grep APPRISE_NOTIFICATION_TITLE /etc/birdnet/birdnet.conf &>/dev/null;then+ sudo -u$USER echo "APPRISE_NOTIFICATION_TITLE=New BirdNET-Pi Detection" >> /etc/birdnet/birdnet.conf+fi+if ! grep APPRISE_NOTIFICATION_BODY /etc/birdnet/birdnet.conf &>/dev/null;then+ sudo -u$USER echo "APPRISE_NOTIFICATION_BODY=A \$sciname \$comname was just detected with a confidence of \$confidence" >> /etc/birdnet/birdnet.conf+fi+if ! grep APPRISE_NOTIFY_EACH_DETECTION /etc/birdnet/birdnet.conf &>/dev/null;then+ sudo -u$USER echo "APPRISE_NOTIFY_EACH_DETECTION=false" >> /etc/birdnet/birdnet.conf+fiif ! which lsof &>/dev/null;thensudo apt update && sudo apt -y install lsoffi