Coder Social home page Coder Social logo

ha-google-photos's Introduction

Google Photos Integration for Home Assistant

GitHub Release GitHub Activity License

hacs Project Maintenance BuyMeCoffee

Discord Community Forum

This integration allows you to add albums from your Google Photos account as a camera entity to your Home Assistant setup. The entity will be showing media from your Google Photo album so you can add some personalization to your dashboards.

This component will set up the following platforms.

For each selected album:

Platform Name Description
camera media An image from the Google Photos Album.
sensor filename Filename of the currently selected media item.
sensor creation_timestamp Timestamp of the currently selected media item.
sensor media_count Counter showing the number of media items in the album (photo + video). It could take a while to populate all media items, to check if the integration is still loading an attribute is_updating is available.
select image_selection_mode Configuration setting on how to pick the next image.
select crop_mode Configuration setting on how to crop the image, either Original, Crop or Combine images (explanation).
select update_interval Configuration setting on how often to update the image, if you have a lot of albums running on your instance it is adviseable to not set this to low.

example

Installation

HACS (Once available)

  1. Find the integration as Google Photos
  2. Click install.
  3. Restart Home Assistant.

Manual

  1. Using the tool of choice open the directory (folder) for your HA configuration (where you find configuration.yaml).
  2. If you do not have a custom_components directory (folder) there, you need to create it.
  3. In the custom_components directory (folder) create a new folder called google_photos.
  4. Download all the files from the custom_components/google_photos/ directory (folder) in this repository.
  5. Place the files you downloaded in the new directory (folder) you created.
  6. Restart Home Assistant

Configuration

  1. In the HA UI go to "Configuration" -> "Integrations" click "+" and search for "Google Photos".
  2. Generate a Client ID and Client Secret on Google Developers Console. The authentication procedure in this integration is based of the Google Mail integration.
    1. First, go to the Google Developers Console to enable Photos Library API
    2. The wizard will ask you to choose a project to manage your application. Select a project and click continue.
    3. Verify that your Photos Library API was enabled and click ‘Go to credentials’
    4. Navigate to APIs & Services (left sidebar) > Credentials
    5. Click on the field on the left of the screen, OAuth Consent Screen.
    6. Select External and Create.
    7. Set the App Name (the name of the application asking for consent) to anything you want, e.g., Home Assistant.
    8. You then need to select a Support email. To do this, click the drop-down box and select your email address.
    9. You finally need to complete the section: Developer contact information. To do this, enter your email address (the same as above is fine).
    10. Scroll to the bottom and click Save and Continue. You don’t have to fill out anything else, or it may enable additional review.
    11. You will then be automatically taken to the Scopes page. You do not need to add any scopes here, so click Save and Continue to move to the Optional info page. You do not need to add anything to the Optional info page, so click Save and Continue, which will take you to the Summary page. Click Back to Dashboard.
    12. Click OAuth consent screen again and set Publish Status to Production otherwise your credentials will expire every 7 days.
    13. Make sure Publishing status is set to production.
    14. Click Credentials in the menu on the left-hand side of the screen, then click Create credentials (at the top of the screen), then select OAuth client ID.
    15. Set the Application type to Web application and give this credential set a name (like “Home Assistant Credentials”).
    16. Add https://my.home-assistant.io/redirect/oauth to Authorized redirect URIs then click Create. 1/ You will then be presented with a pop-up saying OAuth client created showing Your Client ID and Your Client Secret. Make a note of these (for example, copy and paste them into a text editor), as you will need these shortly. Once you have noted these strings, click OK. If you need to find these credentials again at any point, then navigate to APIs & Services > Credentials, and you will see Home Assistant Credentials (or whatever you named them in the previous step) under OAuth 2.0 Client IDs. To view both the Client ID and Client secret, click on the pencil icon; this will take you to the settings page for these credentials, and the information will be on the right-hand side of the page.
    17. Double-check that the Photos Library API has been automatically enabled. To do this, select Library from the menu, then search for Photos Library API. If it is enabled you will see API Enabled with a green tick next to it. If it is not enabled, then enable it.
  3. Provide the integration with a client id and client secret to use with th Google Photos Library api. If you want to change the credentials, go to Open your Home Assistant instance and Manage your application credentials..
  4. Continue through the steps of selecting the account you want to authorize.
  5. NOTE: You may get a message telling you that the app has not been verified and you will need to acknowledge that in order to proceed.
  6. You can now see the details of what you are authorizing Home Assistant to access with two options at the bottom. Click Continue.
  7. The page will now display Link account to Home Assistant?, note Your instance URL. If this is not correct, please refer to My Home Assistant. If everything looks good, click Link Account.
  8. You may close the window, and return back to Home Assistant where you should see a Success! message from Home Assistant.

After the setup is complete a device will be created with entity for your favorite photos. To add more albums from you account, click configure on the integration card.

Example setup

Screenshots:

Crop modes

Original

Provides scaled down images that would fit in the requested view in the original aspect ratio. If your dashboard configuration does not specify the aspect ratio, the card size could change for every image.

Crop

Crop image to fit into the requested view.

Combine images

In combine images mode, the integration will combine two images of the same orientation if it calculates that showing two images side by side would lead to a lower loss in square pixels than cropping a single image. For example; two portrait images on a landscape view.

Examples

Dashboard Picture card

show_state: false
show_name: false
camera_view: auto
type: picture-entity
entity: camera.google_photos_library_favorites
aspect_ratio: '1:1'
tap_action:
  action: call-service
  service: google_photos.next_media
  data:
    mode: RANDOM
  target:
    entity_id: camera.google_photos_library_favorites

