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


  • 3

Sonos - Virtual Device


Guest deraaij

Question

Guest deraaij

Update: Please use TCP as of version 3.x as os.execute has been depreciated. As soon as we are able to have custom headers I will update the LUA code.

Hi all,

For those who are interested I made a Virtual Device based on the new LUA feature (inspired on lua code for MIOS) which can control a sonos device. It uses curl but will change it when the http api is documented. Change the IP address accruing to your needs.

EDIT: Added additional comments from other post which I posted in this thread.

EDIT: Changed req.lua --> /tmp/req.lua which works with beta 3.423 & 3.424

Play

Please login or register to see this code.

Stop

Please login or register to see this code.

Pause

Please login or register to see this code.

Previous

Please login or register to see this code.

Next

Please login or register to see this code.

Mute

Please login or register to see this code.

UnMute

Please login or register to see this code.

Volume – Not Working yet because we do not get the value off: _sliderValue_ @fibaro how does this work with Lua?

Please login or register to see this code.

Example Text-2-Speech using LUA in a scene:

Please login or register to see this code.

Remark: Play is initiated with the last statement to actual play the text (change it accordingly).

Example play song from network with LUA:

Please login or register to see this code.

Remark: Play is initiated with the last statement to actual play the song (change it accordingly).

Example radio station via LUA:

Please login or register to see this code.

Remark: Play is initiated with the last statement to actual play radio (change it accordingly). For now only the radio name is set.

Regards,

Mark[/b]

Link to comment
Share on other sites

Recommended Posts

  • 0
