Panic button: how do i continuously play sound clip until simulated switch is turned off


#1

1) Give a description of the problem
how do i make an mp3 clip (dog barking) play continuously while a button (simulated switch) is on?
**2) What is the expected behavior?
mp3 clip (dog barking) will play continuously while a button (simulated switch) is on
3) What is happening/not happening?
the mp3 clip (dog barking) only plays a single clip.

4) Post a Green Snapshot of the pistonimage

5) Attach any logs (From ST IDE and by turning logging level to Full)
d93aeb69-851c-436d-97f3-6424900f895b 11:06:29 AM: debug â•‘â•‘ Executed physical command [Bedroom Speaker].playTrack([https://s3.amazonaws.com/smartapp-media/sonos/dogs.mp3]) (23ms)

d93aeb69-851c-436d-97f3-6424900f895b 11:06:29 AM: debug â•‘â•‘ Executed physical command [Angeloroom Speaker].playTrack([https://s3.amazonaws.com/smartapp-media/sonos/dogs.mp3]) (49ms)

d93aeb69-851c-436d-97f3-6424900f895b 11:06:29 AM: trace â•‘â•‘ Executed [Angeloroom Speaker].playTrack (51ms)

d93aeb69-851c-436d-97f3-6424900f895b 11:06:29 AM: trace â•‘â•‘ Executed [[Samsung] R1].playTrack (43ms)

d93aeb69-851c-436d-97f3-6424900f895b 11:06:29 AM: debug â•‘â•‘ Executed physical command [[Samsung] R1].playTrack([https://s3.amazonaws.com/smartapp-media/sonos/dogs.mp3]) (41ms)

d93aeb69-851c-436d-97f3-6424900f895b 11:06:29 AM: debug ║║ Cancelling condition #1’s schedules…

d93aeb69-851c-436d-97f3-6424900f895b 11:06:29 AM: debug ║║ Cancelling statement #3’s schedules…

d93aeb69-851c-436d-97f3-6424900f895b 11:06:29 AM: debug â•‘â•‘ Condition group #1 evaluated true (state changed) (10ms)

d93aeb69-851c-436d-97f3-6424900f895b 11:06:29 AM: trace ║╚ Execution stage started

d93aeb69-851c-436d-97f3-6424900f895b 11:06:29 AM: debug ║║ Cancelling condition #2’s schedules…

d93aeb69-851c-436d-97f3-6424900f895b 11:06:29 AM: trace â•‘ Runtime (37577 bytes) successfully initialized in 72ms (v0.3.109.20181207) (108ms)

d93aeb69-851c-436d-97f3-6424900f895b 11:06:29 AM: debug â•‘ RunTime Analysis CS > 19ms > PS > 72ms > PE > 16ms > CE

d93aeb69-851c-436d-97f3-6424900f895b 11:06:29 AM: info ╚ Received event [DOGBARK].switch = on with a delay of 81ms

thank you much in advance.


#2

Hi @macombweare,
Let me answer your question first but I will also recommend something else.

The reason why it plays once and stops is, your trigger is CHANGES TO. Meaning, the piston will not fire AGAIN because CHANGES TO is no longer the case.
If you add a condition to your trigger,

IF
Switch 19 CHANGES TO on (trigger)
and
Switch 19 IS ON (Condition)

now it will start playing when swtich is CHANGING and IS

But there is still a problem with that I had encountered.
Now, (I guess maybe depending on the speakers system) your recording will start AGAIN without finishing the fisrt time playing. And previous play will be interrupted by the next one.
Maybe in dog barking scenerio it would not make difference???

To stop that you can add WAIT
IF
Switch 19 CHANGES TO on (trigger)
and
Switch 19 IS ON (Condition)
then (NEVER CANCEL TASK)
With music players
Play track:
Wait 20 seconds (2-3 second longer than the clip size)

  • Let me know if you need explanation about NEVER CANCEL TASK

But having said that I would recommend something different:
Create a LONG CLIP in a simple sound editor.
I have a cat alarm (if a door left open more than 20 seconds)
The clip starts with an alert sound “Alert cat door is left open more than 20 seconds. Shut the door and check the cat” I looped this for 15 minutes in an audio editing program and uploaded…

Now my piston is just like yours,
No overlaping, no waiting for piston to trigger again and again etc…


#3

just tried to add (NEVER CANCEL TASK) but can’t seem to find it in any of the commands.

thank you again for your help…


#4

You are so welcome…

Click on WITH.
You will see a mechanical wheel icon… Clik on that…
TASK CANCELLATION POLICY… clik on
select NEVER CANCEL TASK
SAVE

You will see N with an orange circle around it


#5

Got it! Ill see how this works when i get home.

Re: dogbarking being interrupted may not be a bad idea afterall. If there was an intruder in the house wouldn’t this make the intruder think there are A LOT OF DOGS IN THE HOUSE? Lol

But with the sound editing would also be a good idea. Where would i have my file hosted? Would it be free?

Again my thanks.


#6

Where do you host the current one???

But anyway, I am sure the internet is full of free website and/or audio hosting places nowadays. Even the paid ones are like $40 a year (price of a single motion sensor LOL) You need something very basic that’s all.

Ussualy for annoucements I use my ownwebsites directory.
If it’s a playlist etc (two hours of nature sounds etc) I just host them in one of the spare computers in the local network by using Nicecast


#7

Its from s3.amazonaws.com/smartapp-media/sonos/dogs.mp3

I do have a BI server that can probably host the edited .MP3 file… i will just have to figure that out… my next step if THE above discussion does not work…

I know i cant thank you enough… so id have to say thank you a lot. .


#8

yeah any server will do it…
You are so welcome… my pleasure
Let us know how it goes…


#9

A Raspberry Pi can also act as a server, with a one time cost of $39 or less.
I plan on storing a bunch of MP3 sound effects on mine to add some fun events to my SmartHome.


#10

I like the RPi idea… I would be even faster because it will be local…


#11

I was pleasantly surprised that webCoRE can see the data stored on my Pi, even though I have not opened my Pi to the internet. It is actually seen as a local server!! (192.168.x.y)


#12

unfortunately the NEVER CANCEL TASK and addition of WHILE SWITCH IS ON (condition) did not work.

it still only played the clip once…


#13

ill be waiting for the write-up…


#14

pls post your piston… I believe I know what happened DUH!! (my fault)
Switch 19 CHANGES TO on (trigger) won’t be the case after first time. So piston will not fire again…
I made that mistake because as i said I use 15 minutes long mp3 so it doesn’t have to fire again…

But let me see the piston first…


#15

THANKS


#16

LINE 23
Click on AND
change LOGICAL AND to LOGICAL OR
That means, the piston will execute EITHER it CHANGES to ON or IS ON…


#17

thank you. will try again later when i get home. my thanks again.


#18

I will definitely be sharing a sample piston when mine is all setup, but I should probably mention now that I will not be looping any sound effects. If I need a long (repeating) sound, I will create my own audio file as long as I want.

I am choosing this path because there is no way for webCoRE to know when the track finishes playing. My webCoRE code will likely be: when X happens, start MP3, when Y happens, stop MP3.


#19

makes sense.

when i get a chance to do mine. id have my clip 15min. long. that should be more than enough to discourage intruders to stay any longer…

ive been long curious about pi setups. looks like another project coming for me…


#20

If this piston code is to be fired after the intruders enter your house, bright lights flashing on and off can be very disorienting. Paired with an obnoxious (loud) sound effect, and of course alerts sent to your phone, can all be helpful.

Mine also turns on an old school boombox and my TVs, all set to full volume. The more crazy stuff happening, the more they want to get out of there!