Giter Site home page Giter Site logo

werner81 / openhab_spotify-webconnect-api Goto Github PK

View Code? Open in Web Editor NEW

This project forked from pmpkk/openhab_spotify-webconnect-api

0.0 1.0 0.0 29 KB

A simple Python script to integrate Spotify's Web Connect API (https://developer.spotify.com/web-api/web-api-connect-endpoint-reference/) to OpenHab (openhab.org)

License: MIT License

CSS 45.97% Python 44.24% HTML 9.79%

openhab_spotify-webconnect-api's Introduction

openhab_spotify-webconnect-api

A simple Python script to integrate Spotify's Web Connect API (https://developer.spotify.com/web-api/web-api-connect-endpoint-reference/) to OpenHab (openhab.org)

Prerequisite

  • OpenHab 2.1 installed on Raspberry Pi (or similar)
  • OpenHab REST installed
  • Spotify User Account
  • Spotify Developer Account
  • The script uses OpenHab items to store parameters and credentials. Make sure you have persistance turned on, otherwise all your settingd are lost upon reboot/restart
  • Know your OpenHab root URL/IP and port. In this doc, I assume http://openhabianpi.local:8080/

Instructions

  1. Add the spotify.items file into openhab-conf/items and verify they have been added to your setup in Paper UI
  1. Place the following files in the folders:
  • matrix-theme.css into openhab-conf/html/matrix-theme
  • AppIcons.svg into openhab-conf/html/matrix-theme
  • spotify-auth.html into openhab-conf/html
  • myopenhab.py into openhab-conf/scripts
  • spotify.py into openhab-conf/scripts
  • spotify.rules into openhab-conf/rules
  • spotify.items into openhab-conf/items
  1. Verify you can reach spotify-auth.html
  1. After registering as a Spotify developer, create a new App and retrieve client id and secret:
  1. Give the client id and secret to OpenHab
  • Save the Client ID to spotify_client_id in OpenHab (e.g. through openhab CLI smarthome:update spotify_client_id {your_id})
  • Copy the Client Secret to spotify_client_secret in OpenHab (e.g. through the rest API)
  1. Authenticate your New App for your Spotify User
  • Go to: http://openhabianpi.local:8080/static/spotify-auth.html
  • You should see a page called "Spotify Integration" with a status message "Click here to Authenticate"
  • Click the link and authenticate your app
  • When done, the page returns and displays "New Auth Code successfully saved to OpenHab!"
  • Check that the spotify_auth_code is set in OpenHab
  1. Test spotify.py in SSH
  • Set the REDIRECT_URI in spotify.py to the right value
  • Run this in terminal /usr/bin/python /etc/openhab2/scripts/spotify.py

You should see this:

Successfully got state from OpenHab: spotify_client_id
Successfully got state from OpenHab: spotify_client_secret
Successfully got state from OpenHab: spotify_access_token
Successfully got state from OpenHab: spotify_refresh_token
Successfully got state from OpenHab: spotify_token_issued
Successfully got state from OpenHab: spotify_token_expiry
-- Calling Service: Update
Successfully posted state to OpenHab: spotify_current_track
Successfully posted state to OpenHab: spotify_current_artist
Successfully posted state to OpenHab: spotify_current_cover
Successfully posted state to OpenHab: spotify_current_duration
Successfully posted state to OpenHab: spotify_current_progress
Successfully posted state to OpenHab: spotify_current_progress
Successfully posted state to OpenHab: spotify_current_playing
Successfully posted state to OpenHab: spotify_current_device
Error posting state to OpenHab: spotify_current_volume (HTTP Response 400)
Successfully posted state to OpenHab: spotify_current_device_id
 -> Success
Successfully posted state to OpenHab: spotify_lastConnectionDateTime
Done in 0.761183977127 seconds
  1. You can now hook up OpenHab rules or HabPanel with the data in the spotify items.

Use

  • spotify.py
  • parameters:
    • none = refresh data
    • play = resume playing
    • play uri = play suported uris (album, artist or playlist), e.g. spotify:user:spotify:playlist:37i9dQZF1DX5OepaGriAIm
    • pause = pause
    • next = next track
    • previous = previous track
    • volume_up = 10% up
    • volume_down = 10% down
    • get_devices = get available devices and safe to openhab
    • transfer_playback = transfer playback to device set in openhab

openhab_spotify-webconnect-api's People

Contributors

pmpkk avatar

Watchers

 avatar

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.