Great yo guys want to help. Thx in advance.
I want it to be programmed 14 days in advance. I have a script, but have to admit it was made with a lot of help of the community, google , copy/paste and some reading in a javascript book.
This is my script at this moment;
// Script by Marcel for randomly playing radiostations and playlists from Spotify with your Sonos Device
// With the use of a Synology Server and the Sonos Docker Api
// Using Homey's apps Better Logic and HTTP request
// Add your Server's Ipadres and PortnumerPrefix voor radiostations en playlists
const IpAdres = '192.168.178.2'; //Add your local ip adres of your server e.g '190.178.178.3'
const Portnumber = '5005';//Add your portnumber of your server for the Sonos api
// Do not adjust
const RadioPrefix = 'http:%2F%2F' + IpAdres + ':' + Portnumber + '%2Fwoonkamer%2Ffavorite%2F';
const PlayListPrefix = 'http:%2F%2F'+ IpAdres + ':'+ Portnumber + '%2Fwoonkamer%2Fspotify%2Fnow%2Fspotify:user:spotify:playlist:';
//Add your station at //Radiostations. In your Sonos app, from Sonos(not Homey) you
//need to add your radiostation as favorite. Use this exact name in this script
//I have added three playlists. Therefore the variable names Radio12, Radio13 en Radio14 must be
//stay the same and not been altered.
//To add some random playlist I have made 17 playlist which you can adjust. Just search the ID
//of your playlist in your Spotify App(not Homey) and paste this ID at //PlayList between
//the quotes
// Add 14 string variables in Better Logic, called RadioDay1, RadioDay2.....Radioday3, three extra
//string variables called PlayListDay1, PlayListDay2 and PlayListDay3, and three string variables
// called PlayListName1, PlayListName2 and PlayListName 3. The variable names are case sensitive.
//Radiostations=> Add the name of your Sonos favorite between the quotes
const Radio1 = RadioPrefix + '538 Ibiza Radio';
const Radio2 = RadioPrefix + 'Deep Radio';
const Radio3 = RadioPrefix + '538 Dance Radio';
const Radio4 = RadioPrefix + 'Dance FM';
const Radio5 = RadioPrefix + 'Deep House Ibiza';
const Radio6 = RadioPrefix + 'Deep Radio';
const Radio7 = RadioPrefix + '538 Ibiza Radio';
const Radio8 = RadioPrefix + 'Dance FM';
const Radio9 = RadioPrefix + 'Sky Radio 101 FM';
const Radio10 = RadioPrefix + 'On Disco';
const Radio11 = RadioPrefix + 'Heart Dance';
const Radio12 = 'Playlist1';//Do not adjust this variable
const Radio13 = 'Playlist2';//Do not adjust this variable
const Radio14 = 'Playlist3';//Do not adjust this variable
//Playlist => Add the ID of your Spotify playlist between the quotes. For your own needs you can add the
//name of the playlist after the //
const PlayListId0 = '7GQS3BcOeogh8wKEeA3fN8?si=taswh15eRZuXmFAkyn6IfQ'//12inch Classics Part 1
const PlayListId1 = '1C5F8dA3nWRN46u6lCehqm?si=67RdCbXtSG27gx6C7qP2Sw'//Deep Delight Part 2
const PlayListId2 = '1QdAD45sKZQwptkm4VeKmO?si=_5P2-G9-SZG91WsNHt0f4g'//360 Dance Part 2
const PlayListId3 = '4YKqPMOlV5JJK6XVKKdWJ9?si=SL7iH53eSNu-PnsZJIcr6A'//Deep House Part 2
const PlayListId4 = '7jzMzltNsYhaI5Xfkxe9If?si=IwDTD4ylQJC9c5JWxEUXQw'//Massive Pop Remixes Part 1
const PlayListId5 = '5sInx9KNxVqnONg9EsIptX?si=8T0QWluxSDqI3bClrf0OOQ'//Dance Classics Part 1
const PlayListId6 = '0NhMKI95ujIjriBaRXrIBs?si=pG_J4OXGTz6mhN_kG1mvMg'//Dance Pop Remixes Part 1
const PlayListId7 = '1s4YUBb95LaWazpgvNGzAu?si=35wEzzqcQIKAgSZq7bkEaA'//Deep House Relax Part 3
const PlayListId8 = '60HqFyCYzr6dxr4OMxDtS7?si=x7Oa5bNBQXy4DQlC2COLaw'//Truly Deeply House Part 1
const PlayListId9 = '00JuraVC5HSlXCLpYJ4RQx?si=LJFWf4UoQ-2DtayVAGb26g'//360 Dance Part 1
const PlayListId10 = '0C66rsP0YemHrh3dUhSszt?si=gdtcDlzURLWQVZCKi8Evkw'//Deep House Relax Part 2
const PlayListId11 = '4Vaus40H2m6gkwNqhzzril?si=6y9qg0HxQAqfB_B3bhfeIQ'//Deep Delight Part 1
const PlayListId12 = '7kS4ICEIagMdVKUMAe2Hy1?si=CazM4dkSQLq-0wJ_IaiJDw'//Deep House Part 3
const PlayListId13 = '7fwbNi5Be9Jh2ljr9b8Z34?si=TodSqWEASG2mNdGvxV_CKA'//Truly Deeply House 2
const PlayListId14 = '28MJ5Ws6Hw7K3sM0buLxvS?si=sR9304GXTzikRt1n3so-MQ'//Marcels Favorieten 2017
const PlayListId15 = '4oH8GC0TMvQGlTXlj3luUq?si=RnmzYP4YRCWSPa9ptJTuRA'//Deep House Relax Part 1
const PlayListId16 = '4g1z40nOzcPytHV5DvWpvB?si=GVjxQsb6RTyA5CB72mjSLQ'//Deep House Relax 4
//PlaylistNames => Add the Name ad you want to get presented of your Spotify playlist between the quotes.
const PlayListName0 = '12inch Classics Part 1'
const PlayListName1 = 'Deep Delight Part 2'
const PlayListName2 = '360 Dance Part 2'
const PlayListName3 = 'Deep House Part 2'
const PlayListName4 = 'Massive Pop Remixes Part 1'
const PlayListName5 = 'Dance Classics Part 1'
const PlayListName6 = 'Dance Pop Remixes Part 1'
const PlayListName7 = '/Deep House Relax 3'
const PlayListName8 = 'Truly Deeply House Part 1'
const PlayListName9 = '360 Dance Part 1'
const PlayListName10 = 'Deep House Relax 2'
const PlayListName11 = 'Deep Delight Part 1'
const PlayListName12 = 'Deep House Part 3'
const PlayListName13 = 'Truly Deeply House 2'
const PlayListName14 = 'Marcels Favorieten 2017'
const PlayListName15 = 'Deep House Relax Part 1'
const PlayListName16 = 'Deep House Relax 4'
//Do not change the next variables
const PlayList0 = PlayListPrefix + PlayListId0//12inch Classics Part 1
const PlayList1 = PlayListPrefix + PlayListId1//Deep Delight Part 2
const PlayList2 = PlayListPrefix + PlayListId2//360 Dance Part 2
const PlayList3 = PlayListPrefix + PlayListId3//Deep House Part 2
const PlayList4 = PlayListPrefix + PlayListId4//Massive Pop Remixes Part 1
const PlayList5 = PlayListPrefix + PlayListId5//Dance Classics Part 1
const PlayList6 = PlayListPrefix + PlayListId6//Dance Pop Remixes Part 1
const PlayList7 = PlayListPrefix + PlayListId7//Deep House Relax Part 3
const PlayList8 = PlayListPrefix + PlayListId8//Truly Deeply House Part 1
const PlayList9 = PlayListPrefix + PlayListId9//360 Dance Part 1
const PlayList10 = PlayListPrefix + PlayListId10//Deep House Relax Part 2
const PlayList11 = PlayListPrefix + PlayListId11//Deep Delight Part 1
const PlayList12 = PlayListPrefix + PlayListId12//Deep House Part 3
const PlayList13 = PlayListPrefix + PlayListId13//Truly Deeply House 2
const PlayList14 = PlayListPrefix + PlayListId14//Marcels Favorieten 2017
const PlayList15 = PlayListPrefix + PlayListId15//Deep House Relax Part 1
const PlayList16 = PlayListPrefix + PlayListId16//Deep House Relax 4
function wait(ms){//Declaring function wait
var start = new Date().getTime();
var end = start;
while(end < start + ms) {
end = new Date().getTime();}}
var nums = [Radio1,Radio2,Radio3,Radio4,Radio5,Radio6,Radio7,Radio8,Radio9,Radio10,Radio11,
Radio12,Radio13,Radio14];
var usedNums = [];
let BLApp = await Homey.apps.getApp({id:"net.i-dev.betterlogic" });
while (nums.length) {
var nummer = nums.length.toString();
var randomIndex = Math.floor(Math.random() * (nums.length));
var randomNumber = nums.splice(randomIndex, 1)[0];
// console.log( 'First radiostation is: '+randomNumber.toString() + " " + nummer) ;
// console.log('Nummer: '+nummer)
// console.log('Randomnummer is :'+randomNumber)
// console.log('RadioDay is :'+randomNumber)
let result=BLApp.apiPut("RadioDay"+nummer+"/" + randomNumber.toString());
};
var nums = [PlayList1,PlayList2,PlayList3,PlayList4,PlayList5,PlayList6,PlayList7,
PlayList8,PlayList9,PlayList10,PlayList11,PlayList12,PlayList13,PlayList14,PlayList15,
PlayList16, PlayList0];
var usedNums = [];
while (nums.length) {
var nummer = nums.length.toString();
var randomIndex = Math.floor(Math.random() * (nums.length));
var randomNumber = nums.splice(randomIndex, 1)[0];
let result=BLApp.apiPut("PlayListDay"+nummer+"/" + randomNumber.toString());
};
wait(2000);
let PlayListDay1 = await BLApp.apiGet('PlayListDay1');//Retrieving Better Logic variable
PlayListDay1 = PlayListDay1.value
console.log('PlayListDay1: ' +PlayListDay1)
let PlayListDay2 = await BLApp.apiGet('PlayListDay2');//Retrieving Better Logic variable
PlayListDay2 = PlayListDay2.value
console.log('PlayListDay2: ' +PlayListDay2)
let PlayListDay3 = await BLApp.apiGet('PlayListDay3');//Retrieving Better Logic variable
PlayListDay3 = PlayListDay3.value
console.log('PlayListDay3: ' +PlayListDay3)
let PlayListDay = [PlayListDay1, PlayListDay2, PlayListDay3]
let PlayListDayNumber = 0
let PlayListIdNumber = -1
let PlayListId = [PlayListId0, PlayListId1, PlayListId2, PlayListId3, PlayListId4, PlayListId5, PlayListId6, PlayListId7, PlayListId8, PlayListId9, PlayListId10, PlayListId11, PlayListId12, PlayListId13, PlayListId14, PlayListId15, PlayListId16]
let PlayListName = [PlayListName0, PlayListName1,PlayListName2,PlayListName3,PlayListName4,PlayListName5,PlayListName6,PlayListName7,PlayListName8,PlayListName9,PlayListName10,PlayListName11,PlayListName12,PlayListName13,PlayListName14,PlayListName15,PlayListName16]
for (let Count = 0; Count <= 16; Count++){
switch(Count){
case Count:{
if (PlayListDayNumber === 3){break;}
PlayListIdNumber = PlayListIdNumber + 1
console.log('Count is: '+Count)
console.log('PlayListDayNumber is: '+(PlayListDayNumber+1))
console.log('PlayListIdNumber is : '+PlayListIdNumber)
console.log('PlayListId is: '+PlayListId[PlayListIdNumber])
x = PlayListDay[PlayListDayNumber].includes(PlayListId[PlayListIdNumber].substring(0,22))
if(x === true){
{BLApp.apiPut('PlayListDay'+[PlayListDayNumber +1] +'Name/' +PlayListName[PlayListIdNumber])
console.log('PlayListIdNumber is : '+PlayListIdNumber)
console.log('PlayListDay'+[PlayListDayNumber + 1] +'Name is: ' +PlayListName[PlayListIdNumber])
console.log('PlayListDayNumber is nu nog: '+(PlayListDayNumber +1))
PlayListDayNumber = PlayListDayNumber +1
PlayListIdNumber = 0
Count = 0
console.log('PlayListDayNumber is nu : '+(PlayListDayNumber +1))
break;}}
else continue;}
}}