Guest David R
  • Inquirer
  • This is VD is good but if you have more than one Sonos in your house it sends them a bit crazy if there all not grouped together. Eg. press pause on kitchen will stop living room then press play on kitchen will start the bedroom. It sort of cycles through the different ip addresses

    Link to comment
    Share on other sites

    • 0

    deamrperry, sorry but its not working. The volume is not changing.

    When i move the slider it jumps back to prev. volume.

    I guess the problem is to read the slider value. How to get hold of that?

    [ Added: 2015-01-16, 23:26 ]

    Anyone knows how to solve this? Problem with the slider in 4.031?

    I can't get the Sonos Volume to work in LUA.

    Link to comment
    Share on other sites

    • 0

    I customized this great VD for personal use (again thanks) and created buttons for playing different radio channels.

    Also created (SONOS) Zone buttons, with this buttons you can simply add you SONOS to a specific Zone.

    Then I created I scene which adds the devices to one zone, Sets the Volume and plays a radio channel.

    Note: Make sure your SONOS devices keep the same IP (for example using DHCP reservation in your router). Create a Zone for every device (I got three) and import this VD tree times (off course using deferent IP’s).

    Now i need to find out how to play Spotify playlists using this VM….

    Please login or register to see this attachment.

    Please login or register to see this attachment.

    Link to comment
    Share on other sites

    • 0

    You think you can advice me in how to change SONOS volume slider using LUA?

    I have a VD for my TV but the volume is controlled by another IP a SONOS Speaker.

    So all buttons except the slider controls the TV and that works fine, but how to get the slider to work for SONOS?

    Link to comment
    Share on other sites

    • 0

    thanks for the VD. I have a question. The volume is working, but none of the radio stations are working. When am I looking TV and click on Veronica for example, the sound goes of, but no Veronica station. I have it with every other button.

    Link to comment
    Share on other sites

    • 0
    thanks for the VD. I have a question. The volume is working, but none of the radio stations are working. When am I looking TV and click on Veronica for example, the sound goes of, but no Veronica station. I have it with every other button.

    After you select a radio station u have to select play again....

    Here you can see i am not a real programmer, maybe someone could help you out

    Please login or register to see this image.

    /emoticons/default_icon_wink.gif" alt=";-)" />

    [ Added: 2015-01-24, 17:05 ]

    I just found out that you have to match your Virtual Device ID in the code in the ‘Main loop’ code section.

    You can find your Virtual ID by watching the URL while you are managing the Virtual device:

    For example: fibaro/nl/devices/virtual_edit.html?id=165

    It’s also important to set the IP address off the device in the Main loop. It’s mentioned twice!

    Please login or register to see this attachment.

    Please login or register to see this attachment.

    Link to comment
    Share on other sites

    • 0

    hello there

    i have managed to add the Sonos as a virtual device with the help of the codes i found here (very much appreciated, thank you guys!)

    now i want to make a scene to the queued song but cannot manage to get the code right, i know where the play code in the virtual device but i don't know what to do with it

    please advice

    Thank you

    Link to comment
    Share on other sites

    • 0

    whic tcp port shoul i use?

    if i put 1400 a can only get inform. from my sonos, but i cant control it. nothing work(play/pause/stop/slider.....)

    Link to comment
    Share on other sites

    • 0

    I customized this great VD for personal use (again thanks) and created buttons for playing different radio channels.

    Also created (SONOS) Zone buttons, with this buttons you can simply add you SONOS to a specific Zone.

    Then I created I scene which adds the devices to one zone, Sets the Volume and plays a radio channel.

    Note: Make sure your SONOS devices keep the same IP (for example using DHCP reservation in your router). Create a Zone for every device (I got three) and import this VD tree times (off course using deferent IP’s).

    Now i need to find out how to play Spotify playlists using this VM….

    HI

    can you please explain more  details how we can do it and where in virtual device because i have it working in 1 zone only every time  i add a second virtual device it control the first 1  but cant change the channels and i don't know how to join the zones i have 9 zone sonos 

    thanks in advance

    Tnx

    Link to comment
    Share on other sites

    • 0

    I customized this great VD for personal use (again thanks) and created buttons for playing different radio channels.

    Also created (SONOS) Zone buttons, with this buttons you can simply add you SONOS to a specific Zone.

    Then I created I scene which adds the devices to one zone, Sets the Volume and plays a radio channel.

    Note: Make sure your SONOS devices keep the same IP (for example using DHCP reservation in your router). Create a Zone for every device (I got three) and import this VD tree times (off course using deferent IP’s).

    Now i need to find out how to play Spotify playlists using this VM….

     

    Hi, can you please explain how do you add all loudspeakers to one zone? Thank you!

    Link to comment
    Share on other sites

    • 0

    Hi all. 

     

    Hope you can help me on this. 

     

    i have got the virtual device working AOK, Text to speech working and all going good.

     

    I though i'd try and make it so i can play an mp3/track from my Synology NAS but just can't get it to play at all. 

     

    The idea is, to have a virtual button hooked up to an MP3 so when a button is pressed, it will play that track. 

     

    Here is my code below: - 

     

    Please login or register to see this code.

    I have tried IP address and DNS name of my NAS with no joy:-( 
     
    I am very new to the LUA scene and just can't work out why this is not working. 
     
    I am unsure as well how to work out the Content-Length length.
     
    Any help on this would be greatly appreciated on this.
     
    Regards,
     
    Hal  
    Link to comment
    Share on other sites

    • 0

    hello agan

    i added the virtual device of my sonos as explained perfectly and can control it through my HC2 but i can't get it to work in a scene, the list of commands i can put in the LUA code is "pressButton" and when i put it and write the ID of the button i want to be pressed it doesn't work

    please advice

    thank you

    Link to comment
    Share on other sites

    • 0

    how to solve multi sonos environment ? I have two VD and basically it's working like that that "play" is playing one and another - not only defined one (f.e. kitchen)

    Link to comment
    Share on other sites

    • 0

     

    Hi all. 

     

    Hope you can help me on this. 

     

    i have got the virtual device working AOK, Text to speech working and all going good.

     

    I though i'd try and make it so i can play an mp3/track from my Synology NAS but just can't get it to play at all. 

     

    The idea is, to have a virtual button hooked up to an MP3 so when a button is pressed, it will play that track. 

     

    Here is my code below: - 

     

    Please login or register to see this code.

    I have tried IP address and DNS name of my NAS with no joy:-( 
     
    I am very new to the LUA scene and just can't work out why this is not working. 
     
    I am unsure as well how to work out the Content-Length length.
     
    Any help on this would be greatly appreciated on this.
     
    Regards,
     
    Hal  

     

    This something I would like to do. i.e. play an mp3 file. Has anyone an idea how to make it work or how to modify the code above

     

    Brian

    Link to comment
    Share on other sites

    • 0

    Hi all. 

     

    Hope you can help me on this. 

     

    i have got the virtual device working AOK, Text to speech working and all going good.

     

    I though i'd try and make it so i can play an mp3/track from my Synology NAS but just can't get it to play at all. 

     

    The idea is, to have a virtual button hooked up to an MP3 so when a button is pressed, it will play that track. 

     

    Here is my code below: - 

     

     

    Please login or register to see this code.

    I have tried IP address and DNS name of my NAS with no joy:-( 

     

    I am very new to the LUA scene and just can't work out why this is not working. 

     

    I am unsure as well how to work out the Content-Length length.

     

    Any help on this would be greatly appreciated on this.

     

    Regards,

     

    Hal

     

     

    This something I would like to do. i.e. play an mp3 file. Has anyone an idea how to make it work or how to modify the code above

     

    Brian

     

     

     

    Hal/ Brain,

     

    I use the following lua code (copyright: Jean-Christophe Vermandé) for playing an mp3;

    Please login or register to see this code.

    You have to make an virtual device. Put the ip-adress of the sonos device and it's port usually 1400. The above lua-script is used under a button.

     

    I use TTS (SONOS Virtual Device & Text To Speech (TTS) version 0.0.8) for dynamic text, the above script (Sonos play stream) i use for static text.

     

    For playing the mp3 from the nas it would be made available for guest accounts (setting NAS share Music for example), the mp3 file needs to be part of the SONOS library otherwise it will not play (setting in SONOS configuration, make share available to songs library).

     

    Make the adjustments necessary for your home environment;

     

    playFile("//UNC path/musicfilename.mp3", volume);

     

    Regards,

     

    PdG

    Link to comment
    Share on other sites

    • 0

    Hi D3v1ld0cs

     

    That's Brill. It worked first time. I had pulled something similar of his French forum but could not get it to work.

    Now to get those MP3 files made.

    Thanks again. Made my day

    Please login or register to see this image.

    /emoticons/default_icon_biggrin.gif" alt=":-D" />

     

    Brian

     
    Link to comment
    Share on other sites

    • 0

    Thanks! I was trying to solve sonos mp3 file playing for few weeks. Now everything works like a charm

    Please login or register to see this image.

    /emoticons/default_smile.png" alt=":)" srcset="https://forum.fibaro.com/uploads/emoticons/[email protected] 2x" width="20" height="20" />

    Link to comment
    Share on other sites

    • 0

    Hello

    Is there any chance to play from SONOS FAVORITES or SONOS PLAYLIST instead of mp3 file?

    Link to comment
    Share on other sites

    • 0

    Ok, to get the correct url do the following:

    1.) Play correct radio station on a zone.

    2.) Surf to

    Please login or register to see this link.

    3.) Take the correct url, and replace the one in the example code.

    Good luck!

     

    Hello, thank you for this great topic. It helps a lot. But I still have problems playing a radio station via TCP.  I did (several times now) steps mentioned above. If I got it right you first have to press the button with the radio station and after that the play button. But nothing happens. Sonos keeps playing current song or starts playing the current song in the playlist. I also tested the code with 0x0D0x0A0x0D0x0A at the end - no luck. It would be very great if someone could help me out here, please. At my HC2 there is Version 4.040 running

    Link to comment
    Share on other sites

    • 0

    Hello, thank you for this great topic. It helps a lot. But I still have problems playing a radio station via TCP.  I did (several times now) steps mentioned above. If I got it right you first have to press the button with the radio station and after that the play button. But nothing happens. Sonos keeps playing current song or starts playing the current song in the playlist. I also tested the code with 0x0D0x0A0x0D0x0A at the end - no luck. It would be very great if someone could help me out here, please. At my HC2 there is Version 4.040 running

    Hello

     

    I made it this way : copy all addresses from RADIOLOG and made .m3u  playlist file - and then put link to this file - works ok.

    playFile("//192.168.2.155/music/3.m3u", 30);

     

    But I have another issue - MP3 plays only for 30 sec and stops autmaticly - anyone knows why?

    Link to comment
    Share on other sites

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