joeyhage / homebridge-spotify-speaker

Control Spotify playlists using a fake speaker accessory
MIT License
19 stars 3 forks source link

Changing the Volume don't work when the Wifi Device goes into sleep mode #55

Open epicbenz opened 1 year ago

epicbenz commented 1 year ago

Describe Your Problem:

Hi Joey, its me again xD

I noticed the following problem, maybe you can help me with it. As you have already recognized in problem #47, the Amazon Echo Dot goes into sleep mode after some time. Here you had the idea to insert a retry delay for the device. Is that also possible for the volume control? Background is that I would like to build an automation, where at different times a different volume is set. However, if I activate a trigger (e.g.) a time and the Amazon Echo is then in sleep mode, then I get the error below and the volume is not changed. When the Amazon Echo is not in sleep mode, changing the volume works without problems. Is there also a possibility here with a retry delay or does this only work when "switching on" the playlist?

Logs:

[10/30/2023, 9:20:04 PM] [HomebridgeSpotifySpeaker] SpotifyDeviceNotFoundError: "{\"error\":{\"status\":404,\"message\":\"Device not found\"}}"

Plugin Config:

{
    "bridge": {
        "name": "Homebridge XXXX",
        "username": "XX:XX:XX:XX:XX:XX",
        "port": 51640,
        "pin": "xxx-xx-xxx",
        "advertiser": "avahi"
    },
    "accessories": [],
    "platforms": [],
        {
            "name": "HomebridgeSpotifySpeaker",
            "spotifyClientId": "ClientID",
            "spotifyClientSecret": "ClientSecret",
            "spotifyRedirectUri": "https://example.com/callback",
            "spotifyAuthCode": "AuthCode",
            "spotifyPollInterval": 20,
            "deviceNotFoundRetry": {
                "enable": true,
                "retryDelay": 2000
            },
            "devices": [
                {
                    "deviceName": "Bad Musik",
                    "deviceType": "speaker",
                    "spotifyDeviceName": "Andreas' 2. Echo Dot",
                    "spotifyPlaylistUrl": "https://open.spotify.com/playlist/xxxxxxxxxx",
                    "playlistShuffle": true,
                    "playlistRepeat": false
                }
            ],
            "debug": false,
            "platform": "HomebridgeSpotifySpeaker"
        },
    "disabledPlugins": []
}

Screenshots:

Environment:

epicbenz commented 11 months ago

A Little Reminder :)

joeyhage commented 11 months ago

@epicbenz the retry I put in place previously is also in place for changing volume. As I think about what you are asking, I don't think it is possible using Spotify. Here's why:

If the device you want to change the volume of is sleeping, that means there is nothing playing on the device. If nothing is playing, then Spotify doesn't have an active connection to the device. Based on what I have experienced, an active connection to the device is required to change the volume.

You may need to start a playlist, change the volume, then stop the playlist if you want to change the volume while nothing is playing.

epicbenz commented 11 months ago

@epicbenz the retry I put in place previously is also in place for changing volume. As I think about what you are asking, I don't think it is possible using Spotify. Here's why:

If the device you want to change the volume of is sleeping, that means there is nothing playing on the device. If nothing is playing, then Spotify doesn't have an active connection to the device. Based on what I have experienced, an active connection to the device is required to change the volume.

You may need to start a playlist, change the volume, then stop the playlist if you want to change the volume while nothing is playing.

Hmm, okay i have thought that it won't be possible.

Thanks anyway for your work.

epicbenz commented 11 months ago

@epicbenz the retry I put in place previously is also in place for changing volume. As I think about what you are asking, I don't think it is possible using Spotify. Here's why:

If the device you want to change the volume of is sleeping, that means there is nothing playing on the device. If nothing is playing, then Spotify doesn't have an active connection to the device. Based on what I have experienced, an active connection to the device is required to change the volume.

You may need to start a playlist, change the volume, then stop the playlist if you want to change the volume while nothing is playing.

Hi,

I think I have an idea to solve this problem.

Would it be possible to do this?:

  1. Trigger (Time) -> Echo plays a playlist with a silent song, wait 30 seconds and than changes the volume to xx% wait again 30 seconds and stops playing
  2. Trigger (Sensor) -> Echo plays the normal playlist
  3. Trigger (other Time) -> Echo plays a playlist with a silent song, wait 30 seconds and than changes the volume to xx% wait again 30 seconds and stops playing

Or is it not possible to deposit two different playlists/songs?

I have tried to do my Automation in Home Assistant but there is the same problem with the idle of the echo dot.

epicbenz commented 11 months ago

@joeyhage

I have tried this:

I have set a second device with another name and another playlist. So I have the device "Bad 1" with playlist 1 and device "Bad 2" with a completely silent playlist.

Now I have created an automation, In that the time triggers "Bad 2" and the Echo Dot plays a silent Playlist. After 1 min the volume is changed to xx%. After another Minute I stop "Bad 2", so the Echo Dot changes silent the volume.

But sometimes it works perfectly, and sometimes I get this error:

[12/8/2023, 10:30:03 PM] [HomebridgeSpotifySpeaker] Unexpected error when making request to Spotify: {"error":{"status":403,"message":"Player command failed: Restriction violated","reason":"UNKNOWN"}}

Do you know what is wrong or why it sometimes works and sometimes not?

I really don't get it why it sometimes works exactly like it should and sometimes just not.

joeyhage commented 9 months ago

@epicbenz Apologies for the delayed response! I did a little research and it sounds like that error happens when a play request is sent to a device already playing or a pause request is sent to a device that is already paused.