Lovelace wall panel

You can combine this integration with the lovelace-wallpanel (min version 4.8) extension by j-a-n to show your photos as a screensaver on your dashboards. For the best results set the crop mode of the album to Crop or Combine images.

Home Assistant Dashboard configuration yaml (raw config):

wallpanel:
  enabled: true
  hide_toolbar: true
  hide_sidebar: true
  fullscreen: true
  image_fit: cover
  image_url: media-entity://camera.google_photos_favorites_media,
  cards:
      # Note: For this markdown card to work you need to enable write metadata in the integration settings.
    - type: markdown
      content: >-
        {{states.camera.google_photos_favorites_media.attributes.media_metadata.photo.cameraMake}},
        {{states.camera.google_photos_favorites_media.attributes.media_metadata.photo.cameraModel}}

Important Make sure to align the image crop modes with the configuration of the wall panel, if not set correctly images might appear blurry. For crop mode original, set the image_fit property to contain.

Service

It is possible to control the album using the service exposed by google_photos.

Go to next media

Example

service: google_photos.next_media
data:
  entity_id: camera.google_photos_library_favorites
  mode: Random

Key Descriptions

Key Required Default Description
entity_id Yes Entity name of a Google Photo album camera.
mode No Random Selection mode next image, either Random or Album order

FAQ

How can I change my credentials? / I entered the wrong credentials now what?

Go to Open your Home Assistant instance and Manage your application credentials. (or click the 3 dot menu on the integrations screen), here you can delete the credentials, the setup flow will ask for new credentials again when setting up the integration.

Why is it always loading the same image after loading the integration?

This is the cover photo of you album, you can change it in Google Photos, or trigger a next_media on the service after start-up.

Notes / Remarks / Limitations

  • Currently the album media list is cached for 3 hours.
  • Directly after loading the integration / starting HA, the album will only contain 100 items. This is done to reduce server load on the Google Photos servers, every 30 seconds a new batch of media is requested.

Future plans

  • Give end user more control over album cache time
  • Support for videos
  • Support loading media using content categories
  • Support loading media filtered by date/time
  • Custom photo carousel fronted component
  • Add trigger on new media

Debug Logging

To enable debug log, add the following lines to your configuration.yaml and restart your HomeAssistant.

logger:
  default: info
  logs:
    custom_components.google_photos: debug
    googleapiclient: debug

Contributions are welcome!

If you want to contribute to this please read the Contribution guidelines


ha-google-photos's People

Contributors

alray31 avatar daanoz avatar thekirankumar avatar viper5000 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

ha-google-photos's Issues

Access blocked: the request of this app is not valid

Solved : I could not reuse the old settings because that was not configured as a webapplication

I try to install this integration.

I allready had a google id with credentials for home assistant . So I added the google photo api to that.
After downloading the integration in home assistant and restarting HASS I want to add the integration.
When I add name and credentials I click continue. The error I get is : You cannot login because this app send a invalid request. Try again later or send a message to the developer about this problem.

Error:400: redirect_uri_mismatch

I am not sure I use the correct name, but I suppose I have to use OAuth 2.0 Client IDs name ?
Tried the name on the Oauth consent screen too

Version Home assistant
Home Assistant 2023.9.2
Supervisor 2023.10.0
Operating System 10.5
Frontend 20230911.0 - latest
I am running Home Assistant on a virtual machine

I am sorry when this topic does not meet all requirement to add a new issue but I am hoping this information is enough to solve this problem

Generic Error

After installing the integration from HACS and attempting to add the integration, I get to the final step when I link it to my home assistant url I select the link and then I get a popup that says "Error". Any help would be greatly appreciated as I am really excited to get this integration working!

image

Here is the only log I am finding;

This error originated from a custom integration.

Logger: aiohttp.server
Source: custom_components/google_photos/config_flow.py:87
Integration: Google Photos (documentation, issues)
First occurred: 1:00:08 PM (2 occurrences)
Last logged: 1:04:42 PM

