Skip to content

A live bird collage card for your Home Assistant dashboard.

Initial CUSTOM_IMAGE commit

ehpersonal386638016546b9
diff --git a/birdnet.conf-defaults b/birdnet.conf-defaults
index 43215e58..b329455c 100644
--- a/birdnet.conf-defaults
+++ b/birdnet.conf-defaults
@@ -206,6 +206,13 @@ RAW_SPECTROGRAM=0
HEARTBEAT_URL=
+## CUSTOM_IMAGE and CUSTOM_IMAGE_TITLE allow you to show a custom image on the
+## Overview page of your BirdNET-Pi. This can be used to show a dynamically
+## updating picture of your garden, for example.
+
+CUSTOM_IMAGE=
+CUSTOM_IMAGE_TITLE=
+
## These are just for debugging
LAST_RUN=
THIS_RUN=
diff --git a/scripts/advanced.php b/scripts/advanced.php
index 0fd2ecf3..dbecbb13 100644
--- a/scripts/advanced.php
+++ b/scripts/advanced.php
@@ -211,6 +211,22 @@ if(isset($_GET['submit'])) {
$contents2 = preg_replace("/RAW_SPECTROGRAM=.*/", "RAW_SPECTROGRAM=0", $contents2);
}
+ if(isset($_GET["custom_image"])) {
+ $custom_image = $_GET["custom_image"];
+ if(strcmp($custom_image,$config['CUSTOM_IMAGE']) !== 0) {
+ $contents = preg_replace("/CUSTOM_IMAGE=.*/", "CUSTOM_IMAGE=$custom_image", $contents);
+ $contents2 = preg_replace("/CUSTOM_IMAGE=.*/", "CUSTOM_IMAGE=$custom_image", $contents2);
+ }
+ }
+
+ if(isset($_GET["custom_image_label"])) {
+ $custom_image_label = $_GET["custom_image_label"];
+ if(strcmp($custom_image_label,$config['CUSTOM_IMAGE_TITLE']) !== 0) {
+ $contents = preg_replace("/CUSTOM_IMAGE_TITLE=.*/", "CUSTOM_IMAGE_TITLE=$custom_image_label", $contents);
+ $contents2 = preg_replace("/CUSTOM_IMAGE_TITLE=.*/", "CUSTOM_IMAGE_TITLE=$custom_image_label", $contents2);
+ }
+ }
+
$fh = fopen('/etc/birdnet/birdnet.conf', "w");
$fh2 = fopen("./scripts/thisrun.txt", "w");
fwrite($fh, $contents);
@@ -301,6 +317,12 @@ foreach($formats as $format){
<label for="raw_spectrogram">Minimalist Spectrograms: </label>
<input type="checkbox" name="raw_spectrogram" <?php if($newconfig['RAW_SPECTROGRAM'] == 1) { echo "checked"; };?> ><br>
+ <label for="custom_image">Custom Image Absolute Path: </label>
+ <input name="custom_image" type="text" value="<?php print($newconfig['CUSTOM_IMAGE']);?>"/><br>
+
+ <label for="custom_image_label">Custom Image Label: </label>
+ <input name="custom_image_label" type="text" value="<?php print($newconfig['CUSTOM_IMAGE_LABEL']);?>"/><br>
+
<h3>BirdNET-Lite Settings</h3>
<p>
diff --git a/scripts/install_config.sh b/scripts/install_config.sh
index f5e36982..cdc386bc 100755
--- a/scripts/install_config.sh
+++ b/scripts/install_config.sh
@@ -233,6 +233,13 @@ SILENCE_UPDATE_INDICATOR=0
RAW_SPECTROGRAM=0
+## CUSTOM_IMAGE and CUSTOM_IMAGE_TITLE allow you to show a custom image on the
+## Overview page of your BirdNET-Pi. This can be used to show a dynamically
+## updating picture of your garden, for example.
+
+CUSTOM_IMAGE=
+CUSTOM_IMAGE_TITLE=
+
## These are just for debugging
LAST_RUN=
THIS_RUN=
diff --git a/scripts/overview.php b/scripts/overview.php
index 477ba53a..d045fcbe 100644
--- a/scripts/overview.php
+++ b/scripts/overview.php
@@ -23,6 +23,20 @@ $user = shell_exec("awk -F: '/1000/{print $1}' /etc/passwd");
$home = shell_exec("awk -F: '/1000/{print $6}' /etc/passwd");
$home = trim($home);
+if(isset($_GET['custom_image'])){
+ if(isset($config["CUSTOM_IMAGE"])) {
+ ?>
+ <br>
+ <h3><?php echo $config["CUSTOM_IMAGE_TITLE"]; ?></h3>
+ <?php
+ $image_data = file_get_contents($config["CUSTOM_IMAGE"]);
+ $image_base64 = base64_encode($image_data);
+ $img_tag = "<img src='data:image/png;base64," . $image_base64 . "'>";
+ echo $img_tag;
+ }
+ die();
+}
+
if(isset($_GET['fetch_chart_string']) && $_GET['fetch_chart_string'] == "true") {
$myDate = date('Y-m-d');
$chart = "Combo-$myDate.png";
@@ -294,8 +308,11 @@ if (file_exists('./Charts/'.$chart)) {
$refresh = $config['RECORDING_LENGTH'];
$time = time();
echo "<img id=\"spectrogramimage\" src=\"/spectrogram.png?nocache=$time\">";
+
?>
+<div id="customimage"></div>
+
</div>
</div>
@@ -372,6 +389,24 @@ window.addEventListener("load", function(){
window.setInterval(function(){
document.getElementById("spectrogramimage").src = "/spectrogram.png?nocache="+Date.now();
}, <?php echo $refresh; ?>*1000);
+
+<?php if(isset($config["CUSTOM_IMAGE"])){?>
+// every 1 second, this loop will run and refresh the custom image
+window.setInterval(function(){
+ // Find the customimage element
+ var customimage = document.getElementById("customimage");
+
+ function updateCustomImage() {
+ var xhr = new XMLHttpRequest();
+ xhr.open("GET", "overview.php?custom_image=true", true);
+ xhr.onload = function() {
+ customimage.innerHTML = xhr.responseText;
+ }
+ xhr.send();
+ }
+ updateCustomImage();
+}, 1000);
+<?php } ?>
</script>
<style>
diff --git a/scripts/update_birdnet_snippets.sh b/scripts/update_birdnet_snippets.sh
index 560c9410..ff8a0173 100755
--- a/scripts/update_birdnet_snippets.sh
+++ b/scripts/update_birdnet_snippets.sh
@@ -174,5 +174,13 @@ if ! grep RAW_SPECTROGRAM /etc/birdnet/birdnet.conf &>/dev/null;then
sudo -u$USER echo "RAW_SPECTROGRAM=0" >> /etc/birdnet/birdnet.conf
fi
+if ! grep CUSTOM_IMAGE /etc/birdnet/birdnet.conf &>/dev/null;then
+ sudo -u$USER echo "CUSTOM_IMAGE=" >> /etc/birdnet/birdnet.conf
+fi
+if ! grep CUSTOM_IMAGE_TITLE /etc/birdnet/birdnet.conf &>/dev/null;then
+ sudo -u$USER echo "CUSTOM_IMAGE_TITLE=" >> /etc/birdnet/birdnet.conf
+fi
+
+
sudo systemctl daemon-reload
restart_services.sh