Audio notification on event

Hello,

Is there any way I can have a dashboard play an audio notification or alarm somehow if an event goes off?

I have created a dashboard that we need to watch, it is off on another screen that may not be actively monitored and sometimes an event goes unnoticed for a while.

I saw this: Audio alarm based on event

But not sure if anything came of it. I wonder if somehow the Custom HTML module can be used, but not sure where to start.

Hey @Danny_Nguyen,

This is possible, but you will need to use the Custom HTML Dashboard Block. With the Custom HTML Block, you can query device data which allows that data to be accessible in the body content of the HTML block.

Here’s an example that queries a temperature value, and plays a beep sound (stored in Application Files) if the temperature is over a certain value:

<script>
// sound file stored in application files
var sound = new Audio('https://files.onlosant.com/5f14713424d1dc0006eb47b1/beep-07.mp3')

// variable for temperature query
var tempValue

// max value that we want to alert for
var tempMax = 100

// check if the query was successful, if so, place the value of the query
// in tempValue
if(DashboardBlock.input.queries.temperature){
    tempValue = DashboardBlock.input.queries.temperature.value
}

// this function plays the sound
function playSound() {
    sound.play()
}

// if the value of the temperature query is greater than the max value
// we set, then play the sound
if(tempValue > tempMax){
    playSound()
}


</script>

<button onclick="playSound()">Press me to play a sound</button>

Here’s a picture of my query:

This code also places a button on the Custom HTML Block that when clicked plays the beep sound. The Audio API has good browser support, but you may run into an issue with Opera Mini.

Please let me know if this works for you!

Thank you,
Heath

Hi Heath,

Thanks for this!

Using your code, I can get a sound to make once it matches a certain string from last event created. The next problem is that the query fires every 5 seconds or so and the event sometimes stays for longer than 5 seconds so the beep happens every time the query refreshes and nothing new happened yet.

I think I can get around this by having the code create a new event that so that once the query fires next, it doesn’t match. Not sure if that’s doable, but that’s the idea currently in my head.