Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed weekly report week number calculation to match ISO 8601 week definition #80

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

rsiv
Copy link

@rsiv rsiv commented Apr 4, 2024

January 1st belongs to the last week of the previous year if it falls on Friday, Saturday or Sunday.
This caused an incorrect week in the date selector and showed an empty report for the next week.

Big thanks for this project!
I've got an automation set up to send out a report every evening listing all the bird species identified, and it's been a real hit.

…finition

January 1st belongs to the last week of the previous year if it falls on Friday, Saturday or Sunday
This caused an incorrect week in the date selector and showed an empty report for the next week
@Nelluk
Copy link

Nelluk commented Apr 4, 2024

I've got an automation set up to send out a report every evening listing all the bird species identified, and it's been a real hit.

Can you share any details on how you accomplished that? I'd love to do the same thing. I have BirdCage connected to my HomeAssistant via MMQT but not really sure what I can do with that incoming data.

@rsiv
Copy link
Author

rsiv commented Apr 4, 2024

@Nelluk with MQTT you can send a notification each time a bird is detected, but that resulted in too much noise.

So I added a command line sensor that gets the daily report from BirdCAGE API.
The sensor state is today's species count and the attribute birds holds the species list:

command_line:
  - sensor:
      name: Birds detected today
      unique_id: birds_detected_today
      icon: mdi:bird
      command: "curl -Ss https://birdcage-api.xxx/api/detections/date_range_report/{{ now().strftime('%Y-%m-%d') }}/{{ now().strftime('%Y-%m-%d') }} | jq 'map(.common_name) | sort' | jq '{birds: . }'"
      value_template: "{{ value_json.birds | length }}"
      json_attributes:
        - birds

This could be done with a rest_sensor instead, but that would require some changes to the json structure in the API.
Make sure you change https://birdcage-api.xxx above to match your API_SERVER_URL.

Next, I have an automation that sends a report every evening at 10 pm:

alias: Birds report
trigger:
- platform: time
  at: '22:00:00'
condition: []
action:
- service: notify.xxx
  data:
    title: "\U0001F99C Birds report ({{ states('sensor.birds_detected_today') }} species) - {{ as_timestamp(states('sensor.date_time_iso')) | timestamp_custom('%a, %b %-d, %Y') }}"
    message: "{{ state_attr('sensor.birds_detected_today', 'birds') | join('\n') }}"

The date in the title requires this sensor, you can just remove it instead:

sensor:
  - platform: time_date
    display_options:
      - "date_time_iso"

Here is a sample report. Pretty sure it's too early for Baltimore Oriole and some others here, I'm still tuning the confidence level.

🦜 Birds report (23 species) - Mon, Apr 1, 2024
American Crow
American Robin
Baltimore Oriole
Blue Jay
Brown Thrasher
Canada Goose
Common Raven
Downy Woodpecker
Eastern Bluebird
Fish Crow
Great Crested Flycatcher
House Finch
Mourning Dove
Northern Cardinal
Northern Flicker
Northern Mockingbird
Red-bellied Woodpecker
Red-shouldered Hawk
Red-tailed Hawk
Red-winged Blackbird
Tufted Titmouse
White-breasted Nuthatch
White-throated Sparrow

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants