jhansche / ha-birdbuddy

Home Assistant integration for Bird Buddy smart bird feeders
MIT License
45 stars 2 forks source link

Surface last-seen media #4

Closed jhansche closed 1 year ago

jhansche commented 1 year ago

With v0.0.4, we added bird collections to the Media browser.

We also get thumbnail and photo info when a new postcard arrives (even if we haven't added it to a collection yet). Using this information we can download the latest postcard images as they arrive, and if we save it as a single filename, then its location can be predictable and could be surfaced with a local media URI.

As of v0.0.5, we do now have events and device triggers, so it is possible to do this now on your own, with an automation that calls download_file, using data_template to extract the URL from the event trigger (this is untested currently):

action:
  - service: downloader.download_file
    data:
      url: "{{ trigger.event.data.sighting.medias[0].contentUrl }}"
      subdir: "birdbuddy"
      filename: "last_postcard.jpg"
      overwrite: True

cc @Snille

Snille commented 1 year ago

Woho!! Thank you! :) I just got the "beta" option now! :) Downloading and setting it up!

Happy new year!! :)

Snille commented 1 year ago

You are moving fast! Thank you. :) I guess the above automation can be updated? This is what I did (not tested yet)...

alias: Bird Buddy - Postcard
description: Bird Buddy is sending a postcard.
trigger:
  - platform: device
    device_id: <my id>
    domain: birdbuddy
    type: new_postcard
    feeder_id: <my id>
condition: []
action:
  - service: birdbuddy.collect_postcard
    data:
      strategy: best_guess
      best_guess_confidence: 10
      postcard: "{{ trigger.event.data.postcard }}"
      sighting: "{{ trigger.event.data.sighting }}"
  - service: downloader.download_file
    data:
      url: "{{ trigger.event.data.sighting.medias[0].contentUrl }}"
      subdir: birdbuddy
      filename: last_postcard.jpg
      overwrite: true
mode: single

Not sure if the collect part is necessary? Just wating for a bird to show... :) Also, fyi, the "data_template" is only "data" now days in HA. :)

jhansche commented 1 year ago

Also, fyi, the "data_template" is only "data" now days in HA. :)

Cool, good to know 👍

Not sure if the collect part is necessary?

The collect_postcard service would attempt to save the new postcard to the Bird Buddy Collections. If you don't do that part, then the new postcard not get moved to the Collections, so you would not be able to see the images in the Media Browser. If you prefer to leave that as a manual step however, you can continue to use the mobile app to open and collect postcards, and as long as you do it from the same email+pass user account as the integration, then anything you collect in the mobile app will appear in the HA Media collections as well (and vice versa).

The intent of the collect_postcard service is for people who do not want to have to go through the process of reviewing every new bird photo, accepting the recognized species, fixing the species, and so on.

I would recommend disabling the collect_postcard action for now, until you see how the postcard behavior works in the mobile app. If you find that you are often accepting the recognized species and don't have to make changes, and you find that process to be tedious, then you can reenable the service. But if you find that you enjoy the whimsy of opening the postcard in the app, or you find that you often have to manually select or fix the species in the app, then there's no need to use the service. You can still use the automation to download those last_postcard.jpg images, without affecting the postcard or sightings that you'll continue to be able to process in the app.

jhansche commented 1 year ago

So, I was able to add a new "Recent Visitor" sensor, which has state=bird species, and entity_picture points to the BB media URL. However, the picture-entity card does not seem to work the way I expected it should: there are only 2(3) ways to get an image to show in picture-entity:

It does not seem possible to pull the image directly from the entity's entity_picture attribute (which is documented here).

I added some notes and screenshots in the community thread

jhansche commented 1 year ago

For now I'm going to move forward with #16 which only adds the entity_picture thumbnail to the recent-visitor entity.

The good news is if you still want to use downloader to host the latest_visitor.jpg image, you will be able to drive your automation from changes to that entity's state, rather than having to hook into the new-postcard trigger. That's only a minor improvement, because new-postcard will only trigger with the next postcard, while the recent-visitor sensor is also going to attempt to load the latest collection/media on startup as well. The URL to download will be available as entity_picture.

There are definitely improvements that can be made, and I'm sure those will come.

The new attribute will be disabled by default (as many of them are).