Jump to content

Welcome to Smart Home Forum by FIBARO

Dear Guest,

 

as you can notice parts of Smart Home Forum by FIBARO is not available for you. You have to register in order to view all content and post in our community. Don't worry! Registration is a simple free process that requires minimal information for you to sign up. Become a part of of Smart Home Forum by FIBARO by creating an account.

 

As a member you can:

  •     Start new topics and reply to others
  •     Follow topics and users to get email updates
  •     Get your own profile page and make new friends
  •     Send personal messages
  •     ... and learn a lot about our system!

 

Regards,

Smart Home Forum by FIBARO Team


  • 0

SONOS - play audio file


Question

Posted

Hi.

Can anyone share solution how to play mp3 file on Sonos. I use kirkof VD, but that is only for TTS.

My goal is to play some mp3 file when I change state of some variables in HC.

Thanks

9 answers to this question

Recommended Posts

  • 0
Guest spazpeker
Posted

that VD can do files as well, here is a scene i have to play a star trek red alert file from my NAS

 

--[[
%% properties
%% events
%% globals
--]]

-- 416 is the Virtual Device ID
-- 28 is the Process button ID
local sid, bid = 416, 28
-- Create STREAM params object
local params = {
  -- stream: the file / uri
  stream = "//DISKSTATION/music/redalert.mp3",
  -- source: "local" or "http", "local" is setted by default
  source = "local",
  -- duration: play duration in seconds (option) or "auto"
  duration = "auto",
  -- volume: the volume for playing the stream
  volume = 50
}
local _f = fibaro
local _x ={root="x_sonos_object",load=function(b)local c=_f:getGlobalValue(b.root)if string.len(c)>0 then local d=json.decode(c)if d and type(d)=="table"then return d else _f:debug("Unable to process data, check variable")end else _f:debug("No data found!")end end,set=function(b,e,d)local f=b:load()if f[e]then for g,h in pairs(d)do f[e][g]=h end else f[e]=d end;_f:setGlobal(b.root,json.encode(f))end,get=function(b,e)local f=b:load()if f and type(f)=="table"then for g,h in pairs(f)do if tostring(g)==tostring(e or"")then return h end end end;return nil end}
-- Make a request to the remote to process params object instantly
_x:set(tostring(sid), { stream = params })
_f:call(sid, "pressButton", bid)

  • 0
  • Inquirer
  • Posted

    Thanks. Working 100%.

    • 0
    Posted

    This is exactly what i need!! but i cant seem to get it working would it be possible for you to give me a pointer where to start?

    Many Thanks

    • 0
  • Inquirer
  • Posted

    First You need to have VD from Jean-Christophe Vermandé (Krikroff77) "SONOS Remote & Text To Speech (TTS)" .

    Than just in scene from spazpeker@ change stream path. If You use network location for your audio files adjust folder permission so that Fibaro can access it.

    Sonos remote VD is in att.

     

    Vedran

     

    Please login or register to see this attachment.

    • 0
    Posted

    Many thanks - for you explanation - i will try it now

     

    • 0
    Posted (edited)

    hi

    here is a link to my video it explains how to play mp3 files using the VD

    thanks

     

    Please login or register to see this link.

    Edited by morpheus75
    • Like 1
    • 0
    Posted

    It works, thank you very much! But are you also facing delay-problems? When I start playing the MP3-file (in my case a 6 second alarm sound) it's not that easy to stop it fast. It takes around 10 - 15 seconds until the VD accepts stopping the script. Even if you push directly on the buttons of the VD instance, it takes time.... any idea how I can fix that? Thanks!

    • 0
    Posted
    On 6/9/2018 at 7:30 PM, Veki said:

    First You need to have VD from Jean-Christophe Vermandé (Krikroff77) "SONOS Remote & Text To Speech (TTS)" .

    Than just in scene from spazpeker@ change stream path. If You use network location for your audio files adjust folder permission so that Fibaro can access it.

    Sonos remote VD is in att.

     

    Vedran

     

    Please login or register to see this attachment.

    Hi @Veki!

     

    I have just install the VD, and created a scene according to above stream.

    Should I create global variables or something, because I'm getting error message which shows there is something wrong with global variables, becuase the VD and the scene got NIL value.

     

    Here are the lines with the problems:

     

    local _x ={root="x_sonos_object",load=function(b)
    local c=_f:getGlobalValue(b.root) 
    if string.len(c)>0 then 
     

    The error message is 

     

    2020-04-29 22:00:48.847847 [ fatal] Unknown exception: /opt/fibaro/scenes/84.lua:25: bad argument #1 to 'len' (string expected, got nil)

     

    Do you have any idea what the wrong is?

     

    Thank you!

     

    Join the conversation

    You can post now and register later. If you have an account, sign in now to post with your account.

    Guest
    Answer this question...

    ×   Pasted as rich text.   Paste as plain text instead

      Only 75 emoji are allowed.

    ×   Your link has been automatically embedded.   Display as a link instead

    ×   Your previous content has been restored.   Clear editor

    ×   You cannot paste images directly. Upload or insert images from URL.

    ×
    ×
    • Create New...