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

Challenge : LUA scene for KeyFob volume buttons


peterburgering

Question

Hi all, I have a HC2 and I am trying to connect my KeyFob to my Sonos Playbar to set the volume. I already have it working but now I am finetuning and cannot get to the end. I have programmed my "+" and "-" button on the KeyFob so that they set the volume up and down. But I want to have it more sophisticated. My goal is when I push "+" the volume goes up by 1 on every click. And goes down by 1 when clicking the "-" button. But I need some help with this. 


Does someone here know how I can create the correct LUA code for this?? 

 

Here below the current situation in the scene for the KeyFob:

 

--[[
%% properties
%% events
263 CentralSceneEvent
%% globals
--]]

local sa = fibaro:getSourceTrigger()["event"]["data"]
--fibaro:debug(json.encode(sa))


if ((sa['keyId'] == 1) and (sa['keyAttribute'] ==  'Pressed'))
  then 
  fibaro:debug('key1') 
end

if ((sa['keyId'] == 1) and (sa['keyAttribute'] ==  'Pressed2'))
  then 
  fibaro:debug('key1 double') 
end

if ((sa['keyId'] == 1) and (sa['keyAttribute'] ==  'Pressed3'))
  then 
  fibaro:debug('key1 triple') 
end

if ((sa['keyId'] == 1) and (sa['keyAttribute'] ==  'HeldDown'))
  then 
  fibaro:debug('key1 held') 
end

if ((sa['keyId'] == 1) and (sa['keyAttribute'] ==  'Released'))
  then 
  fibaro:debug('key1 release') 
end


if ((sa['keyId'] == 2) and (sa['keyAttribute'] ==  'Pressed'))
  then 
  --fibaro:debug('key2') 
  fibaro:call(348, "setMute", "1")
end

if ((sa['keyId'] == 2) and (sa['keyAttribute'] ==  'Pressed2'))
  then 
  --fibaro:debug('key2 double')
  fibaro:call(348, "setMute", "0")
end

if ((sa['keyId'] == 2) and (sa['keyAttribute'] ==  'Pressed3'))
  then 
  fibaro:debug('key2 triple') 
end

if ((sa['keyId'] == 2) and (sa['keyAttribute'] ==  'HeldDown'))
  then 
  fibaro:debug('key2 held') 
end

if ((sa['keyId'] == 2) and (sa['keyAttribute'] ==  'Released'))
  then 
  fibaro:debug('key2 release') 
end


if ((sa['keyId'] == 3) and (sa['keyAttribute'] ==  'Pressed'))
  then 
  fibaro:debug('key3') 
end

if ((sa['keyId'] == 3) and (sa['keyAttribute'] ==  'Pressed2'))
  then 
  fibaro:debug('key3 double') 
end

if ((sa['keyId'] == 3) and (sa['keyAttribute'] ==  'Pressed3'))
  then 
  fibaro:debug('key3 triple') 
end

if ((sa['keyId'] == 3) and (sa['keyAttribute'] ==  'HeldDown'))
  then 
  fibaro:debug('key3 held') 
end

if ((sa['keyId'] == 3) and (sa['keyAttribute'] ==  'Released'))
  then 
  fibaro:debug('key3 release') 
end


if ((sa['keyId'] == 4) and (sa['keyAttribute'] ==  'Pressed'))
  then 
  fibaro:debug('key4') 
end

if ((sa['keyId'] == 4) and (sa['keyAttribute'] ==  'Pressed2'))
  then 
  fibaro:debug('key4 double') 
end

if ((sa['keyId'] == 4) and (sa['keyAttribute'] ==  'Pressed3'))
  then 
  fibaro:debug('key4 triple') 
end

if ((sa['keyId'] == 4) and (sa['keyAttribute'] ==  'HeldDown'))
  then 
  fibaro:debug('key4 held') 
end

if ((sa['keyId'] == 4) and (sa['keyAttribute'] ==  'Released'))
  then 
  fibaro:debug('key4 release') 
end


if ((sa['keyId'] == 5) and (sa['keyAttribute'] ==  'Pressed'))
  then 
  --fibaro:debug('key5') 
  fibaro:call(348, "setVolume", "10")
end

if ((sa['keyId'] == 5) and (sa['keyAttribute'] ==  'Pressed2'))
  then 
  --fibaro:debug('key5 double')
  fibaro:call(348, "setVolume", "5")
end

if ((sa['keyId'] == 5) and (sa['keyAttribute'] ==  'Pressed3'))
  then 
  fibaro:debug('key5 triple') 
end

if ((sa['keyId'] == 5) and (sa['keyAttribute'] ==  'HeldDown'))
  then 
  fibaro:debug('key5 held') 
end

if ((sa['keyId'] == 5) and (sa['keyAttribute'] ==  'Released'))
  then 
  fibaro:debug('key5 release') 
end


if ((sa['keyId'] == 6) and (sa['keyAttribute'] ==  'Pressed'))
  then 
  --fibaro:debug('key6') 
  fibaro:call(348, "currentVolume", "12")

end

if ((sa['keyId'] == 6) and (sa['keyAttribute'] ==  'Pressed2'))
  then 
  --fibaro:debug('key6 double') 
  fibaro:call(348, "setVolume", "15")
end

if ((sa['keyId'] == 6) and (sa['keyAttribute'] ==  'Pressed3'))
  then 
  --fibaro:debug('key6 triple')
  fibaro:call(348, "setVolume", "17")
end

if ((sa['keyId'] == 6) and (sa['keyAttribute'] ==  'HeldDown'))
  then 
  fibaro:debug('key6 held') 
end

if ((sa['keyId'] == 6) and (sa['keyAttribute'] ==  'Released'))
  then 
  fibaro:debug('key6 release') 
end


 

Link to comment
Share on other sites

0 answers to this question

Recommended Posts

There have been no answers to this question yet

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