Skip to main content

PyPI version Black

Python 3 implementation of SongPal protocol as used by Sony’s soundbar and potentially other devices.

Supported devices

The library has been tested to work with following devices:

  • BDV-N9200W

  • CMT-SX7B

  • HT-XT2, HT-XT3

  • HT-NT5

  • HT-MT500

  • HT-ZF9

  • HT-ST5000

  • SRS-X77, SRS-X88, SRS-X99

  • STR-DN1060, STR-DN1070, STR-DN1080

  • STR-AZ5000ES

  • STR-AN1000, TA-AN1000

Getting started

Installation

The easiest way to install is by using pip:

$ pip install python-songpal

Locating the endpoint

To communicate with the device you need to locate its endpoint URL. The easiest way to do is to execute the discover command:

$ songpal discover

Discovering for 3 seconds
Found HT-XT3 - BAR-2015
* API version: 1.0
* Endpoint: http://192.168.1.1:10000/sony
* Services:
  - Service: guide
  - Service: system
  - Service: audio
  - Service: avContent

This will run a UPnP discovery to find out responsive devices implementing the ScalarWebAPI.

The endpoint can be defined with --endpoint option, or alternatively SONGPAL_ENDPOINT environment variable can be set.

General Usage

The accompanied songpal tool can be used to control your device. All available commands can be listed with --help and more help on each command can be obtained by passing it to the sub-command, e.g., songpal power --help. Most interesting commands are most likely power, output, volume, and sound.

Generally speaking invoking a command without any parameters will display some relevant information like settings or active output.

For debugging -d (--debug) can be passed – also multiple times for increased verbosity – for protocol-level information.

Some of the commands can be used to adjust settings related to that functionality, usually by passing the target and its wanted value as parameters to the command.

$ songpal bluetooth mode off

On commands which are not mainly used for settings, such as power, require explicit set sub-command for changing the settings.

Status

$ songpal status

will display some basic information about the device, such as whether it is powered on and what are its volume settings.

Power Control

power command can be used to both turning the device on and off, and change its power settings.

$ songpal power

$ songpal power settings

$ songpal power

$ songpal power set quickStartMode on

Volume Control

$ songpal volume [-- output 'output title'] [<value>|mute|unmute]

$ songpal volume 20

$ songpal volume +5

$ songpal volume -10

$ songpal volume --output 'Zone 2'


$ songpal volume --output 'Main Zone' 15

Sound Settings

Your device may support various sound-related settings, such as night mode or adjusting the subwoofer volume.

$ songpal sound

$ songpal sound nightMode off

$ songpal sound subwooferLevel 4

Zone Control

$ songpal zone

Zones:
  * Main Zone (uri: extOutput:zone?zone=1) (active)
  * Zone 2 (uri: extOutput:zone?zone=2) (active)
  * Zone 3 (uri: extOutput:zone?zone=3)
  * HDMI Zone (uri: extOutput:zone?zone=4)

$ songpal zone 'Main Zone'

Activating Main Zone (uri: extOutput:zone?zone=1) (active)

$ songpal zone 'Zone 2' true

Activating Zone 2 (uri: extOutput:zone?zone=2) (active)

$ songpal zone 'Zone 2' false

Deactivating Zone 2 (uri: extOutput:zone?zone=2) (active)

Input Control

without zones: .. code-block:

$ songpal input
      * HDMI1 (uri: extInput:hdmi?port=1)
      * HDMI2 (uri: extInput:hdmi?port=2) (active)
      * HDMI3 (uri: extInput:hdmi?port=3)

$ songpal input HDMI1

with zones: .. code-block:

$ songpal input

Inputs:
  * SOURCE (uri: extInput:source)
    - extOutput:zone?zone=2
    - extOutput:zone?zone=3
    - extOutput:zone?zone=4
  * GAME (uri: extInput:game) (active)
    - extOutput:zone?zone=1
    - extOutput:zone?zone=4
  * SAT/CATV (uri: extInput:sat-catv)
    - extOutput:zone?zone=1
    - extOutput:zone?zone=2
    - extOutput:zone?zone=3
    - extOutput:zone?zone=4
  * VIDEO 1 (uri: extInput:video?port=1)
    - extOutput:zone?zone=1
    - extOutput:zone?zone=2
    - extOutput:zone?zone=3
    - extOutput:zone?zone=4
  * VIDEO 2 (uri: extInput:video?port=2)
    - extOutput:zone?zone=1
    - extOutput:zone?zone=4
  * TV (uri: extInput:tv)
    - extOutput:zone?zone=1
  * SA-CD/CD (uri: extInput:sacd-cd)
    - extOutput:zone?zone=1
    - extOutput:zone?zone=2
    - extOutput:zone?zone=3
    - extOutput:zone?zone=4
  * Bluetooth Audio (uri: extInput:btAudio)
    - extOutput:zone?zone=1
    - extOutput:zone?zone=2
    - extOutput:zone?zone=3

