jishi / node-sonos-http-api

An HTTP API bridge for Sonos easing automation. Hostable on any node.js capable device, like a raspberry pi or similar.
http://jishi.github.io/node-sonos-http-api/
MIT License
1.85k stars 460 forks source link

Feature Request: Select SPDIF/Line in Source as action #109

Open NovaGL opened 8 years ago

NovaGL commented 8 years ago

I can understand if you don't want to do this as it's possible via presets, but I would like the option.

The way I would go about it is:

Get Zone info from

POST /DeviceProperties/Control HTTP/1.1
HOST: SONOS-IP:1400
SOAPACTION: "urn:schemas-upnp-org:service:DeviceProperties:1#GetZoneInfo"
CONTENT-TYPE: text/xml; charset="utf-8"

<?xml version="1.0" encoding="utf-8"?>
<s:Envelope s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
   <s:Body>
      <u:GetZoneInfo xmlns:u="urn:schemas-upnp-org:service:DeviceProperties:1" />
   </s:Body>
</s:Envelope>

From the output get XX:XX:XX:XX:XX:XX remove all ":"

Then combine it with "x-sonos-htastream:RINCON_" + MACAddress + "01400:spdif"

    <s:Envelope
        xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"
        s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
        <s:Body>
            <u:SetAVTransportURI
                xmlns:u="urn:schemas-upnp-org:service:AVTransport:1">
                <InstanceID>
                    0
                    </InstanceID>
                <CurrentURI>
                    x-sonos-htastream:RINCON_XXXXXXXXXXXX01400:spdif                    
                    </CurrentURI>
                <CurrentURIMetaData>
                    </CurrentURIMetaData>
                </u:SetAVTransportURI>
            </s:Body>
        </s:Envelope>

Thanks for reading.

jishi commented 8 years ago

Well, there already is a "setavtransporturi" action available, which would look like this:

/RoomName/setavtransporturi/x-sonos-htastream:RINCON_XXXXXXXXXXXX01400:spdif

So you don't actually need to use the presets for this. But, it would be nice to simplify it, I'm thinking something like this:

/RoomName/linein (for local line-in if available) /RoomName/linein/SrcRoomName (for line-in from another player)

And also handle the difference between the PLAYBAR and regular players somehow.

NovaGL commented 8 years ago

Thanks, writing presets/tv is easier than setavtransporturi/x-sonos-htastream:RINCON_XXXXXXXXXXXX01400:spdif

It's good to have options, I like your thinking and happy to test something like this in the future.

NovaGL commented 8 years ago

Are you still thinking of implementing this?

jishi commented 8 years ago

Yes, I just need to find a reliable way of identifying a playbar or equivalent device that uses the x-sonos-htastream scheme. If you have any suggestions (preferably, something that is evented), I'll gladly take suggestions.

NovaGL commented 8 years ago

Could you parse the info from the XML?

sonos-ip:1400/xml/device_description.xml

It has the RICON under UDN and says model number

jishi commented 8 years ago

I could, but I don't fetch that data today and if it would be evented, that would be "cleaner". I can probably always check some properties that I expect to be part of a PLAYBAR device.

Also, relying on model names might not function properly in the future if they release a second version of PLAYBAR or another device with a spdif line in.

Maybe there is service actions that actually triggers line-in that takes this into consideration, I should probably investigate that as well.

NovaGL commented 8 years ago

Why use Model names? I would use model numbers much safer, you have a list of model numbers that support SPDIF. If I find an event that shows this information, I will post it.

jishi commented 8 years ago

Model names, model numbers follow the same scheme, meaning that I can not infer what capabilities a certain device has, which makes it impossible to support new devices without actually adding support for them. That would be the dream scenario, but of course, if that is not possible, I can always use model number.

Any difference in properties that are evented between a playbar and a regular player are of interest.

NovaGL commented 8 years ago

This might be of use to you.

If a device supports SPDIF it will be able to be evented using urn:upnp-org:serviceId:HTControl

Sonos PLAYBAR/urn:upnp-org:serviceId:HTControl TOSLinkConnected 0

If a device supports Line-In it can be evented using. urn:upnp-org:serviceId:AudioIn

Sonos CONNECT/urn:upnp-org:serviceId:AudioIn LineInConnected 0

jishi commented 8 years ago

Yeah, that was super useful. The Sonos controller is aware if something is connected, and one should probably take that into account as well. With your discovery, it will both be possible to know that, and what type of device that is connected.

jishi commented 8 years ago

I'm planning on taking a stab at this, but I would like the output from a PLAYBAR http://x.x.x.x:1400/xml/device_description.xml

If you could send that to me at jimmy@shimizu.se that would be great! I have already fixed this for regular line-in devices, but wanted to make it model agnostic.

LqqkOut commented 7 years ago

Emailed device_description.xml - hopefully this helps with a resolution

martin072 commented 5 years ago

Hi jish, Any news on the spdif feature? I noticed the command supports only linein for the moment?

chrisns commented 3 years ago

https://github.com/jishi/node-sonos-http-api/pull/789

mvdwater commented 3 years ago

I'm willing to help by providing any info or help debug to get this working for PLAYBAR. I'm currently using the workaround, but it would be nice if this just works out of the box.

I noticed that the <ZoneGroupMember> info has a HdmiCecAvailable="1" which is not as nice as using the Services, but probably easier to implement?

<ZoneGroupState><ZoneGroups><ZoneGroup Coordinator="RINCON_XXXXXXXXXXXX01400" ID="RINCON_XXXXXXXXXXXX01400:1875128050"><ZoneGroupMember UUID="RINCON_XXXXXXXXXXXX01400" Location="http://x.x.x.x:1400/xml/device_description.xml" ZoneName="MyZone" Icon="" Configuration="1" SoftwareVersion="62.1-86220" SWGen="2" MinCompatibleVersion="61.0-00000" LegacyCompatibleVersion="58.0-00000" BootSeq="8" TVConfigurationError="0" HdmiCecAvailable="1" WirelessMode="1" WirelessLeafOnly="0" HasConfiguredSSID="1" ChannelFreq="2437" BehindWifiExtender="0" WifiEnabled="1" Orientation="0" RoomCalibrationState="1" SecureRegState="3" VoiceConfigState="0" MicEnabled="0" AirPlayEnabled="1" IdleState="0" MoreInfo=""/></ZoneGroup></ZoneGroups><VanishedDevices></VanishedDevices></ZoneGroupState>