A live bird collage card for your Home Assistant dashboard.
initial commit
ehpersonal38f3f618e2a8ef
diff --git a/birdnet.conf-defaults b/birdnet.conf-defaultsindex 239d4d87..6eb87b68 100644--- a/birdnet.conf-defaults+++ b/birdnet.conf-defaults@@ -63,6 +63,8 @@ APPRISE_NOTIFICATION_BODY="A \$sciname \$comname was just detected with a confidAPPRISE_NOTIFY_EACH_DETECTION=0APPRISE_NOTIFY_NEW_SPECIES=0APPRISE_WEEKLY_REPORT=1+APPRISE_NOTIFY_NEW_SPECIES_EACH_DAY=0+APPRISE_MINIMUM_SECONDS_BETWEEN_NOTIFICATIONS_PER_SPECIES=0#---------------------- Flickr Images API Configuration -----------------------### If FLICKR_API_KEY is set, the web interface will try and display bird imagesdiff --git a/scripts/install_config.sh b/scripts/install_config.shindex db980d73..a7f79915 100755--- a/scripts/install_config.sh+++ b/scripts/install_config.sh@@ -76,6 +76,8 @@ APPRISE_NOTIFICATION_BODY="A \$sciname \$comname was just detected with a confidAPPRISE_NOTIFY_EACH_DETECTION=0APPRISE_NOTIFY_NEW_SPECIES=0APPRISE_WEEKLY_REPORT=1+APPRISE_NOTIFY_NEW_SPECIES_EACH_DAY=0+APPRISE_MINIMUM_SECONDS_BETWEEN_NOTIFICATIONS_PER_SPECIES=0#---------------------- Flickr Images API Configuration -----------------------### If FLICKR_API_KEY is set, the web interface will try and display bird imagesdiff --git a/scripts/update_birdnet_snippets.sh b/scripts/update_birdnet_snippets.shindex a2c8cea4..c5e6ee87 100755--- a/scripts/update_birdnet_snippets.sh+++ b/scripts/update_birdnet_snippets.sh@@ -47,6 +47,9 @@ fiif ! grep APPRISE_NOTIFY_NEW_SPECIES_EACH_DAY /etc/birdnet/birdnet.conf &>/dev/null;thensudo -u$USER echo "APPRISE_NOTIFY_NEW_SPECIES_EACH_DAY=0 " >> /etc/birdnet/birdnet.conffi+if ! grep APPRISE_MINIMUM_SECONDS_BETWEEN_NOTIFICATIONS_PER_SPECIES /etc/birdnet/birdnet.conf &>/dev/null;then+ sudo -u$USER echo "APPRISE_MINIMUM_SECONDS_BETWEEN_NOTIFICATIONS_PER_SPECIES=0 " >> /etc/birdnet/birdnet.conf+fi# If the config does not contain the DATABASE_LANG setting, we'll want to add it.# Defaults to not-selected, which config.php will know to render as a language option.diff --git a/scripts/utils/notifications.py b/scripts/utils/notifications.pyindex 81061402..7db8fd45 100644--- a/scripts/utils/notifications.py+++ b/scripts/utils/notifications.py@@ -4,11 +4,15 @@ import socketimport sqlite3from datetime import datetimeimport requests+import timeuserDir = os.path.expanduser('~')APPRISE_CONFIG = userDir + '/BirdNET-Pi/apprise.txt'DB_PATH = userDir + '/BirdNET-Pi/scripts/birds.db'+flickr_images = {}+species_last_notified = {}+def notify(body, title, attached=""):apobj = apprise.Apprise()@@ -37,6 +41,14 @@ def sendAppriseNotifications(species, confidence, path, date, time, week, latitubody = settings_dict.get('APPRISE_NOTIFICATION_BODY')sciName, comName = species.split("_")+ print(species_last_notified)++ APPRISE_MINIMUM_SECONDS_BETWEEN_NOTIFICATIONS_PER_SPECIES = settings_dict.get('APPRISE_MINIMUM_SECONDS_BETWEEN_NOTIFICATIONS_PER_SPECIES')+ if APPRISE_MINIMUM_SECONDS_BETWEEN_NOTIFICATIONS_PER_SPECIES != "0":+ if species_last_notified.get(comName) is not None:+ if int(time.time()) - species_last_notified[comName] < int(APPRISE_MINIMUM_SECONDS_BETWEEN_NOTIFICATIONS_PER_SPECIES):+ return+try:websiteurl = settings_dict.get('BIRDNETPI_URL')if len(websiteurl) == 0:@@ -46,7 +58,6 @@ def sendAppriseNotifications(species, confidence, path, date, time, week, latitulistenurl = websiteurl+"?filename="+pathimage_url = ""- flickr_images = {}if len(settings_dict.get('FLICKR_API_KEY')) > 0 and "$flickrimage" in body:if not comName in flickr_images:@@ -93,6 +104,7 @@ def sendAppriseNotifications(species, confidence, path, date, time, week, latitu.replace("$flickrimage", image_url if "{" in body else "")\.replace("$overlap", overlap)notify(notify_body, notify_title, image_url)+ species_last_notified[comName] = int(time.time())APPRISE_NOTIFICATION_NEW_SPECIES_DAILY_COUNT_LIMIT = 1 # Notifies the first N per day.if settings_dict.get('APPRISE_NOTIFY_NEW_SPECIES_EACH_DAY') == "1":@@ -137,6 +149,7 @@ def sendAppriseNotifications(species, confidence, path, date, time, week, latitu.replace("$overlap", overlap)\+ " (first time today)"notify(notify_body, notify_title, image_url)+ species_last_notified[comName] = int(time.time())con.close()except sqlite3.Error as e:print(e)@@ -184,6 +197,7 @@ def sendAppriseNotifications(species, confidence, path, date, time, week, latitu.replace("$overlap", overlap)\+ " (only seen " + str(int(numberDetections)) + " times in last 7d)"notify(notify_body, notify_title, image_url)+ species_last_notified[comName] = int(time.time())con.close()except sqlite3.Error:print("Database busy")