Hi everyone! I’ve been diving into the fascinating world of bird detection and integrating it with Home Assistant. It’s been an exciting journey, and I wanted to share my experience and some tips for anyone looking to embark on a similar project.
I recently came across the Birdweather PUC, a self-contained microphone array that detects bird calls and connects to a cloud-based database. While it’s a bit pricey, the functionality it offers is truly impressive. The device uses APIs to send data to an iOS app, which then updates almost in real time. I decided to bring this data into Home Assistant to create a custom dashboard showcasing the latest bird detections.
Step 1: Getting Started
First, I reached out to Tim at Birdweather.com for an API token. After a quick email exchange, I was all set to start integrating the data. The next step was modifying my Home Assistant configuration to include the new sensors. I used the REST API for simplicity, as it seemed more straightforward than the GraphQL option.
Step 2: Configuring Sensors
I ended up creating two REST sensors: one to retrieve the top 50 bird species detected in the past day and another for the most recent detection. Here’s a snippet of the configuration:
yaml
sensor:
-
platform: rest
name: Top 50 Bird Species
resource: https://app.birdweather.com/api/v1/stations/{token}/species/?period=day&limit=50
value_template: “{{ value_json.species[0].commonName }}”
json_attributes: [species] -
platform: rest
name: Latest Bird Detection
resource: https://app.birdweather.com/api/v1/stations/{token}/detections/?limit=1
value_template: >
{% if value_json.detections and value_json.detections | length > 0 %}
{{ value_json.detections[0].species.commonName }}
{% else %}
No detections
{% endif %}
json_attributes: [detections]
Step 3: Creating the Dashboard
After setting up the sensors, the real challenge was figuring out how to display the data on a dashboard. I wanted to create separate sensors for each of the top 10 detected species. While it was a bit tedious, I managed to do this by defining each sensor individually. Here’s an example of how I structured one of them:
yaml
template:
- sensor:
- name: “Top Bird Species 0”
state: >
{{ state_attr(‘sensor.top_50_bird_species’, ‘species’)[0][‘commonName’] if state_attr(‘sensor.top_50_bird_species’, ‘species’) is defined and state_attr(‘sensor.top_50_bird_species’, ‘species’)|length > 0 else ‘Unknown’ }}
attributes:
ImageURL: >
{{ state_attr(‘sensor.top_50_bird_species’, ‘species’)[0][‘imageUrl’] if state_attr(‘sensor.top_50_bird_species’, ‘species’) is defined and state_attr(‘sensor.top_50_bird_species’, ‘species’)|length > 0 else ‘Unknown’ }}
id: >
{{ state_attr(‘sensor.top_50_bird_species’, ‘species’)[0][‘id’] if state_attr(‘sensor.top_50_bird_species’, ‘species’) is defined and state_attr(‘sensor.top_50_bird_species’, ‘species’)|length > 0 else ‘Unknown’ }}
detections: >
{{ state_attr(‘sensor.top_50_bird_species’, ‘species’)[0][‘detections’] if state_attr(‘sensor.top_50_bird_species’, ‘species’) is defined and state_attr(‘sensor.top_50_bird_species’, ‘species’)|length > 0 else ‘Unknown’ }}
last_detection_time: >
{{ state_attr(‘sensor.top_50_bird_species’, ‘species’)[0][‘latestDetectionAt’] if state_attr(‘sensor.top_50_bird_species’, ‘species’) is defined and state_attr(‘sensor.top_50_bird_species’, ‘species’)|length > 0 else ‘Unknown’ }}
- name: “Top Bird Species 0”
Step 4: Designing the Dashboard
For the dashboard, I opted for a simple markdown card setup. I used a fresh page on my iPad Pro to display the information. Here’s a snippet of the dashboard configuration:
yaml
- path: bird-dash
type: sections
sections:- type: grid
cards:- type: markdown
content: |+Latest Detection
[0][‘species’][‘imageUrl’] }}){{ states(‘sensor.latest_bird_detection’) }}
{% set raw_timestamp = state_attr(‘sensor.latest_bird_detection’, ‘detections’)[0][‘timestamp’] %}
{% set timestamp = strptime(raw_timestamp, ‘%Y-%m-%dT%H:%M:%S.%f%z’) %}{{ timestamp.strftime(‘%B %d, %I:%M %p’) }}
title: Today’s Top 10 Detected Birds
- type: markdown
- type: grid
Final Thoughts
This project has been a great learning experience, and I’m excited to see how it evolves. While there’s definitely room for improvement, especially in making the sensor setup more dynamic, the current setup provides a solid foundation. I hope this guide inspires others to explore the intersection of nature and smart home technology!
Cheers! ![]()