H.O.O.P. (Hope) - Homey Object Oriented Programming

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;}

}}
1 Like

In HOOP in the settings you can add javascript functions and use that in the Flow Variables cards.

1 Like

I log in to the Athom devolper setting and copy/paste the code into the app. When I go back to the app and press “configure app” I get an error :


I want to install the Homey Elevator but I get also an error :

I’ve read the above and tried again but no luck? Anyone can help?

Install 1.2.3 when its in the store and use the settings, the issue for iOS has been resolved.

Okay thanks, I will install it when it’s in the store

v 1.2.3. is in the store now.

I’ve installed version 1.2.3 and still the same error when I tried to install the Homey Elevator device. The error when I go to the configure app page is gone. Thanks for that.

Indeed, the Elevator device will give an error on some phones (iOS) and there is nothing i can do about that. Thats why i have the backup settings-elevation which again works correctly as backup for some phone’s.

Hi,

Is someone willing to point me in the right direction for my use case?

I have a Aqara Opple light switch with 2 buttons. What I want is a flow with 2 “when” conditions. If button 1 or button 2 is pressed, turn on the light.
More like a “If-Or-Then” statement.

Now I have 2 flows. One for each button.

Is this possible with this app?

Regards,

Dennis

Hey Dennis,

Not yet! I have been working on a if-if-if structure, and it is looking promising.
I allready have build the trigger system, just need to make the conditional-trigger-cards.

I just need time to finish it.

1 Like

That sounds great! Please keep us posted!

Hey Arie,

It’s been a while, but very appreciated:
Thanks a lot for your explanation and examples.
Agreed, in case of multiple IF statements before THEN, using the seperate IF - THEN cards keeps it readable.

And in case of just ONE IF statement, the card with IF the following 1 cards are A THEN do B seems readable enough, and indeed shortens the flows with mulitiple if-A-then-do-B statements

Hey Arie, I got this error this evening when searching for trigger card devices, screenshot:


I realized I enabled 2FA the other day, and did not logout everywhere I could think of. The Homey app on my Android is keeping the logoff button a secret to me, so I did not logoff from the app.

So I logged on to various Athom & Homey related sites with my H. account and 2FA codes, also at my.homey.app
But no difference whith this error.
At the Homey app on Android the trigger devices are still presented and selectable.
Any ideas? No hurry (for me)

Trying to create an homey elevator device again? Or use the settings to re-elevate.

Update2:

  • 1st used the settings to re-elevate. No effect
  • 2nd re created an homey elevator device. No effect
    • NOTE: While starting with building flows it seems to work fine, when reaching flows of this size, it gets worse (this flow doesn’t do what I expect it to do yet):
  • The Homey memory check page timed out with an Unknown Error, but after 10 retries, now it works.
  • Oww, the H.o.o.p. app uses 45.5MB. Not your fault my Homey is choking because of the extra 20-30MB of ram usage, it is packed to the max so that’s solely my problem.
    • I gave the H.o.o.p. app a restart command, but it timed out after 30 secs.
      Now I, reluctantly, restarted Homey and call it quits for today.
  • After rebooting Homey, H.o.o.p. app is using 18,1MB, and Homey 106.4MB… it shrunk with 110MB’s…
    So all in all it’s a combination of a growing app, and growing Homey ram usage.

Thx for the quick response, Arie.
Update: it occurs occasionally now, also while trying to save a flow.
I will re create an homey elevator device.

I just updated to 5.0.4.
I wend from Homey ~200MB to 179.7MB.

I did update all stuff for HOOP, will be publishing the newest version, but i didn’t change anything except the newest athom-api.

For me everything works fine, but i don’t use MFA/2FA yet, and i will not be doing that this month (because of lack of time if something goes wrong).

Thanks Arie. All of your work is much appreciated.
In hindsight I knew when Homey’s got full memory problems, apps go stalling and network (wifi) goes banana’s.
The papertrails app indicated that.
It was kind of coincidence it occurred while editing large flows.
Well,
I shoud restart apps & Homey from the beginning (note to self)

Oh I fully understand you want wait to enable 2FA, this can have unexpected side effects.

1 Like

Indeed, and i have so mucht customly-writen system in my House connected to/through Homey.
But in may i’ll probably change to MFA.

It shoudn’t matter, but “shouldn’t” and “does-not” ain’t the same :wink:

1 Like

That is a truth as a cow, Arie :wink::laughing:

1 Like

So I want to create a flow for a 4-function-click switch.
Expected functionality: The second click can be x mins/hours later, so if you want to turn the light off, just click a few times until it turns off (no need for remembering how many clicks are needed here).
1 click = dim light to 20%
2nd click = dim light to 50%
3rd click = dim light to 100%
4th click = turn light off

The only thing what works at this time is the timeline message from the THEN card, after pushing the button :wink: It displays the counter var value, it stays on 0


Any ideas, I can’t see it anymore, I tried 1,000 things…

My Flow:

Because some betterlogic texts disappear, a screenshot of the first part (of 4)