@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
-
Hi there, I recently had a smart plug fritz out on me. I replaced it with the same model and gave it the same name. How do I update my FLIC hub to use the new device? I deleted it in the "Matter" section and added the new one. But some FLIC button actions don't work. (In fact, I think none of them worked- I already updated a few). But now I'm trying to use the Twist to control the light, and there's a bunch of points to update within that. Is there not an easy way to update ALL my Flic actions with one fell swoop instead of having to go into every button/twist and make the updates?? 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?