Hi
I have set up some flows to announcements setup using tts to my google Home speakers.
That is functioning fine, but I would like to have like 4 different flows or different cards that it should randomly choose to play from.
But I have know idea how to set it up so that when the main flow runs it should choose between 4 different announcements randomly.
Is there a simple example of setting op a flow that can do that.
Hope someone can help.
Something like this (to get the idea).
The logics condition āproceed with a chance of x %ā is key here. It works with numbers around 49 and up (49.1).
Optional: I made a Logics numeric variable, so I can change the x % number (for finetuning) for all flows at once
The idea is workable, but the trigger for all subsequent flows should be āthis flow was startedā. Now they all go off at movement, and you get double actions. You also have the fact that the probability that the next flow is triggered decreases each time due to multiplication of the probability factors. I canāt think off the top of my head which probabilities you need to fill in to get a fair distribution. Im guessing it should be 25%, 33%, 50% and 100% if you have four options.
Another option is to use better logic, which can do math.js calculations and can probably generate a random number. then you can make a flow ladder like this testing which number came out. Or you could go for Homeyscript.
If you can use Homeyscript you could adjust this script. It was written to randomly play 14 different radiostations and playlist. You can use it to randomly fill one variable. That variable can be used because it is randomly filled. After it was executed you let the script run again to randomly fill this variable again
Have you tested with each flow with the right trigger, and tested by counting each option for large amounts? Because if you daisychain the flows then the first definitely has a higher chance than the next. Especially at 49 percent, because if the first option already has 49% chance, thereās only 51% chance left for the other three to even be considered.
By the way, if the last flow has a percentage chance of doing something, then thereās also a chance nothing happens. Hence my 100% chance at the end. If you didnāt pick any of the first three, thereās only one choice left. And if youād consider looping back to the first flow, then you would increase the chance of the first option being chosen even more.
That is partially true. The random value should be evenly distributed, othersise it would be a useless function. But you use round, which means the first and the last value have only half the chance (due to the first option never having a chance rounding up, and the last value never having a chance of rounding down). So if you want to round, you should range from 0.5 to 4.499 to get an even distribution from 1 to 4.
This all is assuming the random function returns a decimal value from 0 to 4 and not an integer value.
Youāre right, the condition isnāt needed there.
But I just quickly picked the flows from an example and just wanted to point out the āproceed with a chance ofā logics condition card is the trick.
Like I said, Iāve tested it multiple times, other users too with a similar result.
It is not random.
-Who feeds the cat / Wie voert de kat-
Used ligics / Gebruikte logica {{round(random(1,4))}}
Who's turn was it / Wie is aan de beurt geweest (view the log below / zie log)
Nr. 1: 25x
Nr. 2: 36x
Nr. 3: 44x
Nr. 4: 12x
Trigger flow:
https://homey.app/f/KONH6x
Log:
2021-03-18 05:10.01.051 Flow [0-4] Wie voert de kat: nummer 1
2021-03-18 05:15.01.527 Flow [0-4] Wie voert de kat: nummer 3
2021-03-18 05:20.01.347 Flow [0-4] Wie voert de kat: nummer 4
2021-03-18 05:25.01.672 Flow [0-4] Wie voert de kat: nummer 1
2021-03-18 05:30.08.431 Flow [0-4] Wie voert de kat: nummer 2
2021-03-18 05:35.04.709 Flow [0-4] Wie voert de kat: nummer 2
2021-03-18 05:40.01.383 Flow [0-4] Wie voert de kat: nummer 1
2021-03-18 05:45.02.285 Flow [0-4] Wie voert de kat: nummer 3
2021-03-18 05:50.01.671 Flow [0-4] Wie voert de kat: nummer 2
2021-03-18 05:55.01.340 Flow [0-4] Wie voert de kat: nummer 2
2021-03-18 06:00.01.625 Flow [0-4] Wie voert de kat: nummer 3
2021-03-18 06:05.01.418 Flow [0-4] Wie voert de kat: nummer 2
2021-03-18 06:10.01.355 Flow [0-4] Wie voert de kat: nummer 2
2021-03-18 06:15.01.439 Flow [0-4] Wie voert de kat: nummer 2
2021-03-18 06:20.01.342 Flow [0-4] Wie voert de kat: nummer 1
2021-03-18 06:25.01.455 Flow [0-4] Wie voert de kat: nummer 4
2021-03-18 06:30.01.469 Flow [0-4] Wie voert de kat: nummer 3
2021-03-18 06:35.01.751 Flow [0-4] Wie voert de kat: nummer 1
2021-03-18 06:40.01.839 Flow [0-4] Wie voert de kat: nummer 2
2021-03-18 06:45.01.267 Flow [0-4] Wie voert de kat: nummer 2
2021-03-18 06:50.01.847 Flow [0-4] Wie voert de kat: nummer 2
2021-03-18 06:55.01.284 Flow [0-4] Wie voert de kat: nummer 3
2021-03-18 07:00.01.743 Flow [0-4] Wie voert de kat: nummer 2
2021-03-18 07:05.01.205 Flow [0-4] Wie voert de kat: nummer 4
2021-03-18 07:10.01.247 Flow [0-4] Wie voert de kat: nummer 1
2021-03-18 07:15.01.341 Flow [0-4] Wie voert de kat: nummer 3
2021-03-18 07:20.01.263 Flow [0-4] Wie voert de kat: nummer 1
2021-03-18 07:25.02.046 Flow [0-4] Wie voert de kat: nummer 2
2021-03-18 07:30.01.296 Flow [0-4] Wie voert de kat: nummer 3
2021-03-18 07:35.01.893 Flow [0-4] Wie voert de kat: nummer 1
2021-03-18 07:40.01.357 Flow [0-4] Wie voert de kat: nummer 1
2021-03-18 07:45.01.495 Flow [0-4] Wie voert de kat: nummer 4
2021-03-18 07:50.01.600 Flow [0-4] Wie voert de kat: nummer 2
2021-03-18 07:55.01.511 Flow [0-4] Wie voert de kat: nummer 1
2021-03-18 08:00.01.459 Flow [0-4] Wie voert de kat: nummer 2
2021-03-18 08:05.01.308 Flow [0-4] Wie voert de kat: nummer 3
2021-03-18 08:10.02.066 Flow [0-4] Wie voert de kat: nummer 4
2021-03-18 08:15.01.459 Flow [0-4] Wie voert de kat: nummer 3
2021-03-18 08:20.01.278 Flow [0-4] Wie voert de kat: nummer 3
2021-03-18 08:25.01.676 Flow [0-4] Wie voert de kat: nummer 1
2021-03-18 08:30.01.321 Flow [0-4] Wie voert de kat: nummer 1
2021-03-18 08:35.01.323 Flow [0-4] Wie voert de kat: nummer 4
2021-03-18 08:40.01.349 Flow [0-4] Wie voert de kat: nummer 2
2021-03-18 08:45.01.460 Flow [0-4] Wie voert de kat: nummer 4
2021-03-18 08:50.01.521 Flow [0-4] Wie voert de kat: nummer 3
2021-03-18 08:55.01.610 Flow [0-4] Wie voert de kat: nummer 3
2021-03-18 09:00.01.435 Flow [0-4] Wie voert de kat: nummer 1
2021-03-18 09:05.02.057 Flow [0-4] Wie voert de kat: nummer 1
2021-03-18 09:10.01.251 Flow [0-4] Wie voert de kat: nummer 3
2021-03-18 09:15.01.359 Flow [0-4] Wie voert de kat: nummer 3
2021-03-18 09:20.01.255 Flow [0-4] Wie voert de kat: nummer 3
2021-03-18 09:25.01.315 Flow [0-4] Wie voert de kat: nummer 2
2021-03-18 09:30.01.241 Flow [0-4] Wie voert de kat: nummer 2
2021-03-18 09:35.01.287 Flow [0-4] Wie voert de kat: nummer 3
2021-03-18 09:40.01.337 Flow [0-4] Wie voert de kat: nummer 4
2021-03-18 09:45.01.565 Flow [0-4] Wie voert de kat: nummer 2
2021-03-18 09:50.01.382 Flow [0-4] Wie voert de kat: nummer 2
2021-03-18 09:55.01.373 Flow [0-4] Wie voert de kat: nummer 3
2021-03-18 10:00.01.355 Flow [0-4] Wie voert de kat: nummer 3
2021-03-18 10:05.01.388 Flow [0-4] Wie voert de kat: nummer 1
2021-03-18 10:10.01.225 Flow [0-4] Wie voert de kat: nummer 1
2021-03-18 10:15.01.295 Flow [0-4] Wie voert de kat: nummer 1
2021-03-18 10:20.01.280 Flow [0-4] Wie voert de kat: nummer 1
2021-03-18 10:25.02.413 Flow [0-4] Wie voert de kat: nummer 3
2021-03-18 10:30.04.571 Flow [0-4] Wie voert de kat: nummer 2
2021-03-18 10:35.01.357 Flow [0-4] Wie voert de kat: nummer 1
2021-03-18 10:40.01.293 Flow [0-4] Wie voert de kat: nummer 3
2021-03-18 10:45.01.621 Flow [0-4] Wie voert de kat: nummer 4
2021-03-18 10:50.02.241 Flow [0-4] Wie voert de kat: nummer 2
2021-03-18 10:55.01.222 Flow [0-4] Wie voert de kat: nummer 3
2021-03-18 11:00.01.229 Flow [0-4] Wie voert de kat: nummer 2
2021-03-18 11:05.01.577 Flow [0-4] Wie voert de kat: nummer 4
2021-03-18 11:10.01.226 Flow [0-4] Wie voert de kat: nummer 3
2021-03-18 11:15.01.249 Flow [0-4] Wie voert de kat: nummer 1
2021-03-18 11:20.01.246 Flow [0-4] Wie voert de kat: nummer 3
2021-03-18 11:25.01.259 Flow [0-4] Wie voert de kat: nummer 1
2021-03-18 11:30.01.394 Flow [0-4] Wie voert de kat: nummer 3
2021-03-18 11:35.01.392 Flow [0-4] Wie voert de kat: nummer 3
2021-03-18 11:40.04.606 Flow [0-4] Wie voert de kat: nummer 3
2021-03-18 11:45.01.458 Flow [0-4] Wie voert de kat: nummer 3
2021-03-18 11:50.01.189 Flow [0-4] Wie voert de kat: nummer 3
2021-03-18 11:55.01.684 Flow [0-4] Wie voert de kat: nummer 3
2021-03-18 12:00.01.247 Flow [0-4] Wie voert de kat: nummer 2
2021-03-18 12:05.01.391 Flow [0-4] Wie voert de kat: nummer 4
2021-03-18 12:10.02.050 Flow [0-4] Wie voert de kat: nummer 1
2021-03-18 12:15.01.211 Flow [0-4] Wie voert de kat: nummer 3
2021-03-18 12:20.01.279 Flow [0-4] Wie voert de kat: nummer 2
2021-03-18 12:25.01.697 Flow [0-4] Wie voert de kat: nummer 2
2021-03-18 12:30.01.463 Flow [0-4] Wie voert de kat: nummer 3
2021-03-18 12:35.01.398 Flow [0-4] Wie voert de kat: nummer 3
2021-03-18 12:40.01.236 Flow [0-4] Wie voert de kat: nummer 3
2021-03-18 12:45.01.488 Flow [0-4] Wie voert de kat: nummer 2
2021-03-18 12:50.02.028 Flow [0-4] Wie voert de kat: nummer 1
2021-03-18 12:55.01.469 Flow [0-4] Wie voert de kat: nummer 3
2021-03-18 13:00.01.310 Flow [0-4] Wie voert de kat: nummer 1
2021-03-18 13:05.02.345 Flow [0-4] Wie voert de kat: nummer 3
2021-03-18 13:10.01.354 Flow [0-4] Wie voert de kat: nummer 2
2021-03-18 13:15.01.292 Flow [0-4] Wie voert de kat: nummer 3
2021-03-18 13:20.01.319 Flow [0-4] Wie voert de kat: nummer 2
2021-03-18 13:25.01.332 Flow [0-4] Wie voert de kat: nummer 2
2021-03-18 13:30.01.555 Flow [0-4] Wie voert de kat: nummer 2
2021-03-18 13:35.02.042 Flow [0-4] Wie voert de kat: nummer 3
2021-03-18 13:40.01.237 Flow [0-4] Wie voert de kat: nummer 2
2021-03-18 13:45.01.272 Flow [0-4] Wie voert de kat: nummer 2
2021-03-18 13:50.01.423 Flow [0-4] Wie voert de kat: nummer 1
2021-03-18 13:55.01.191 Flow [0-4] Wie voert de kat: nummer 3
2021-03-18 14:00.01.302 Flow [0-4] Wie voert de kat: nummer 3
2021-03-18 14:05.01.789 Flow [0-4] Wie voert de kat: nummer 2
2021-03-18 14:10.01.397 Flow [0-4] Wie voert de kat: nummer 4
2021-03-18 14:15.01.405 Flow [0-4] Wie voert de kat: nummer 3
2021-03-18 14:20.01.233 Flow [0-4] Wie voert de kat: nummer 3
2021-03-18 14:25.01.868 Flow [0-4] Wie voert de kat: nummer 3
2021-03-18 14:30.01.363 Flow [0-4] Wie voert de kat: nummer 2
2021-03-18 14:35.01.339 Flow [0-4] Wie voert de kat: nummer 2
2021-03-18 14:40.01.372 Flow [0-4] Wie voert de kat: nummer 3
2021-03-18 14:45.01.900 Flow [0-4] Wie voert de kat: nummer 3
2021-03-18 14:46.21.471 Flow [0-4] Wie voert de kat: nummer 2
So, is it possible to test with 0.5 to 4.5 like I said? Because what I predicted seems to happen, the first and last have approx. half the chance. If you cannot use fractions as the start and end, then you should use truncation, not rounding. That, and you should test way more times for the values to truly converge.
Should be 0.5 and 4.499999 by the way, otherwise thereās a chance youāll get 5.
Your version seems like a fine way to determine who feeds the cat though, as long as it is Mom, daughter, son, dad
Did a little test myself, now with the right range. The delays are to prevent Homey from killing the flow for running too often and to make sure the calculation is done when the result is counted:
After 825 steps the division is: 197/212/205/211 and that is not that bad for this low a testcount. After 8782 steps the division is 2217/2163/2169/2233. Again, pretty good. So my conclusion is: if you do the range right, thereās nothing wrong with the random function. @Peter_Kawa, hope your family will now be able to trust Homey to pick whoāll feed the cat, and @Dalle do these flows give you enough of an idea how to build your announcements?
It will probably look something like this If you do not want to delay the announcement itself:
Flow 1: if this flow was started then let TextToSpeach cast variable NextAnnouncementText to a chromecast device,
and calculate variable NextAnnouncement to {{round(random(0.5,4.4999))}} with a delay of a 5 seconds
Flow 2: If variable NextAnnouncement changes and NextAnnouncement equals 1 then set variable NextAnnouncementText to text1
Flow 3: If variable NextAnnouncement changes and NextAnnouncement equals 2 then set variable NextAnnouncementText to text2
Flow 4: If variable NextAnnouncement changes and NextAnnouncement equals 3 then set variable NextAnnouncementText to text3
Flow 5: If variable NextAnnouncement changes and NextAnnouncement equals 4 then set variable NextAnnouncementText to text4
Note that the very first time youāll have to set the text yourself or run the first flow once more, as the next announcement text is determined 5 seconds after the announcement was made. These delays are needed because Homey runs all cards at the same time and things may not happen in the right order. I used 5 seconds because I thought text to speach and casting would take some time, but you can probably safely set the delay much lower because the variable will probably be used only at the very start of the texttospeach card.
Hi and thanks for the examples, I will try this later today and see if I can understand how et works.
IĀ“am new to the logic part so I will see if I can understand how to get the tts flows to be incorporated.
Have you looked at the test flows I shared? All the building blocks are there to create the random text. The actual flows you need to build your original question are below in text.
Maybe looking at the tutorial Getting Started - Logic variables will help you on your way how to create the cards you need.
I cannot speak for the poster, but I wouldnāt want to have the announcement twice. One of which is in the wrong place, close to a kids bedroom.
The other reason is that picking something at random is a useful thing to be able to for other applications as well. So learning about that is useful for other things too, when it is not logical to have homey speak to get things done.
Hi again I have finally got it to function, hurray my first flow with logic cards and variables
But it is a lot of flows to create for this type of functionality.
It would have been great if there was a card that could just choose from a list of flows that you give it.
Thanks a lot for your help.
Youāre welcome. Homey often requires more flows. It is a consequence of how they designed it to be both simple, powerful and efficient at the same time. The trick is not to worry too much about it, but organize them nicely in folders and use descriptive nam3s.