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

Nice too see!
You can even easily add dim steps, or other actions with a certain no. of pushes.
I realized f.i. my table lights have 3 favorite dim values: 20%, 50% and 100%
So an extra step is simple to add:
IF “PushButtonPushesCount” = 2
THEN (Set light 20%)

IF “PushButtonPushesCount” = 3
THEN (Set light 50%)

IF “PushButtonPushesCount” = 4
THEN (Set light 100%)

I like it!

I made this 3-step-dim-and-off function earlier on with standard flows, and it took me 7 flows. Yes… seven!

Hey Peter,

I see you use two cards for If Then:
`IF (all cards until THEN are true); Operator = AndAlso &&`
and then this card:
`THEN`

But this card does the same and has the THEN operator included:
`IF the next X cards are true THEN execute the X cards after that; Operator = AndAlso &&`

To me the first way is somewhat clearer to read, because there is a THEN operator card visible, which isn’t the case with the 2nd case. I think in hindsight it’s a bit more difficult to ‘read’ the flow steps.
Is it matter of ‘taste’, what you like? Or an other idea behind it?

Well, it indeed is kind off a taste thing yeah.
For complex statements, i would advise to use the “normal” IF, THEN, ELSE and END IF cards.

The thought after IF-THEN and IF-ELSE-THEN (and i am creating a ELSE-THEN) cards, is “single line” statements.

IF-THEN statements | Homey

When you fill a string/text with a lott of possible values, it usually means a lott of single-line-statements, like this:
IF vaccuumbin is Full THEN str = str + “Bin is full!”

If you program block-statements, you need 5 cards for this.

• IF
• condition
• THEN
• execution
• END IF

This just felt wrong to me, because i would be using this a lott (programming single-line IF-THEN statements.

With the IF-THEN, you just need 3 cards:

• IF the next 1 card is true, execute the next 1 card
• condition
• execution

And when i made it, i thought: why would i fix it to The next card and the Card after that?
So i bould it so you can set the the amount If/Then cards yourself Its just more flexable that way.

In big string-collection flows, these IF-THEN and IF-ELSE-THEN cards are a real space-saver and therefor performance-saver (on the Homey mobile App anyway).

But for any other use then simple IF-THEN (string) collection flows, i would advise to use the IF and THEN cards, as, indeed, this is more clearly readable and less error prone.

1 Like

Do you mean by that: when switch X is set to on, or when knob Y was pressed? Because I couldn’t find any switch or button to trigger things yet
Now I’m studying your flows for Kongedam. I kind of like those kind of puzzles.,

No, debounce in this case would be that the function/flow can be activated multiple times within a curtain period, but will only execute once within that time : Eather at the start of the debounce-period to prevent multiple executions, or at the end of the debounce-period waiting for extra input.

But for a good debouncefunctionality, i first need HOOP triggers that can override/duplicate any trigger so you can have any trigger start HOOP flos directly.
Then debouncing will be a build in card

1 Like

I am almost done with creating Trigger Cards, which will alowe for triggers to be overwriten and thuse directly trigger HOOP flows:
This flow will trigger when the Countdown Test is empty. No need for an extra starting flow when this goes live

2 Likes

Added Trigger Cards - Use any triggercard in your Homey as H.O.O.P. trigger, so you only need one flow!
For example Volume based on time (Day/night) - one flow

Now live in the Homey Community Store!

1 Like

I am trying to make a flow but having a hard time to get it done. Maybe someone can point me in the right direction.

I am trying to make a flow but having a hard time to get it done. Maybe someone can point me in the right direction.

In these variables a few times there are duplicates, which is on purpose. But what i want is that a duplicate radiostation can not occur two days in a row. So Radiodag1 with Dance Radio may not be also on Radiodag2. What i want is when this happens the content will be copied into variable Radiodag3 and the content of Radiodag3 will be copied i to Radiodag2. After that the flow has to continue if there are more duplicates radiostations after another. What also may occur is in case duplicate radiostations are after another the script which has run to fill these variables will run again and then will check if there are duplicates after another.

Is this possible to achieve with H.O.O.P? I hope so…

Hey Marcel,

Just a quick question (if so, i will tell/make an example later / write you a function to place in HOOP):
Could you use an Array (list/collection) filled with all your favorite stations, and then, every day, pick a random but exclude the previousdayplayed , and save it in a variable “previousdayplayed”.

Am i correct in understanding that you want a list/station to be played every day, but not twice in a row?
Or do you want it programmed like that 14 days in advance?
(This is a big difference in how to handle it, option 1 is very simple with HOOP!, option 2 would require a bit more time to make a javascript you could use in HOOP functions)

If i recall it well you have a script for this, Marcel?
I think that would come in handy for Arie.

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

const RadioPrefix = 'http:%2F%2F' + IpAdres + ':' + Portnumber + '%2Fwoonkamer%2Ffavorite%2F';
const PlayListPrefix = 'http:%2F%2F'+ IpAdres + ':'+ Portnumber + '%2Fwoonkamer%2Fspotify%2Fnow%2Fspotify:user:spotify:playlist:';

//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

//string variables called PlayListDay1, PlayListDay2 and PlayListDay3, and three string variables
// called PlayListName1, PlayListName2 and PlayListName 3. The variable names are case sensitive.

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

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!