Notify Node - jensrossbach/node-red-sony-audio GitHub Wiki

Notifies an event from a Sony audio device via the Sony Audio Control API. This node listens for notifications and emits the event data in a configurable form upon reception. The service to listen to and the events to subscribe to can be set via the node's configuration page.

Configuration

On the configuration page, you can configure various settings of the node.

General Configuration

General Settings

Name

Optionally enter a name to be displayed - if omitted, the name of the selected service will be shown as label of the node.

Device

You have to select the Sony audio device to connect to from the dropdown box (or create a new device configuration if not yet done).

Notification Configuration

Events

Here you can select the service and its provided events to subscribe to. You can select multiple notifications but only one service at a time. If you want to listen to multiple services, you have to create multiple notify node instances and select a different service for each.

Service & Notification Settings

Output Configuration

Here you can define rules that set output message properties or context variables when receiving a notification from the device. Each entry in the list stands for a rule setting either a message property, a global variable or a flow variable.

Output

For each rule, you can select the type of content to be applied:

Selection Description
filtered data Filters the raw data coming from the device using different criteria.
unfiltered data Either the complete block of unprocessed data as it comes from the device or a specific part from it.
env variable An environment variable or a text including environment variables.
string Static text or text containing templates.
number An arbitrary static number.
boolean A static boolean value (true or false).
JSON Static content specified in JSON format.
expression A JSONata expression to create dynamic content built on top of the original data coming from the device.
buffer A static binary buffer.
timestamp The time when the notification arrives.

Filtered Data

Filters extract essential data out of the raw notification coming from the device. Each filter corresponds to a specific API on the device and if the API of the notification does not match a configured filter, it does nothing.

Auto

This is a special filter which does not filter data on its own but instead automatically selects a filter matching the API of the notification.

Powered

Results in true or false depending on wether the device is powered on or not. The auto filter will always select this filter for the notifyPowerStatus API.

Standby

Results in true or false depending on wether the device is in standby mode or not.

Software Update

Results in true or false depending on wether a software update is available for the device or not.

Absolute Volume

Extracts the absolute volume level from the notification. The auto filter will always select this filter for the notifyVolumeInformation API. If the volume is not associated with a specific zone, the result is a number, otherwise it is an object with the following format:

Property Type Description
volume Number The absolute volume level
zone Number The associated zone

Relative Volume

Extracts the relative volume step from the notification. If the volume is not associated with a specific zone, the result is a number, otherwise it is an object with the following format:

Property Type Description
volume Number The relative volume step
zone Number The associated zone

Muted

Extracts the mute state from the notification. If the mute state is not associated with a specific zone, the result is a boolean value, otherwise it is an object with the following format:

Property Type Description
muted Boolean The mute state
zone Number The associated zone

Source

Extracts information about the active source from the notification. The result is an object with the following format:

Property Type Description
scheme String The source scheme
source String The actual source pertaining to the scheme
port Number The port in case of an HDMI, video or line input source
preset Number The preset number in case of an FM radio source

For more information, please refer to the API specification of method notifyPlayingContentInfo and the documentation for resource URIs.

Unfiltered Data

This selection allows you to access the complete raw notification data coming from the device or parts of it.

Selection Type Description
all data Object The complete data from the notification, including all of the below parts as properties.
host String The IP address of the device.
service String The API service name.
method String The API method name.
version String The API version number.
payload Object The payload containing the parameters of the notification.

Templating

The string input supports embedded templates to insert dynamic content into the text. The following template variables from the notification data of the device are available:

Variable Description
host The IP address of the device.
service The API service name.
method The API method name.
version The API version number.
payload The payload containing the parameters of the notification. As this variable maps to an object, one of its nested properties that are convertible to string content should be referenced.

The template variables can be processed and transformed in various ways based on the powerful syntax of the Nunjucks templating engine. For more information please refer to the Nunjucks documentation.

Examples

Text containing the IP address of the device and the API of the notification:

{{host}}/{{service}}.{{method}}@{{version}}

Example result:

192.168.1.42/[email protected]

Text containing the volume of a notification for the notifyVolumeInformation API:

The new volume is {{payload.volume}}.

Example result:

The new volume is 14.

Text containing the volume as percentage value of a notification for the notifyVolumeInformation API:

The new volume is {{(payload.volume/payload.maxVolume*100)|round}}%.

Example result:

The new volume is 28%.

JSONata Expressions

With JSONata expressions, you can dynamically process the raw notification data from the device and transform it into an arbitrary form as you need it. This allows you to kind of create your own filters for the notification data. The expressions have access to the following attributes from the original data:

Attribute Type Description
host String The IP address of the device.
service String The API service name.
method String The API method name.
version String The API version number.
payload Object The payload containing the parameters of the notification.

Besides this, you have the full power of JSONata expressions including access to context and environment variables. For more details, please refer to the Node-RED documentation as well as the JSONata documentation.

If a certain condition is not met, you can return undefined from the expression which will prevent the rule from setting any content.

Examples

Expression to extract the power status from a notification of the notifyPowerStatus API, ensuring that the event matches the notifying API:

(method = "notifyPowerStatus") ? (payload.status = "active") : undefined

Depending on the notification, the result would be either true, false or undefined. In the latter case, the rule would be canceled.

Expression to extract the volume from a notification of the notifyVolumeInformation API, ensuring that the event matches the notifying API:

(method = "notifyVolumeInformation") ? payload.volume : undefined

Depending on the notification, the result would be a number or undefined. In the latter case, the rule would be canceled.

Output Options

There is a checkbox options to further control the output behavior.

Options

Send message only if msg.payload has been set

This option defines the behavior if an output message shall only be sent if msg.payload has been set by one of the property rules or if it should be always sent when a notification is received from the device. Activate the checkbox if you for instance want to prevent a message from being sent in case a filter rule did not match the API of the notification.