Posts: 26
Threads: 2
Joined: Jul 2015
Reputation:
0
09.09.2019, 11:45
(This post was last modified: 09.09.2019, 11:47 by Hippolyte.)
Hello everyone
I have been following this conversation for the last year and implementend the SE version which was working nicely.
I'd like to test this new app and more specifically the new Sonos API. Has anyone manage to control their Sonos with the new API ?
I am completely stuck with all theses :
Create authorization code -> https://developer.sonos.com/reference/au...tion-code/
Create token -> https://developer.sonos.com/reference/au...ate-token/
etc ...
I don't know what part is already done by the LM Sonos App itself and what part should I do to have a simple script doing play/pause (without using the objects automatically created but fully Sonos API) ? https://developer.sonos.com/reference/co...back/play/
Anyone could help us on that ?
Thank you very much.
Posts: 1764
Threads: 6
Joined: Jul 2015
Reputation:
117
10.09.2019, 21:47
(This post was last modified: 10.09.2019, 21:50 by Erwin van der Zwart.)
Hi,
The old version of the Sonos app was created by me, in that app i created a self build API that was able to receive HTTP command with arguments and those where converted to LUA commands to SOAP (UpnP).
The new version of the app is build by our development department and the decission was made to certify the app to be able to use the official Sonos API, due to this certification we where forced to drop the self build API in the app. Now you can only use the objects that are created automatically by adding them to the touch application.
There is no build in mechanisme to send HTTP commands to the app anymore in the new version.
We still can use the old .lp API by uploading it to the ftp folder, but i still need to make some adjustments as the old app performed a auto scan of Sonos devices on startup that is now missing in the .lp file, but i have no time this moment to do it.
BR,
Erwin
Posts: 4635
Threads: 24
Joined: Aug 2017
Reputation:
207
Hi
Here is how to use new Sonos app via script:
The app runs a daemon which keeps communication with each player/group The daemon will be closed down after 120s if no update is send so we need to run such script every 60s to keep communication up and running.
Code: require('custom.sonos.lib')
groupID=sonos_app.GetStoragePlayerGroups()
for k, v in pairs(groupID) do
sonos_app.SendApiActionCommand(k, 'watchPlayerGroup', os.time())
end
To control the players we need to know groupID which can be read via such command.
Code: groupID=sonos_app.GetStoragePlayerGroups()
Basic control is done like this
Code: -- simle command: play, pause, skipToPrev, skipToNext
sonos_app.SendApiActionCommand(url_group_id, 'play')
Code: -- set volume
sonos_app.SendApiActionCommand(url_group_id, 'setVolume', 50)
The url_group_id is in the table from the groupID but it can be read automatically when we know group name so example start/pause script would looks like that.
Code: require('custom.sonos.lib')
groupName='Kitchen'
-------------------------------------------------------------
groupID=sonos_app.GetStoragePlayerGroups()
for k, v in pairs(sonos_app.GetStoragePlayerGroups()) do
if groupID[k].groupName == groupName then
groupID=k
break
end
end
-------------------------------------------------------------
value = event.getvalue()
if value then
sonos_app.SendApiActionCommand(groupID, 'play')
else
sonos_app.SendApiActionCommand(groupID, 'pause')
end
To read Playlist table use this
Code: sonos_app.GetStoragePlayerGroupData(groupID, 'Playlists')
To Play a playlist
Code: -- play playlist by ID
sonos_app.SendApiActionCommand(url_group_id, 'playPlaylist', playlist_id)
playlist_id looks like a number but it is a string!
To read Favorites use
Code: sonos_app.GetStoragePlayerGroupData(groupID, 'Favorites')
To play a Favorites
Code: sonos_app.SendApiActionCommand(url_groupID, 'playFavorite', url_favID)
------------------------------
Ctrl+F5
Posts: 26
Threads: 2
Joined: Jul 2015
Reputation:
0
Thank you very much Erwin and Daniel for you answers !
Posts: 185
Threads: 38
Joined: Feb 2017
Reputation:
3
06.10.2019, 13:09
(This post was last modified: 06.10.2019, 13:12 by Trond Hoyem.)
(11.09.2019, 07:47)Daniel. Wrote: Hi
Here is how to use new Sonos app via script:
The app runs a daemon which keeps communication with each player/group The daemon will be closed down after 120s if no update is send so we need to run such script every 60s to keep communication up and running.
Code: require('custom.sonos.lib')
groupID=sonos_app.GetStoragePlayerGroups()
for k, v in pairs(groupID) do
sonos_app.SendApiActionCommand(k, 'watchPlayerGroup', os.time())
end
Hi Daniel
Is there a command for reading the volume level? If one wants a slider for volume, it would be good to be able to update the slider if the volume is changed from somewhere else than the LM-object.
There are 10 kinds of people in the world; those who can read binary and those who don't
Posts: 4635
Threads: 24
Joined: Aug 2017
Reputation:
207
I think it is in the table when you read this.
Code: groupID=sonos_app.GetStoragePlayerGroups()
------------------------------
Ctrl+F5
Posts: 4635
Threads: 24
Joined: Aug 2017
Reputation:
207
I just checked and there is no volume in there. You can read it this way
Code: groupstate = storage.get('app:se-sa:' .. groupID .. ':GroupVolume')
It will give you a table like this
* table:
["fixed"]
* bool: false
["volume"]
* number: 35
["muted"]
* bool: false
------------------------------
Ctrl+F5
Posts: 185
Threads: 38
Joined: Feb 2017
Reputation:
3
(07.10.2019, 11:54)Daniel. Wrote: I just checked and there is no volume in there. You can read it this way
Code: groupstate = storage.get('app:se-sa:' .. groupID .. ':GroupVolume')
It will give you a table like this
* table:
["fixed"]
* bool: false
["volume"]
* number: 35
["muted"]
* bool: false OK, thx
Will try this.
There are 10 kinds of people in the world; those who can read binary and those who don't
Posts: 59
Threads: 3
Joined: Nov 2016
Reputation:
0
26.10.2019, 04:28
(This post was last modified: 26.10.2019, 05:39 by Igor68.)
Hi, please help!)) Sonos does not play files with the old API ... (( where could there be an error?
require('socket.url')
require('socket.http')
socket.http.TIMEOUT = 5
reply = socket.http.request('http://198.168.0.10/user/sonos.lp?action=getsonosdata')
file = socket.url.escape('http://admin:pass@192.168.0.10/user/Mix_Lastochka.mp3')
reply = socket.http.request('http://admin:pass@192.168.0.10/user/sonos.lp?action=say&ip=192.168.0.32&audiofile=' .. file .. '&volume=90&duration=10')
log(reply)
Posts: 59
Threads: 3
Joined: Nov 2016
Reputation:
0
Event for sonos (32/5/56) 26.10.2019 12:41:35
* string: Error in /www/user/sonos.lp at line 544: attempt to index global 'sonos' (a nil value)
Posts: 4635
Threads: 24
Joined: Aug 2017
Reputation:
207
New app do not support those libraries. You can install old app, link below, or you can manually upload libraries from old app. All was explained here just read this thread few pages back.
https://forum.logicmachine.net/showthrea...3#pid13173
------------------------------
Ctrl+F5
Posts: 1764
Threads: 6
Joined: Jul 2015
Reputation:
117
Hi,
Just tested this, and is still working, you cannot send a mp3 to the Sonos from a password secured location so you must disable the password of the user folder or use a different source location.
BR,
Erwin
Posts: 59
Threads: 3
Joined: Nov 2016
Reputation:
0
28.10.2019, 14:12
(This post was last modified: 28.10.2019, 14:14 by Igor68.)
(28.10.2019, 13:18)Эрвин ван дер Цварт Wrote: Привет,
только что проверил это и все еще работает, вы не можете отправить mp3 на Sonos из защищенного паролем места, поэтому вы должны отключить пароль пользовательской папки или использовать другое местоположение источника.
БР,
Эрвин Эрвин, привет, правда. ) Все работает, но файл недоступен. Как отключить пароль для ftr? На вкладке вы можете только ввести другой пароль ....
Все работает, но файл недоступен. Как отключить пароль для ftr? На вкладке вы можете только ввести другой пароль ....
Erwin, hi, really. ) Everything works, but the file is not available. How to disable password for ftr? In the tab you can only enter another password ....
sorry for my English))
Posts: 1764
Threads: 6
Joined: Jul 2015
Reputation:
117
28.10.2019, 15:42
(This post was last modified: 28.10.2019, 15:43 by Erwin van der Zwart.)
Hi,
On the bottom of the user access tab there is a button "User access settings" uncheck the checkbox "Enable password for User directory", any source in the user folder is now reachable without the need of a password so Sonos should be able to access it.
BR,
Erwin
Posts: 59
Threads: 3
Joined: Nov 2016
Reputation:
0
Erwin, I can’t remove the password. I followed all your instructions, but the password remains, I can access the apps with only a password. Did a soft reset. Any other ideas?
Posts: 1764
Threads: 6
Joined: Jul 2015
Reputation:
117
Hi,
Unchecking the box for the user folder should be enough, what do you mean by apps folder?
You only need to change this:
http://admin:pass@192.168.0.10/user/Mix_Lastochka.mp3
to
http://192.168.0.10/user/Mix_Lastochka.mp3
When running http://192.168.0.10/user/Mix_Lastochka.mp3 in the browser (new session, no other sessions open) it should play the .mp3, if that works then Sonos should be able to reach it..
BR,
Erwin
Posts: 59
Threads: 3
Joined: Nov 2016
Reputation:
0
Works!
Erwin, thank you so much!
Posts: 26
Threads: 2
Joined: Jul 2015
Reputation:
0
09.12.2019, 15:19
(This post was last modified: 09.12.2019, 15:19 by Hippolyte.)
Hello everyone,
we the previous version of the Sonos app when someone physically pressed the volume button on the Sonos it updated the value on the appropriate object on the LM.
Is it still possible with the new app ?
I know I can do a resident on groupstate = storage.get('app: se-sa:' .. groupID .. ':GroupVolume') to get the updated value yet it is not really elegant way of having the updated value if the user physically pressed the volume button
Thank you for you help.
Posts: 4635
Threads: 24
Joined: Aug 2017
Reputation:
207
Yes, when you add widget then groups with monitoring are also created, same as in old one.
------------------------------
Ctrl+F5
Posts: 2
Threads: 0
Joined: Sep 2017
Reputation:
0
Daniel can you give a example using the new API for playing a doorbell mp3?
|