BirdNET-Pi Addon is fixed since Version 0.13.85. To show the Picture of the last detected Bird you need 0.13.86.
Now i have the same detections in home assistant as in BirdNET-Pi. MQTT sends now all detections. Yeah! Thanks Alex.
I have adjusted the Markdown map and now sort by number. I also have a map that shows the last bird identified. For the sake of completeness, here is everything again:
configuration.yaml
template: !include templates.yaml
templates.yaml
(If your templates.yaml
starts with sensor:
change this to - sensor:
)
- trigger:
- platform: mqtt
topic: birdnet
- platform: time
at: "00:00:00"
id: reset
sensor:
- name: BirdNET
unique_id: birdnet
state: "{{ today_at(trigger.payload_json.Time) }}"
icon: mdi:bird
attributes:
birds: >
{% if trigger.id == 'reset' %}
{{ [] }}
{% else %}
{% set date = trigger.payload_json.Date %}
{% set time = trigger.payload_json.Time %}
{% set scientificName = trigger.payload_json.ScientificName %}
{% set commonName = trigger.payload_json.CommonName %}
{% set confidence = ( trigger.payload_json.Confidence | round(2) * 100 ) | int() ~ '%' %}
{% set speciesCode = trigger.payload_json.SpeciesCode %}
{% set clipName = trigger.payload_json.ClipName %}
{% set url = trigger.payload_json.url.replace('en.', 'de.') %}
{% set flickrImage = trigger.payload_json.FlickrImage %}
{% set current = this.attributes.get('birds', []) %}
{% set new = dict(time=time, scientificName=scientificName, commonName=commonName, confidence=confidence, speciesCode=speciesCode, clipName=clipName, url=url, flickrImage=flickrImage) %}
{{ current + [new] }}
{% endif %}
Markdown Card with Bird-List (sorted by count)
{%- if states('sensor.birdnet') != "unavailable" %}
{%- set bird_species = state_attr('sensor.birdnet','birds') | sort(attribute='time', reverse=true) | map(attribute='commonName') | unique() | list() %}
{%- set bird_objects = state_attr('sensor.birdnet', 'birds') | sort(attribute='time', reverse=true) %}
{%- set ns = namespace(birds_data=[]) %}
{%- for bird_s in bird_species %}
{%- set bird_o = ((bird_objects | selectattr("commonName", "equalto", bird_s)) | list)[0] %}
{%- set bird_o_count = ((bird_objects | selectattr("commonName", "equalto", bird_s)) | list) | length %}
{%- set bird_o_max_confidence = ((bird_objects | selectattr("commonName", "equalto", bird_s)) | map(attribute='confidence') | max) %}
{%- set bird_entry = {
'time': bird_o.time,
'commonName': bird_o.commonName,
'speciesCode': bird_o.speciesCode,
'url': bird_o.url,
'count': bird_o_count,
'max_confidence': bird_o_max_confidence
} %}
{%- set ns.birds_data = ns.birds_data + [bird_entry] %}
{%- endfor %}
{%- set birds_sorted = ns.birds_data | sort(attribute='count', reverse=true) %}
Zuletzt | Wer (eBird) | Wiki | Wie oft | max.
:-:|:-|:-:|-:|:-:
{%- for bird in birds_sorted %}
{{ bird.time }} | [{{ bird.commonName }}](https://ebird.org/species/{{ bird.speciesCode }}) | [⧉]({{ bird.url }}) | {{ bird.count }} | {{ bird.max_confidence }}
{%- endfor %}
{{ bird_objects | count }} Erkennungen
{{ bird_species | count }} Arten
{%- else %}
Noch keine Erkennung vorhanden.
{%- endif %}
Markdown Card with Picture of the last detected Bird
{%- if states('sensor.birdnet') != "unavailable" %}
{%- set bird_objects = state_attr('sensor.birdnet', 'birds') | sort(attribute='time', reverse=true) | list() %}
{%- set last_bird = bird_objects[0] %}
![{{ last_bird.commonName }}]({{ last_bird.flickrImage }})
{%- else %}
Noch keine Erkennung vorhanden.
{%- endif %}
Thanks to you all.