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

MP3 based on movement and variable


Question

Posted (edited)

Hi all! I´ve tried to create a scene with a mp3 playing "good morning" through my sonos. I`ve borrowed part of the scen from Krikroff and his part is working perfectly.... My plan is that this scen is going to be started every morning by Sankotroniks Main scene and triggered by a motionssensor and a variable.... The scene is only suppose to play itself once in the morning and then set  the variable to zero and the kill the scene itself.... But i`ve missed something... Any Ideas?

 

Best regards

Pettzon

 

 

 

 

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

fibaro:debug(" SCENE START ")
if fibaro:countScenes() > 1 then
fibaro:debug(" SCENE ABORT - too many instances ")
fibaro:abort()
end

local startSource = fibaro:getSourceTrigger();
if (
 ( tonumber(fibaro:getValue(87, "value")) > 0 )
    )
   
and
  fibaro:debug(" ... have movements... ")
 ( tonumber(fibaro:getGlobalValue("GoodMorningTTS")) == tonumber("1") )  
then
 
  fibaro:debug(" ...Have got the right variable... ")

    -- 78 is the Virtual Device ID
-- 28 is the Process button ID
local sid, bid = 106, 28
-- Create STREAM params object
local params = {
  -- stream: the file / uri
  stream = "//Diskstation/data program/Fibaro Home Center/Mp3/Välkommen till familjen Pettersson.mp3",
  -- source: "local" or "http", "local" is setted by default
  source = "local",
  -- duration: play duration in seconds (option) or "auto"
  duration = 8,
  -- volume: the volume for playing the stream
  volume = 40
}
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)
 
 -- Ändra variabel
  fibaro:setGlobal("GoodMorningTTS", 0)
 
  fibaro:debug(" ...put variable to zero... ")

 -- Kill running scene cause it is done with appliance
  fibaro:abort();
 
  fibaro:debug(" ... Scene aborted! ")

end

 

Edited by pettzon
typo

3 answers to this question

Recommended Posts

  • 0
Posted

The topic has been moved from "

Please login or register to see this link.

" to "

Please login or register to see this link.

".

 

Temat został przeniesiony z "

Please login or register to see this link.

" do "

Please login or register to see this link.

".

  • 0
Posted

Hi @pettzon,

 

You put debug function in the middle of condition checking. Try bellow code:

Please login or register to see this code.

Also you need to add motion sensor to scene header to be triggered by it otherwise it will be triggered only once when global variable is changed and if in that moment sensor is still safe then you will never hear that greeting!

 

  • 0
  • Inquirer
  • Posted

    Oh! Sloppy mistakes!!! Thanks for your great help!!! :)

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