Skip to main content

Python library for interfacing with Sony's Songpal devices

Project description

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

Supported devices

The library has been tested for now with following devices:

  • Sony HT-XT3

  • SRS-X88

Getting started

Installation

The easiest way for installing this project is by using pypi inside a virtualenv.

$ 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 [<value>|mute|unmute]

$ songpal volume 20

$ songpal volume +5

$ songpal volume -10

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

Output Control

$ songpal output

Outputs:
  * TV (uri: extInput:tv)
  * HDMI1 (uri: extInput:hdmi?port=1)
  * HDMI2 (uri: extInput:hdmi?port=2) (active)
  * HDMI3 (uri: extInput:hdmi?port=3)
  * Bluetooth Audio (uri: extInput:btAudio)
  * Analog (uri: extInput:line)

$ songpal output HDMI1

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.

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

A preliminary Home Assistant can be found under custom_components/media_player/songpal.py.

To install it copy (or link) the file into your custom components directory (~/.homeassistant/custom_components/media_player/), and add the following configuration to your media player configuration file.

media_player:
  - platform: songpal
    name: my soundbar
    endpoint: http://192.168.1.1:10000/sony

Enabling debug for songpal in ~/.homeassistant/configuration.yaml can provide useful information when trying to debug the platform:

logger:
  logs:
    songpal: debug

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

python-songpal-0.0.5.tar.gz (19.5 kB view details)

Uploaded Source

Built Distribution

python_songpal-0.0.5-py3-none-any.whl (22.7 kB view details)

Uploaded Python 3

File details

Details for the file python-songpal-0.0.5.tar.gz.

File metadata

File hashes

Hashes for python-songpal-0.0.5.tar.gz
Algorithm Hash digest
SHA256 cc3ca55e37ad7f10b56b7ac6f877202a0670add21213d7763861d1d86422fa5f
MD5 ca4654b7093b00a0a469cad47d9dee76
BLAKE2b-256 c3526b214dc7257aa38bf19c17465d0546d6b8daa7408bf13da816977572a5d8

See more details on using hashes here.

File details

Details for the file python_songpal-0.0.5-py3-none-any.whl.

File metadata

File hashes

Hashes for python_songpal-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 2409ab2111697bc03beb53daa85a810222e1c6f9e72cd43bb7b8a6b2fc6d3367
MD5 cd9f3c6eb9804fcb1480436bf2e99786
BLAKE2b-256 2040bdbaf5416977f7a1a99d537157eb01e13ba18011fea33b13ad2e974069d5

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page