[PLUGIN] Pandora Plugin 2.0

Looking at the pandora_handler.js is it supposed to remove “Radio” from the station name also? If so it isn’t doing that either. Could the number of stations have an effect? I have 40 of them

No, I’m pretty sure it’s a bonehead error on my part.

Quick fix: Change this line in pandora_handler.js:

PandoraHandler.prototype.setMQTTEnabled (should be line 117)

was: self.mqttHandler = mqttEnabled
change it to: self.mqttEnabled = mqttEnabled

I have the topic in MQTT Explorer now (nice free program for mqtt troubleshooting, by the way).

Let’s apply the duct tape and see what else breaks. :smiley: I’ll commit this fix to the develop branch

I think I did this to help with Google Assistant commands, so you could just say, ‘Hey Google, play Soundgarden’ as a shortcut. That can of course be looked at again.

I think that’s all right. I have about 30 or so. I don’t know what the limit is, but I guess at some point we’ll find out.

It looks like the template in the automations-volumio.yaml “Load Hornet Stations” automation was invalid. I’m not sure exactly what happened there – perhaps a change in the Jinja language? The from_json filter seems to have disappeared, but there was a way around that.

I think it’s a bit cleaner now. The stations are now populating in input_select.hornet_station – you can see them now.

I don’t think we’re out of the woods yet. I’ll take another stab at it tomorrow.

EDIT: I put the changes on that GitHub repo I linked in a previous post.

The station list is populating properly in the input selection.

I am still getting a “UndefinedError: ‘newStationName’ is undefined” error. I think it is due to the way the “play_volumio_pandora_station” template is being parsed as a shell command option.

I pushed v2.8.1 beta of the Pandora Plugin to GitHub if you want to update to that. The only change is to that variable name in the pandora_handler.js setMQTTEnabled() function. (package.json, Readme.md updates as well, yeah sure).

Good. At least that’s working.

I’ll take a look at that in a little bit after the coffee kicks in.

Well that took a while. I fixed a few things – I had a problem in the pyscript script I wrote. Slowly, things are improving.

Things seem to be happening twice with every station change. I’ll have to address that next.

The ‘None’ option is just a bad name I chose for “no choice” – I’ll change that to “nothing” perhaps.

Updates were pushed to the repo.

EDIT: One small change to the plugin beta was just pushed (index.js file). You’ll need that fix as well

Updated to latest versions. Changes made directly on Volumio are updated correctly in HA. The issue now is when making a change to the input on the HA side the follow error is thrown.

Error rendering command template: TypeError: Object of type Undefined is not JSON serializable

I spent a while looking at this process. I rewrote the python script to use socket.io and in synchronous code instead of using asyncio. It should not make a difference which way it is since the script only fires once and exits.

That template was a little screwy. Apparently, the executable command in a shell_command has to come first, and data cannot be in a template until after the first space (see the HA docs on the web). I think I’ll just hard code in the regular parameters for now and look into passing them to the function in the future if there is need for more functionality, leaving the Pandora station as an option.

I might pass in the station as a JSON rather than as a string and that will require one small change to the clearAndPlayStation() function. Not a big deal – it probably makes more sense to do that.

I think I had a reason for dropping the Radio suffix from the station names but I can’t remember what that was. That’s not written in stone and can be amended.

Anyway, I just have to make sure the station gets passed to the shell command and then we’ll have more progress. My new script will change the station from a command prompt, and that wasn’t happening when I started working on it today, so I’m calling that progress.

I want to take one more look before I commit these changes. I’ll do that sometime tomorrow morning here (East Coast USA).

Okay, things seem to be a bit better. I changed the input_select in the Developer Tools -> States dialog and the Pandora station played.

I need to have HA poll Volumio (via MQTT? websocket?) and have it yell at the plugin to publish the MQTT data. If HA starts after Volumio, the stations won’t update until a change or a refresh in the plugin.

One thing at a time. @Drizzay let me know what else is broken (and of course if this update doesn’t work for you).

To all you lurkers, throw some rocks this way if you see something!

Hey @truckershitch went away for a bit and am back. The station change from the developers tool still isn’t working for me. It looks like the script is being called though.

021-04-07 13:57:33 DEBUG (MainThread) [custom_components.pyscript.eval] file.update_options.update_options: calling get(“input_select.hornet_station”, {})