Error handling request
Traceback (most recent call last):
File "/usr/local/lib/python3.10/site-packages/aiohttp/web_protocol.py", line 433, in _handle_request
resp = await request_handler(request)
File "/usr/local/lib/python3.10/site-packages/aiohttp/web_app.py", line 504, in _handle
resp = await handler(request)
File "/usr/local/lib/python3.10/site-packages/aiohttp/web_middlewares.py", line 117, in impl
return await handler(request)
File "/usr/src/homeassistant/homeassistant/components/http/security_filter.py", line 67, in security_filter_middleware
return await handler(request)
File "/usr/src/homeassistant/homeassistant/components/http/forwarded.py", line 227, in forwarded_middleware
return await handler(request)
File "/usr/src/homeassistant/homeassistant/components/http/request_context.py", line 28, in request_context_middleware
return await handler(request)
File "/usr/src/homeassistant/homeassistant/components/http/ban.py", line 80, in ban_middleware
return await handler(request)
File "/usr/src/homeassistant/homeassistant/components/http/auth.py", line 234, in auth_middleware
return await handler(request)
File "/usr/src/homeassistant/homeassistant/components/http/view.py", line 146, in handle
result = await result
File "/usr/src/homeassistant/homeassistant/components/config/config_entries.py", line 171, in get
return await super().get(request, flow_id)
File "/usr/src/homeassistant/homeassistant/helpers/data_entry_flow.py", line 96, in get
result = await self._flow_mgr.async_configure(flow_id)
File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 271, in async_configure
result = await self._async_handle_step(
File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 367, in _async_handle_step
result: FlowResult = await getattr(flow, method)(user_input)
File "/usr/src/homeassistant/homeassistant/helpers/config_entry_oauth2_flow.py", line 332, in async_step_creation
return await self.async_oauth_create_entry(
File "/config/custom_components/google_photos/config_flow.py", line 99, in async_oauth_create_entry
(await self.hass.async_add_executor_job(_check_photoslibrary_access))
File "/usr/local/lib/python3.10/concurrent/futures/thread.py", line 58, in run
result = self.fn(*self.args, **self.kwargs)
File "/config/custom_components/google_photos/config_flow.py", line 87, in _check_photoslibrary_access
lib = build(
File "/usr/local/lib/python3.10/site-packages/oauth2client/_helpers.py", line 133, in positional_wrapper
return wrapped(*args, **kwargs)
TypeError: build() got an unexpected keyword argument 'static_discovery'

Google Photos are no longer loaded after approx. 1 day.

Hello,

after I set up Google Photos again, everything works for about 1 day and the pictures are displayed. After approx. 1 day. no more pictures are displayed. No error message or similar appears. I have already set up google photos several times and even created new login details.

Unfortunately I have not found any other case for this problem. Can anyone here help me?

Error on creating the integration

When trying to set up the integration on my HA, I search under "Add Integration" for "Google Photos", I inputted my oauth credentials, and then a popup appears from google saying that there was a Error 400: redirect_uri_mismatch.

image

Am I doing something wrong?

Thank you!

API error 429 - Quota exceeded

Version of the custom_component

v0.6.2

Describe the bug

I have the update interval set at 10 seconds and crop mode set as Combine, and this uses up all the request quota of the Photos API in around 15 hours (Photos API allows 10,000 requests per day). Is there any way to reduce the number of API calls that are happening without increasing the update interval, so I can keep it running 24/7 please? Any more caching that could be implemented?

The error handling around this also isn't great. It starts spamming the logs with the below error even after I set the update interval to Never.

Debug log


2024-04-14 00:38:33.201 ERROR (MainThread) [aiohttp.server] Error handling request
Traceback (most recent call last):
  File "/usr/local/lib/python3.12/site-packages/aiohttp/web_protocol.py", line 452, in _handle_request
    resp = await request_handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aiohttp/web_app.py", line 543, in _handle
    resp = await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aiohttp/web_middlewares.py", line 114, in impl
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/security_filter.py", line 92, in security_filter_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/forwarded.py", line 83, in forwarded_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/request_context.py", line 26, in request_context_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/ban.py", line 88, in ban_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/auth.py", line 236, in auth_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/headers.py", line 32, in headers_middleware
    response = await handler(request)
               ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/http.py", line 73, in handle
    result = await handler(request, **request.match_info)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/camera/__init__.py", line 823, in get
    return await self.handle(request, camera)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/camera/__init__.py", line 841, in handle
    image = await _async_get_image(
            ^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/camera/__init__.py", line 192, in _async_get_image
    else await camera.async_camera_image(width=width, height=height)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/google_photos/camera.py", line 145, in async_camera_image
    return await self.coordinator.get_media_data(width, height)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/google_photos/coordinator.py", line 262, in get_media_data
    result = await self._get_combined_media_data(width, height)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/google_photos/coordinator.py", line 309, in _get_combined_media_data
    await self._get_media_by_id(secondary_media.get("id")),
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/google_photos/coordinator.py", line 349, in _get_media_by_id
    return await self.hass.async_add_executor_job(_get_media_item)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/google_photos/coordinator.py", line 347, in _get_media_item
    return service.mediaItems().get(mediaItemId=media_id).execute()
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/googleapiclient/_helpers.py", line 130, in positional_wrapper
    return wrapped(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/googleapiclient/http.py", line 938, in execute
    raise HttpError(resp, content, uri=self.uri)
googleapiclient.errors.HttpError: <HttpError 429 when requesting https://photoslibrary.googleapis.com/v1/mediaItems/AGd-TmPZTJYyIJTBT6e70Ohn1n1qXRf2H_SQstaTN7rxtNfKOrN_-ojM8cF-2W9OXYVW40PpCNbf5GxDPw_mY1NE_9vwY77bnQ?alt=json returned "Quota exceeded for quota metric 'All requests' and limit 'All requests per day' of service 'photoslibrary.googleapis.com' for consumer 'project_number:608688248141'.". Details: "[{'@type': 'type.googleapis.com/google.rpc.ErrorInfo', 'reason': 'RATE_LIMIT_EXCEEDED', 'domain': 'googleapis.com', 'metadata': {'quota_metric': 'photoslibrary.googleapis.com/all_requests', 'quota_limit_value': '10000', 'quota_location': 'global', 'consumer': 'projects/608688248141', 'service': 'photoslibrary.googleapis.com', 'quota_limit': 'ApiCallsPerProjectPerDay'}}, {'@type': 'type.googleapis.com/google.rpc.Help', 'links': [{'description': 'Request a higher quota limit.', 'url': 'https://cloud.google.com/docs/quota#requesting_higher_quota'}]}]">


Change credentials (client ID & Client Secret) #Question

I submitted by error different google API credentials, it means, another client ID & Client Secret.
If you desinstall and re install the integration, in somewhere was saved the credentials and it's not possible to update to the correct ones.

Now when I search the NEW integration and select google photos, this is the first page:
image

and, of course, since the project is incorrect (this project has been deleted), google returns an error:
image

what I want to do is to have the original first page when credentials are requested and insert now the correct Client ID & Client Secret.

Add support for rotating google photo as background when cast to google nest hub

Is your feature request related to a problem? Please describe.
I've successfully set up this google photos album integration to pull a random image and show it as a dashboard background using wallpanel. It works perfectly when viewing in a web browser, but when I cast it to a google nest hub using HA's built in casting functionality, the background image does not display on a nest hub. It appears that the google nest hub does not allow for the same type of link that the google photo album entity integration provides.

Describe the solution you'd like
Extend support for a rotating google photo to be used as a dashboard background image when casting to google nest hub

Describe alternatives you've considered
I've attempted to set a rotating google image as a background image in a dashboard view vs setting it as a wallpanel image. Neither solution works when casting to a google nest hub.

Here's the dashboard definition that works on a web browser but does not show a background image when cast to a nest hub.

`
wallpanel:
enabled: true
hide_toolbar: true
hide_sidebar: true
fullscreen: false
fade_in_time: 2
crossfade_time: 2
image_url: media-entity://camera.google_photos_foo_media
image_order: random
display_time: 300
show_images: true
image_background: image
image_animation_ken_burns: true
image_fit: contain
cards:
- type: custom:digital-clock
- initial_view: listWeek
type: calendar
entities:
- calendar.family
card_interaction: true
views:

  • title: Home
    cards:
    • type: custom:digital-clock
    • initial_view: listWeek
      type: calendar
      entities:
      • calendar.family
    • type: picture-entity
      entity: camera.google_photos_foo_media

`

Cannot create a new integration (error with dependenceies)

Version of the custom_component

v0.4.1

Configuration

There's no configuration to post. Installed via HACS, error occurs while trying to add the integration in settings.

Describe the bug

I'm running Home Assistant v2023.1.7 as a Docker container.

After installing the component via HACS, I tried to add a new integration via Settings / Devices & Services / + Add Integration, I see the error below in the logs regarding a conflict with pillow. The Google Photos integration specifies an exact version for pillow (9.4.0), while the Docker image for homeassistant has pillow 9.3.0 installed. The requirements_all.txt for homeassistant v2023.1.7 has pillow==9.3.0 specified, so that's the source of the conflicting requirement.

Debug log

2023-03-06 13:55:32.418 INFO (SyncWorker_58) [homeassistant.util.package] Attempting install of pillow==9.4.0
2023-03-06 13:55:32.402 ERROR (SyncWorker_58) [homeassistant.util.package] Unable to install package pillow==9.4.0: ERROR: Cannot install pillow==9.4.0 because these package versions have conflicting dependencies.
ERROR: ResolutionImpossible: for help visit https://pip.pypa.io/en/latest/topics/dependency-resolution/#dealing-with-dependency-conflicts
[notice] A new release of pip available: 22.3 -> 23.0.1
[notice] To update, run: pip install --upgrade pip

google photos unavailable

hi my google photos says that it is unavailable.
i have tried to restart home assistant without any luck.
it worked yesterday but today it dosent.

No image in app

I have this integration working fine on my desktop browser and even the HA app on my mac.

I get a nice display like so:
Screenshot 2023-06-21 at 16 03 54

but in the android app the image never loads:
Screenshot_2023-06-21-16-13-57-315_io homeassistant companion android

Any idea why that is ?

Not loading in HA 2023.8. 0b3

Cannot load in the newest version (beta)

Get the following log:

Logger: homeassistant.setup
Source: setup.py:209
First occurred: 17.47.01 (1 occurrences)
Last logged: 17.47.01

Setup failed for custom integration google_photos: Requirements for google_photos not found: ['pillow>=9.1.1,<10.0.0'].

Resolution does not scale with pixel density, resulting in blurry pictures on high-density screens

Hello!

I am using your (amazing) integration for my lovelace wallpanel screensaver on a Pixel Tablet.
I tried to troubleshoot why my pictures were blurry, and after some tests I believe it is because the integration is downloading pictures with a resolution based on the CSS resolution (1280x800) instead of the device pixel resolution (2560x1600)

I confirmed this by enabling the debug log and looking at the picture downloaded.

Is that something you can fix on your end? I'm not sure if it is an issue with camera entity in HA or with your camera code, as I do not know how the width/height of the screen is retrieved.
Either way, I'm open to suggestions if a fix is not possible in the integration.

Thanks!

Picture Entities with Google Photos pictures don't display correctly when the dashboard is casted via Google Cast

Home Assistant version: Home Assistant 2023.4.2
Plugin version: v0.5.0

The picture entity works fine when the dashboard is displayed via a browser or the mobile app. However, when it's casted pictures don't appear.

This issue only occurs with Google Photos picture entities, other picture entities work fine. I've tested this with my security cameras.

While trying to debug on the browser (where the image is displayed correctly), I noticed that the URL that is used to load the picture shows an error on the browser's developer tools. The type of the file is not recognized as an image.

After that, there's another request that has a type x-mixed-replace that apparently contains the image data. I'm not sure what else I can do to help debug.

Let me know if you have any questions.

Used wrong OAuth Credentials

Hello,

I was setting this up last night and in my tired state of mind, I accidently tried to link it to the wrong Google OAuth Credentials. Now when I try to redo the setup process it automatically links to the wrong creds and gives me the "Access blocked: This app’s request is invalid".

I have uninstalled the integration manually and via HA UI. I even tried to reset the OAuth credentials in the Google Cloud page, and nothing is allowing me to redo the OAuth Credential setup.

Any Ideas?

Version: v0.5.0

Choosing new album makes entities unavaible

Version of the custom_component

0.4.3

Configuration

Add your logs here.

Describe the bug

Adding the Integrations work fine, i can see the two test images i have in favorites. Changing to the desired album (name fotoram 210130 till 230325) submits as okey, but then all sensors become unavailble.

Debug log

Logger: homeassistant.components.select
Source: custom_components/google_photos/coordinator.py:67
Integration: Select (documentation, issues)
First occurred: 10:35:20 (1 occurrences)
Last logged: 10:35:20

Error while setting up google_photos platform for select
Traceback (most recent call last):
  File "/home/homeassistant/.homeassistant/custom_components/google_photos/coordinator.py", line 452, in _async_update_data
    await self.update_data()
  File "/home/homeassistant/.homeassistant/custom_components/google_photos/coordinator.py", line 366, in update_data
    await self._refresh_album_list()
  File "/home/homeassistant/.homeassistant/custom_components/google_photos/coordinator.py", line 435, in _refresh_album_list
    await self._get_album_list()
  File "/home/homeassistant/.homeassistant/custom_components/google_photos/coordinator.py", line 424, in _get_album_list
    self.album_list = await self.hass.async_add_executor_job(
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
asyncio.exceptions.CancelledError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/homeassistant/.homeassistant/custom_components/google_photos/coordinator.py", line 442, in _async_update_data
    async with async_timeout.timeout(30):
  File "/srv/homeassistant/venv_3.11.0/lib/python3.11/site-packages/async_timeout/__init__.py", line 129, in __aexit__
    self._do_exit(exc_type)
  File "/srv/homeassistant/venv_3.11.0/lib/python3.11/site-packages/async_timeout/__init__.py", line 212, in _do_exit
    raise asyncio.TimeoutError
TimeoutError

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/srv/homeassistant/venv_3.11.0/lib/python3.11/site-packages/homeassistant/helpers/update_coordinator.py", line 239, in _async_refresh
    self.data = await self._async_update_data()
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/homeassistant/.homeassistant/custom_components/google_photos/coordinator.py", line 454, in _async_update_data
    raise UpdateFailed(f"Error communicating with API: {err}") from err
homeassistant.helpers.update_coordinator.UpdateFailed: Error communicating with API: 

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/srv/homeassistant/venv_3.11.0/lib/python3.11/site-packages/homeassistant/helpers/entity_platform.py", line 293, in _async_setup_platform
    await asyncio.shield(task)
  File "/home/homeassistant/.homeassistant/custom_components/google_photos/select.py", line 34, in async_setup_entry
    coordinator = await coordinator_manager.get_coordinator(album_id)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/homeassistant/.homeassistant/custom_components/google_photos/coordinator.py", line 67, in get_coordinator
    await self.coordinator_first_refresh.get(album_id)
homeassistant.exceptions.ConfigEntryNotReady: Error communicating with API: 

Fails on Selecting Album

Version of the custom_component

0.4.4

Describe the bug

After CONFIGURE, and SELECT ALBUM, it spins for a second and then says "Error".

P.S. Thanks for the integration - it's great, and much cleaner than the brutal hack I was doing before.

Apr 01 17:01:23 archlinux hass[626391]: 2023-04-01 17:01:23.357 ERROR (MainThread) [aiohttp.server] Error handling request
Apr 01 17:01:23 archlinux hass[626391]: Traceback (most recent call last):
Apr 01 17:01:23 archlinux hass[626391]:   File "/srv/homeassistant/lib/python3.10/site-packages/aiohttp/web_protocol.py", line 433, in _handle_request
Apr 01 17:01:23 archlinux hass[626391]:     resp = await request_handler(request)
Apr 01 17:01:23 archlinux hass[626391]:   File "/srv/homeassistant/lib/python3.10/site-packages/aiohttp/web_app.py", line 504, in _handle
Apr 01 17:01:23 archlinux hass[626391]:     resp = await handler(request)
Apr 01 17:01:23 archlinux hass[626391]:   File "/srv/homeassistant/lib/python3.10/site-packages/aiohttp/web_middlewares.py", line 117, in impl
Apr 01 17:01:23 archlinux hass[626391]:     return await handler(request)
Apr 01 17:01:23 archlinux hass[626391]:   File "/srv/homeassistant/lib/python3.10/site-packages/homeassistant/components/http/security_filter.py", line 67, in security_filter_middleware
Apr 01 17:01:23 archlinux hass[626391]:     return await handler(request)
Apr 01 17:01:23 archlinux hass[626391]:   File "/srv/homeassistant/lib/python3.10/site-packages/homeassistant/components/http/forwarded.py", line 227, in forwarded_middleware
Apr 01 17:01:23 archlinux hass[626391]:     return await handler(request)
Apr 01 17:01:23 archlinux hass[626391]:   File "/srv/homeassistant/lib/python3.10/site-packages/homeassistant/components/http/request_context.py", line 28, in request_context_middleware
Apr 01 17:01:23 archlinux hass[626391]:     return await handler(request)
Apr 01 17:01:23 archlinux hass[626391]:   File "/srv/homeassistant/lib/python3.10/site-packages/homeassistant/components/http/ban.py", line 80, in ban_middleware
Apr 01 17:01:23 archlinux hass[626391]:     return await handler(request)
Apr 01 17:01:23 archlinux hass[626391]:   File "/srv/homeassistant/lib/python3.10/site-packages/homeassistant/components/http/auth.py", line 234, in auth_middleware
Apr 01 17:01:23 archlinux hass[626391]:     return await handler(request)
Apr 01 17:01:23 archlinux hass[626391]:   File "/srv/homeassistant/lib/python3.10/site-packages/homeassistant/components/http/view.py", line 146, in handle
Apr 01 17:01:23 archlinux hass[626391]:     result = await result
Apr 01 17:01:23 archlinux hass[626391]:   File "/srv/homeassistant/lib/python3.10/site-packages/homeassistant/components/config/config_entries.py", line 241, in post
Apr 01 17:01:23 archlinux hass[626391]:     return await super().post(request, flow_id)
Apr 01 17:01:23 archlinux hass[626391]:   File "/srv/homeassistant/lib/python3.10/site-packages/homeassistant/components/http/data_validator.py", line 72, in wrapper
Apr 01 17:01:23 archlinux hass[626391]:     result = await method(view, request, data, *args, **kwargs)
Apr 01 17:01:23 archlinux hass[626391]:   File "/srv/homeassistant/lib/python3.10/site-packages/homeassistant/helpers/data_entry_flow.py", line 110, in post
Apr 01 17:01:23 archlinux hass[626391]:     result = await self._flow_mgr.async_configure(flow_id, data)
Apr 01 17:01:23 archlinux hass[626391]:   File "/srv/homeassistant/lib/python3.10/site-packages/homeassistant/data_entry_flow.py", line 267, in async_configure
Apr 01 17:01:23 archlinux hass[626391]:     result = await self._async_handle_step(
Apr 01 17:01:23 archlinux hass[626391]:   File "/srv/homeassistant/lib/python3.10/site-packages/homeassistant/data_entry_flow.py", line 367, in _async_handle_step
Apr 01 17:01:23 archlinux hass[626391]:     result: FlowResult = await getattr(flow, method)(user_input)
Apr 01 17:01:23 archlinux hass[626391]:   File "/home/hassio/.homeassistant/custom_components/google_photos/config_flow.py", line 192, in async_step_albumselect
Apr 01 17:01:23 archlinux hass[626391]:     data_schema = await self._get_albumselect_schema()
Apr 01 17:01:23 archlinux hass[626391]:   File "/home/hassio/.homeassistant/custom_components/google_photos/config_flow.py", line 163, in _get_albumselect_schema
Apr 01 17:01:23 archlinux hass[626391]:     album["title"], album["mediaItemsCount"]
Apr 01 17:01:23 archlinux hass[626391]: KeyError: 'mediaItemsCount'

Get access to all the Albums as one entity

Is your feature request related to a problem? Please describe.
As for now, we have to create one set of entities for each album if we want access different albums. And so, we've got lots of different lovelace card that we can show or hide but it's not very convinient. It should include also the shared albums.

Describe the solution you'd like
A unique set of entities for all the selected (at integratoin level) albums with different options for the next media :

  • random through all the albums
  • random through the current album, then random through the next album (randomly choosen or sorted by date, name...) and so one
  • every picture of each album, then the same for the next album (randomly choosen or sorted by date, name...)
  • random through the selected album only (using an helper to choose it)
  • every picture of the selected album only (using an helper to choose it)

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Additional context
I don't use favorite. I prefer to create album for every occasions.

fails on selecting album

gives an error when trying to select an album no list is shown

2023-06-12 16:54:08.633 DEBUG (MainThread) [custom_components.google_photos.config_flow] async_albumselect_confirm called with user_input: None
2023-06-12 16:54:08.642 INFO (SyncWorker_15) [googleapiclient.discovery_cache] file_cache is only supported with oauth2client<4.0.0
2023-06-12 16:54:08.642 DEBUG (SyncWorker_15) [googleapiclient.discovery] URL being requested: GET https://www.googleapis.com/discovery/v1/apis/photoslibrary/v1/rest
2023-06-12 16:54:08.961 DEBUG (SyncWorker_15) [googleapiclient.discovery] URL being requested: GET https://photoslibrary.googleapis.com/v1/albums?pageSize=50&fields=albums%28id%2Ctitle%2CmediaItemsCount%29%2CnextPageToken&alt=json
2023-06-12 16:54:09.548 DEBUG (SyncWorker_15) [googleapiclient.discovery] Next page request URL: list_next https://photoslibrary.googleapis.com/v1/albums?pageSize=50&fields=albums%28id%2Ctitle%2CmediaItemsCount%29%2CnextPageToken&alt=json&pageToken=CkQKPnR5cGUuZ29vZ2xlYXBpcy5jb20vZ29vZ2xlLnBob3Rvcy5saWJyYXJ5LnYxLkxpc3RBbGJ1bXNSZXF1ZXN0EgIIMhLMAUFIX3VRNDNELXdhSmNBUzZDTUlJd0VHanRxSEJfQWlSUHQ1R0pQTkpNWkJtdHRJdGJfUWJxSnlzV1d1ZnU1NkM2N1FUSVkyZ3l3ZkhGSmNHbGl5MnRkNEl2T3h1NGhxRzNYMUpBc29rb1hqaERWaEZaWjc0b2N4UjJqdVNMcmNGSVQzM0hHeC1XMTUybVNPYzlEeFl5X0czZWxlQUwtUXllakZ5djc5a29WVTUzZmRGT2E1a00zTklMUUJNQkp6NER1T05i

Improve fallback resolution in Original mode

Hello,

I've experienced a strange behavior when using "Original" mode. On "Crop" mode it seems fine, pictures get cropped at the view container size, however on "Original" mode, pictures get resized to either the fallback width or height values (1024 x 512 px) (values in code. This leads to seriously blurry pictures.

I tried manually changing the values to 3000x3000 just to test, and indeed it now generates much clearer pictures.

Do you think it might be a good idea to increase these fallback values or would there be a reason not to?

Thanks a lot!

Failed to query google api: Internal error encountered

Hello all,

Running into an issue with this integration now, unfortunately.

It was working fine for the longest time, but then it ended up getting "Stuck" on a single photo. I decided to reload the integration and that's when it stopped working entirely.

I rebooted - no luck.
I then deleted the integration (including creds) and tried to re-add it. Now I'm getting a weird API related error.

The setup was done as per the documents, and as mentioned, was working fine previously.
The OAuth creds are correct, I just re-added them for the new setup of the integration.

I tried to create new OAuth Credentials, but still getting the same error...

image

Background Combos (2 in one)

I have zero idea how possible it is, but it'd be cool to have the ability to use your albums as a background and/or screensaver.
Also, (I may have missed this), but, maybe the possibility to combine albums into one "slideshow". I know you can have multiple cards/multiple albums, but a combine line would be nice; use_album: album1, album 2. I dunno. Anyways, great work. Cheers.

error while creating account

Hello,
I try to install the ha google photo plugin,
I followed the github procedure, I created a client with id and secret code, activated api, ...
all was fine until the oauth screen : when I click on my google account and accept the conditions, I receive this screen :

[https://www.googleapis.com/auth/userinfo.email&authuser=0&prompt=consent]

**

You are receiving this error either because your input OAuth2 scope name is invalid or it refers to a newer scope that is outside the domain of this legacy API.

This API was built at a time when the scope name format was not yet standardized. This is no longer the case and all valid scope names (both old and new) are catalogued at https://developers.google.com/identity/protocols/oauth2/scopes. Use that webpage to lookup (manually) the scope name associated with the API you are trying to call and use it to craft your OAuth2 request.

**

Version of the custom_component

latest

Can someone tell me what I did wrong?
Thanks in advance,
-->Michaël

Support offline usage, fetch and store entire album on disk

Is your feature request related to a problem? Please describe.

I'd like to show a carousel of Google Photos in my Home Assistant dashboard on my camper van while I'm traveling with intermittent connectivity.

Describe the solution you'd like

I'd like to push a button to have the integration synchronize an offline copy of a particular Google Photos album. Once that's done, all of the photos and their metadata would be retrieved from the local filesystem without hitting the network.

If the button is modeled as a home assistant entity, then I could also write an automation to periodically initiate a sync when the network is available under appropriate conditions.

Alternatively, the integration could download the photos directly into the home assistant Local Media directory.

Feature/Improvement - Verify Google Photos Library API is enabled during the inital config

Is your feature request related to a problem? Please describe.
If a user hasn't enabled Photos Library API prior to use a non-descript error is presented when selecting albums.
Add a verification of Google Photo API enabled while still in config flow for ease of use.

Describe the solution you'd like
Verify Google Photo Library API is enabled if not pass the URL for enabling to user and wait for retest after user enables the API.

Describe alternatives you've considered
At minimum raise the error in the UI during the Select Album config interface.

Additional context
googleapiclient.errors.HttpError: <HttpError 403 when requesting https://photoslibrary.googleapis.com/v1/albums?pageSize=50&alt=json returned "Photos Library API has not been used in project before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/photoslibrary.googleapis.com/overview?project= then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry.". Details: "[{'@type': 'type.googleapis.com/google.rpc.Help', 'links': [{'description': 'Google developers console API activation', 'url': 'https://console.developers.google.com/apis/api/photoslibrary.googleapis.com/overview?project=421627846401'}]}, {'@type': 'type.googleapis.com/google.rpc.ErrorInfo', 'reason': 'SERVICE_DISABLED', 'domain': 'googleapis.com', 'metadata': {'consumer': 'projects/421627846401', 'service': 'photoslibrary.googleapis.com'}}]">

Support Shared Albums

Support for shared albums and a bit better error handling (account with no albums)

        def get_albums() -> List[Album]:
            album_list = []
            service: PhotosLibraryService = get_photoslibrary()
            
            albums = service.albums()  # pylint: disable=no-member
            fields = "albums(id,title,mediaItemsCount),nextPageToken"
            request = albums.list(pageSize=50, fields=fields)
            while request is not None:
                result = request.execute()
                album_list = album_list + result.get("albums", [])
                request = albums.list_next(request, result)
            
            sharedAlbums = service.sharedAlbums()  # pylint: disable=no-member
            fields = "sharedAlbums(id,title,mediaItemsCount),nextPageToken"
            request = sharedAlbums.list(pageSize=50, fields=fields)
            while request is not None:
                result = request.execute()
                album_list = album_list + result.get("sharedAlbums", [])
                request = sharedAlbums.list_next(request, result)
            return list(filter(lambda a: ("id" in a and "title" in a), album_list))

        albums = await self.hass.async_add_executor_job(get_albums)
        album_selection = dict({CONF_ALBUM_ID_FAVORITES: "Favorites"})
        for album in albums:
            album_selection[album.get("id")] = "{0} ({1} items)".format(
                album.get("title"), album.get("mediaItemsCount", "?")
            )

Include Location Information in Metadata if available

Is your feature request related to a problem? Please describe.
N/A

Describe the solution you'd like
Nice integration! I'd like to be able to display where a photo was taken on my dashboard. I see the metadata options and see the camera information. I've checked in Google Photos and the location information is available on the photos in question.

Describe alternatives you've considered
Doesn't seem to be any.

Additional context
N/A

Google API Scope Required Now(?)

At the final step of authenticating through Google I received this error pop-up

 "Failed to query google api: Request had insufficient authentication scopes."

FIXED by...
-- Add Scope to View for Photos API ('sensitive' unfortunately)
-- Revert publishing status to "Testing" (otherwise proceed through a verification process)
-- Add myself as a Test User

First time I've used Google's API's so, its very likely I missed something from your instructions.

Your instructions were great -- and this addon was exactly what I needed!! Thank you

Add location info

I will be great to have location info in attribiutes. Can you add this?

Unable to select album, KeyError: 'title'

When choosing "Select Album" from the configuration menu I'm prompted with an "Error" dialogue, no additional information is provided. I'm other able to successfully authenticate ha-google-photos and see my favorite photos.

Release version v0.4.0

Logger: aiohttp.server
Source: custom_components/google_photos/config_flow.py:148
Integration: Google Photos (documentation, issues)
First occurred: 1:15:40 PM (2 occurrences)
Last logged: 1:15:48 PM

Error handling request
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/aiohttp/web_protocol.py", line 433, in _handle_request
    resp = await request_handler(request)
  File "/usr/local/lib/python3.10/site-packages/aiohttp/web_app.py", line 504, in _handle
    resp = await handler(request)
  File "/usr/local/lib/python3.10/site-packages/aiohttp/web_middlewares.py", line 117, in impl
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/security_filter.py", line 67, in security_filter_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/forwarded.py", line 100, in forwarded_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/request_context.py", line 28, in request_context_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/ban.py", line 80, in ban_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/auth.py", line 235, in auth_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/view.py", line 146, in handle
    result = await result
  File "/usr/src/homeassistant/homeassistant/components/config/config_entries.py", line 241, in post
    return await super().post(request, flow_id)
  File "/usr/src/homeassistant/homeassistant/components/http/data_validator.py", line 72, in wrapper
    result = await method(view, request, data, *args, **kwargs)
  File "/usr/src/homeassistant/homeassistant/helpers/data_entry_flow.py", line 110, in post
    result = await self._flow_mgr.async_configure(flow_id, data)
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 267, in async_configure
    result = await self._async_handle_step(
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 367, in _async_handle_step
    result: FlowResult = await getattr(flow, method)(user_input)
  File "/config/custom_components/google_photos/config_flow.py", line 176, in async_step_albumselect
    data_schema = await self._get_albumselect_schema()
  File "/config/custom_components/google_photos/config_flow.py", line 148, in _get_albumselect_schema
    album_selection[album["id"]] = album["title"]
KeyError: 'title'

Support of the new "image" entity?

Is your feature request related to a problem? Please describe.
no

Describe the solution you'd like
With recent versions HA Core does provide an Image entity.
It would be great, if this integration would also support this new entity type, rather than a camera image

Describe alternatives you've considered
none

Additional context
support propper "image entity" for images - camera entity should be used for cameras, where the image does change based on a camera stream

Entities unavailable followed by apparent reset

Version of the custom_component

V0.4.4

Configuration

configured through UI

Describe the bug

All sensors seem to become unavailable on occasion. Once they become available again, the current photo resets to the same one every time. Sometimes it seems like opeing the entity/device page in the frontend can trigger this. The debug logs do not seem to show any activity during the event,yet the device logs do as in screenshots attached.
Use case: I'm using this intergration with wallpanel to have a screensaver photo that updates daily at 04:00 via a service call automation. This seems to work perfectly, but then at some stage during the day the displayed photo reverts to the original one. This hapened with the previous version as well as latest.

Debug log

2023-03-30 03:29:26.838 DEBUG (SyncWorker_6) [googleapiclient.discovery] URL being requested: GET https://photoslibrary.googleapis.com/v1/mediaItems/AMrVKRFzNtwJT4tchGK9ypqykPAvXAjWb1Z06JRjxrMLhBiQBCA-KpEabkpgvQom6CyfoZX9P5vJbjhR4xDLs3UV2WYmcoqLDQ?alt=json
2023-03-30 03:29:43.202 DEBUG (SyncWorker_3) [googleapiclient.discovery] URL being requested: GET https://photoslibrary.googleapis.com/v1/mediaItems/AMrVKREQ8Oog8B1mt0Uqg3e9d7_3yqQJorVfF2Y-tbQr0nGZGYbYl10DKS2VNwQkok5CkjndYjDI?alt=json
2023-03-30 03:29:52.456 DEBUG (SyncWorker_4) [googleapiclient.discovery] URL being requested: GET https://photoslibrary.googleapis.com/v1/mediaItems/AMrVKREg4SH2t61HgJRPf0-y5nX_2gS8mrx3oFwBa_SfVlvsdwLkPkJthi8Az6mJfxWqtYIMs4KglLa0kZdqWP5sMl9LMDqOvw?alt=json

Add your logs here.

Screenshot 2023-03-30 at 03 47 27

Screenshot 2023-03-30 at 03 48 35

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.