@petter-landing-0r the red LED blinking typically indicates low battery. Did you try a fresh one?
-
Hi,
Here's a module I programmed for controlling volume and basic Spotify playback functions with Flic Twist, in case someone else has any use for it. To use it, you'll have to register for a Spotify developer account and create a new app from their dashboard, in order to get access tokens etc.
@flichub @Emil: Is it possible to somehow get this added to the existing public Spotify "provider"? Seems a bit tedious/difficult for users without any programming experience to go down this particular rabbit hole.
// main.js const flicapp = require('flicapp'); const http = require('http'); const datastore = require('datastore'); datastore.get('clientID', (err, key) => { const clientID = key // store this first: (datastore.put('clientID', 'YOUR CLIENT ID') datastore.get('clientSecret', (err, key) => { const clientSecret = key // store this first: (datastore.put('clientSecret', 'YOUR CLIENT SECRET') function percent(volume, decimalPlaces = 0) { const percentage = (volume * 100).toFixed(decimalPlaces); return `${percentage}`; } function spotifyStatus() { datastore.get('accessToken', (err, key) => { const accessToken = key if (key !== null) { const options = { url: 'https://api.spotify.com/v1/me/player', method: 'GET', headers: { 'Content-Type': 'application/json', 'Authorization': 'Bearer ' + accessToken } }; const req = http.makeRequest(options, (error, result) => { if (result.statusCode == 401) { refreshToken(); } if (result.statusCode == 204) { var status = "No active sessions." console.log(status); } if (result.statusCode == 200) { var jresp = JSON.parse(result.content); var status = jresp["is_playing"]; if (status === true) { spotifyPause(); } if (status === false) { spotifyPlay(); } } }) } }) }; function spotifyPlay() { datastore.get('accessToken', (err, key) => { const accessToken = key if (key !== null) { const options = { url: 'https://api.spotify.com/v1/me/player/play', method: 'PUT', headers: { 'Content-Type': 'application/json', 'Authorization': 'Bearer ' + accessToken } }; const req = http.makeRequest(options, (error, result) => { if (result.statusCode == 401) { refreshToken(); } }) } }) }; function spotifyPause() { datastore.get('accessToken', (err, key) => { const accessToken = key if (key !== null) { const options = { url: 'https://api.spotify.com/v1/me/player/pause', method: 'PUT', headers: { 'Content-Type': 'application/json', 'Authorization': 'Bearer ' + accessToken } }; const req = http.makeRequest(options, (error, result) => { if (result.statusCode == 401) { refreshToken(); } }) } }) }; function spotifyNext() { datastore.get('accessToken', (err, key) => { const accessToken = key if (key !== null) { const options = { url: 'https://api.spotify.com/v1/me/player/next', method: 'POST', headers: { 'Content-Type': 'application/json', 'Authorization': 'Bearer ' + accessToken } }; const req = http.makeRequest(options, (error, result) => { if (result.statusCode == 401) { refreshToken(); } }) } }) }; function spotifyVolume(volume) { datastore.get('accessToken', (err, key) => { const accessToken = key if (key !== null) { const options = { url: 'https://api.spotify.com/v1/me/player/volume?volume_percent=' + volume, method: 'PUT', headers: { 'Content-Type': 'application/json', 'Authorization': 'Bearer ' + accessToken } }; const req = http.makeRequest(options, (error, result) => { if (result.statusCode == 401) { refreshToken(); } if (result.statusCode == 404) { console.log("No active sessions.") } }) } }) }; function refreshToken() { datastore.get('refreshToken', (err, key) => { const refreshToken = key if (key !== null) { const options = { url: 'https://accounts.spotify.com/api/token', method: 'POST', headers: { 'Content-Type': 'application/x-www-form-urlencoded', }, content: "refresh_token=" + refreshToken + "&scope=user-read-playback-state%2C+user-modify-playback-state%2C+user-follow-read%2C+user-library-read%2C+streaming%2C+user-read-playback-position%2C+user-top-read%2C+user-read-currently-playing%2C+&client_id=" + clientID + "&client_secret=" + clientSecret + "&grant_type=refresh_token" }; const req = http.makeRequest(options, (error, result) => { if (!error && result.statusCode === 200) { var jresp = JSON.parse(result.content); datastore.put('accessToken', jresp["access_token"]) spotifyStatus(); } }) } }) }; flicapp.on("actionMessage", function(message) { if (message == 'playtoggle') { spotifyStatus(); } }); flicapp.on("actionMessage", function(message) { if (message == 'next') { spotifyNext(); } }); flicapp.on("virtualDeviceUpdate", function(metaData, values) { if (values.volume && metaData.virtualDeviceId == "spotify") { var volume = percent(values.volume) spotifyVolume(volume); flicapp.virtualDeviceUpdateState("Speaker", "spotify", { volume: values.volume }); } }); }); // clientID var }); // clientSecret varAs you probably can see, I'm not exactly a Javascript wizard, but it works 🙂 Enjoy.
Andreas
-
-
TL;DR – Flic and SmartThings seem to be partially authenticated but the services are not fully connected. I log in successfully to SmartThings from the Flic App and authorize, but my Scenes don’t appear. Parts of the Flic app act as though I am connected, other parts indicate I am not – Please advise.
Process:
Run Flic App on Android
Access my (only) Flic Hub
Flic Info Small.png
Internet test button reports access is fine
Select a Standby Flic button to configure
Select ‘Click’ function
Select SmartThings Category:
Flic Login.png
Login to SmartThings when prompted by the Flic app.
After SmartThings authentication I get this screen:
SmartThings Authorize.png
I authorize execute and read on all scenes
Ok – so now from articles and YouTube videos I should be taken to the screen in the Flic app that lists the scenes I have in SmartThings, but I don’t, It takes me back to this screen:
Flic Login.png
If I press ‘LOG IN’ again, I go straight back to the authorize screen, i.e., it doesn’t ask me to (re)authenticate with SmartThings:
SmartThings Authorize.png
And I am back here, looping around forever…
Flic Login.png
If I back out of the login screen, I get here:
Scenes.png
At this point It seems to think I am logged in, but have no Scenes
If I press ADD SCENE, it takes me back here:
Flic Login.png
And around we go!
If I go to the Flic ‘Providers’ screen, I see Philips Hue with a green tick. Hue with my Flic works fine, so I assume a green tick means that the services are connected. SmartThings shows a gear, indicating I am not connected?
Providers.png
If I touch the Gear Icon, predictably I get back to here:
Flic Login.png
My conclusion is that I am partially authenticated but not fully connected?
Please advise on how I might resolve my situation.
Many thanks
-
I bought 3 buttons + hub ~3 years ago. Worked most of the time the first 2 years, then they became very flaky and unreliable, so I unplugged the hub.
I'm trying again now, as it was quite cool product and want to give it another chance.
One of the buttons disconnects after few minutes: I keep pressing on it for ~10 seconds (trying to make it recognized by the hub), it blinks red. After 3-4 attempts, it finally blinks green twice, and the controller then works. I can use it few times in a row, but if I let it rest for 1 or 2 minutes, I have to do the long press dance again (red blinks..). I'm 1 meter from the hub -> totally unusable.
The 2 other buttons can stand a little bit longer (~10 minutes, 2 hours) before I have to reconnect them as well (long press with red blinking)
The hub is running firmware 4.5.0.
Any idea?