2021-04-07 13:57:33 DEBUG (MainThread) [custom_components.pyscript.eval] file.update_options.update_options: calling select_option(, {‘entity_id’: ‘input_select.hornet_station’, ‘option’: ‘Lemongrass’})

I’ll check this out today.

I’m not sure – maybe I didn’t post every change I made on this side to that GitHub repo? Things got a bit hectic last week.

I haven’t looked at this code since my last post. I’ll add something to post the stations in some regular fashion, perhaps publishing via MQTT from the Pandora script with a timer.

Anyway, I have a bit more time to dig into this now.

Oh, did you make sure you have the latest changes on the develop branch? I did change that one function to accept a JSON rather than a plain string for stationName and that could be your issue.

See v2.8.1 beta fix #2: clearAndPlayStation takes JSON input · truckershitch/volumio-plugins@7bb1bed · GitHub

I did a couple of commits last week so you may need a fresh pull.

v2.90 beta was committed to the develop branch.

The main change is the periodic publishing of the station data via MQTT. Before, the data wasn’t always ready for Home Assistant to pick it up. The data is now published approximately every minute. Maybe that’s too often for you? Set a different interval in timers.js if you wish. Be my guest :slight_smile:

Well, I’m gonna crack a beer. Send all hate mail here.

I think it is all working for me now. The current automation is based on the input_select.hornet changing state from none to something else so I might play around with that piece. Big thanks for helping with the WAF.

Great!

Basically, you can use a voice command to change that input_select from Google Assistant. I can’t remember the exact syntax, and that may have changed in the last six months or so.

The command I got to work was awkward, but like this last comment from January 6, 2021 says, you can make a Routine in your Google Home application on your phone to handle things:

Also here:

See if you find anything else with this search:

https://www.google.com/search?q=home+assistant+input+select+google+assistant

Let me know if you find a good way or if you think of any other HA automation ideas.

v2.9.0 was posted about a week ago. Users can upgrade through the regular plugin menu.

when the plugin is stopped, eventually all the songs but the one “in-play” are dequeued. Is there anyway to dequeue the in play song, by the time the queue has cleared the contract on that song has expired so it never plays till the end anyway.

I have noticed that as well. I’ll take a look at it. There is a timestamp on each Pandora object (with the track information) in the queue, so I think that should be possible.

Thanks for your continued input.

Hi truckershitch,

I’ve been using the Pandora Plugin version 1.0 for my app for some time now successfully. I have update to 2.0 (2.0.9) and really like the new features. I am having some trouble loading playlists now. I updated to the latest for both the Plugin and Volumio to see the latest playlist URI and certificate issues. Everything is working well in Volumio.

My Code to load a playlist:
@app.route(’/pandora2/’)
def playPandora2():

sio = SocketIO('localhost', 3000)
sio.emit("clearQueue", "")
sio.emit("addToQueue",{ "albumart": "https://content-images.p-cdn.com/images/e9/48/df/8f/b22b4ea38b8dcdd0779e03e7/_500W_500H.jpg", "icon": "fa fa-folder-open-o", "name": "The Weeknd Radio", "service": "pandora", "title": "The Weeknd Radio", "type": "station", "uri": "/pandora/stationToken=4531784199227013447" })

sio.disconnect()
return "Playlist Loaded"

Here is my journalctl output:

Oct 11 12:04:39 volumiodev volumio[1279]: info: CorePlayQueue::getQueue
Oct 11 12:04:39 volumiodev volumio[1279]: info: CorePlayQueue::getTrack 4
Oct 11 12:04:39 volumiodev volumio[1279]: info: [1633979079040] ControllerPandora::ExpireOldTracks::reaper
Oct 11 12:04:39 volumiodev volumio[1279]: info: [1633979079040] [Pandora] ExpireOldTracks::reaper: No victims found: Expiring zero tracks. Don’t worry – Jason will return.
Oct 11 12:05:19 volumiodev volumio[1279]: error: error
Oct 11 12:05:19 volumiodev volumio[1279]: error: error
Oct 11 12:07:49 volumiodev volumio[1279]: error: error
Oct 11 12:09:39 volumiodev volumio[1279]: info: CorePlayQueue::getQueue
Oct 11 12:09:39 volumiodev volumio[1279]: info: CorePlayQueue::getTrack 4
Oct 11 12:09:39 volumiodev volumio[1279]: info: [1633979379043] ControllerPandora::ExpireOldTracks::reaper
Oct 11 12:09:39 volumiodev volumio[1279]: info: [1633979379043] [Pandora] ExpireOldTracks::reaper: No victims found: Expiring zero tracks. Don’t worry – Jason will return.
Oct 11 12:11:58 volumiodev volumio[1279]: info: CoreCommandRouter::volumioGetState
Oct 11 12:11:58 volumiodev volumio[1279]: info: CoreCommandRouter::volumioClearQueue
Oct 11 12:11:58 volumiodev volumio[1279]: info: CoreStateMachine::ClearQueue
Oct 11 12:11:58 volumiodev volumio[1279]: info: CoreStateMachine::stop
Oct 11 12:11:58 volumiodev volumio[1279]: info: CoreStateMachine::setConsumeUpdateService undefined
Oct 11 12:11:58 volumiodev volumio[1279]: verbose: UNSET VOLATILE
Oct 11 12:11:58 volumiodev volumio[1279]: info: CorePlayQueue::clearPlayQueue
Oct 11 12:11:58 volumiodev python3[9515]: 192.168.4.27 - - [11/Oct/2021 12:11:58] “GET /pandora2/ HTTP/1.1” 200 -
Oct 11 12:11:58 volumiodev volumio[1279]: info: CorePlayQueue::saveQueue
Oct 11 12:11:58 volumiodev volumio[1279]: info: CoreCommandRouter::volumioPushState
Oct 11 12:11:58 volumiodev volumio[1279]: info: CoreCommandRouter::executeOnPlugin: volumiodiscovery , saveDeviceInfo
Oct 11 12:11:58 volumiodev volumio[1279]: info: CoreCommandRouter::volumioPushQueue
Oct 11 12:11:58 volumiodev volumio[1279]: info: CoreCommandRouter::volumioAddQueueItems
Oct 11 12:11:58 volumiodev volumio[1279]: info: CoreStateMachine::addQueueItems
Oct 11 12:11:58 volumiodev volumio[1279]: info: CorePlayQueue::addQueueItems
Oct 11 12:11:58 volumiodev volumio[1279]: info: Adding Item to queue: /pandora/stationToken=4531784199227013447
Oct 11 12:11:58 volumiodev volumio[1279]: info: Exploding uri /pandora/stationToken=4531784199227013447 in service pandora
Oct 11 12:11:58 volumiodev volumio[1279]: info: [1633979518952] ControllerPandora::explodeUri
Oct 11 12:11:58 volumiodev volumio[1279]: info: CorePlayQueue::getQueue
Oct 11 12:11:58 volumiodev volumio[1279]: info: CorePlayQueue::getQueue
Oct 11 12:11:58 volumiodev volumio[1279]: info: CorePlayQueue::saveQueue
Oct 11 12:11:58 volumiodev volumio[1279]: info: CoreCommandRouter::volumioPushQueue
Oct 11 12:11:58 volumiodev volumio[1279]: info: CoreStateMachine::updateTrackBlock
Oct 11 12:11:58 volumiodev volumio[1279]: info: CorePlayQueue::getTrackBlock
Oct 11 12:12:08 volumiodev volumio[1279]: info: CoreCommandRouter::volumioPlay
Oct 11 12:12:08 volumiodev volumio[1279]: verbose: UNSET VOLATILE
Oct 11 12:12:08 volumiodev volumio[1279]: info: CoreStateMachine::play index undefined
Oct 11 12:12:08 volumiodev volumio[1279]: info: CoreStateMachine::setConsumeUpdateService undefined
Oct 11 12:12:08 volumiodev volumio[1279]: info: CorePlayQueue::getTrack 4
Oct 11 12:12:20 volumiodev volumio[1279]: info: CoreCommandRouter::volumioPlay
Oct 11 12:12:20 volumiodev volumio[1279]: verbose: UNSET VOLATILE
Oct 11 12:12:20 volumiodev volumio[1279]: info: CoreStateMachine::play index undefined
Oct 11 12:12:20 volumiodev volumio[1279]: info: CoreStateMachine::setConsumeUpdateService undefined
Oct 11 12:12:20 volumiodev volumio[1279]: info: CorePlayQueue::getTrack 0

No errors that I can see and Volumio reports the playlist loaded in the UI, however the queue is empty. What am I doing wrong?

Thanks!!

G