$ songpal input 'VIDEO 1'

$ songpal input 'SOURCE' --output 'Zone 2'

Device Settings

To list available settings, use settings command.

$ songpal settings

Do note that some settings (e.g. bluetooth settings) are not listed in the global settings tree, but have to be separatedly accessed using the bluetooth command.

Group Control

$ songpal group

Group command require using the UPnP URL --url instead of the API --endpoint, and you’ll need the UUIDs of the devices you want to group as well. Both of these can be obtained through the discover function. All group commands should be executed on the master

Creating groups:

$ songpal group --url [upnpurl] create [groupname] [slave uuids]

$ songpal group --url "http://x.x.x.x:52323/dmr.xml" create GroupName uuid:00000000-0000-1010-8000-xxxx uuid:00000000-0000-1010-8000-xxxx

Aborting groups

$ songpal group --url [pnpurl] abort

$ songpal group --url "http://x.x.x.x:52323/dmr.xml" abort

Changing volume

$ songpal group --url [pnpurl] volume [value -100,100]

$ songpal group --url "http://x.x.x.x:52323/dmr.xml" volume -- -5
$ songpal group --url "http://x.x.x.x:52323/dmr.xml" volume 5

Muting

$ songpal group --url [pnpurl] mute [true|false]

$ songpal group --url "http://x.x.x.x:52323/dmr.xml" mute true
$ songpal group --url "http://x.x.x.x:52323/dmr.xml" mute false

Executing custom commands

For experimenting it can be useful to execute arbitrary commands against the endpoint. You can access the available methods by calling songpal list-all.

command can be used for that as follows:

$ songpal command system getSystemInformation

Notification support

The protocol supports subscribing to notifications on subsystem basis. Executing songpal notifications without any parameters will list available notifications.

Every notification can be listened to separately, or alternatively all notifications from a single subsystem can be subscribed to.

$ songpal notifications --listen-all avContent

Contributing

Reporting bugs or supported devices

When reporting bugs or informing about supported device not listed above, please consider attaching the output of songpal dump-devinfo with your report.

API information

Audio Control API describes the API this project (currently partially) implements.

The Camera Remote API is also similar to this, and may also be useful for developers.

Home Assistant support

Home Assistant supports devices using this library directly since 0.65: https://home-assistant.io/components/media_player.songpal/

Release files for python-songpal 0.16.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for python-songpal 0.16.2
File Size Uploaded
python_songpal-0.16.2.tar.gz 42.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for python-songpal 0.16.2
File Interpreter ABI Platform
python_songpal-0.16.2-py3-none-any.whl Python 3 none any Details

Total release size: 86.7 kB

Release files / python_songpal-0.16.2.tar.gz

Download URL python_songpal-0.16.2.tar.gz
Size 42.5 kB
Tags Source
SHA-256 checksum
How to use checksums
3c1c82d272cb13681bda22e01c29495db082139d4e390b31039870c9bc236e92
BLAKE2b-256 checksum
How to use checksums
2712a41586ed15da6e355da914792bc7a6b5a58c1c7b0ff6fd25069a56bad423
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.0.0 CPython/3.12.2

Release files / python_songpal-0.16.2-py3-none-any.whl

Download URL python_songpal-0.16.2-py3-none-any.whl
Size 44.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b09c5573c4aee8fd1765c1162ca9f7ac2d2a5a0c6ba05b96e2f84d2836be908a
BLAKE2b-256 checksum
How to use checksums
222474de916c8547e5b87824e74004fdf89d05427d4898bd08f2958c8a1e4ccd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.0.0 CPython/3.12.2

Release history Release notifications | RSS feed

This release

0.16.2 This release

2 release files

0.16.1

2 release files

0.16

2 release files

0.15.2

2 release files

0.15.1

2 release files

0.15

2 release files

0.14

2 release files

0.13

2 release files

0.12

2 release files

0.11.2

2 release files

0.11.1

2 release files

0.11

2 release files

0.10

2 release files

0.0.9

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page