Fork me on GitHub

pimatic-sounds by Bert Gierveld (bertreb) | github | npm

pimatic-sounds

Pimatic plugin for playing mp3 files and tts sentences on Chromecast and Sonos devices. A typical chromecast device devices is Google Home or a Google chromecast dongle. The Ikea SYMFONISK is a Sonos device.

Install the plugin via the plugin page of Pimatic or add the following in config.json

 {
   "plugin": "sounds"
 }

After installation and restart activate the plugin and add the following to the plugin config

{
  "port": 8088,     // or the port you like and is free
  "language": "en", // or your own language
  "debug": true     // if you want
}

The IP address of the computer the plugin is running on, is automatically detected and used for the media server. It must be in the range 192.168.xxx.xxx. The supported (but not tested) languages can be found in languages.

Chromecast Device

Create a Chromecast device with the following config.

{
  "id": "testcast",         // id for usage within Pimatic
  "name": "testcast",       // name for usage within Pimatic
  "class": "ChromecastDevice"
  "ip": "192.168.xxx.xxx",  // IP of your Chromecast device
  "playInit": true          // plays initSound.mp3 after (re)start of device
  "xAttributeOptions": [],
}

The Cromecast device types are a single, grouped or paired devices. The discovery will find them and they can be added and used in the rules

Sonos Device

Create a Sonos device with the following config.

{
  "id": "testcast",         // id for usage within Pimatic
  "name": "testcast",       // name for usage within Pimatic
  "class": "SonosDevice"
  "ip": "192.168.xxx.xxx",  // IP of your Chromecast device
  "playInit": true          // plays initSound.mp3 after (re)start of device
  "xAttributeOptions": [],
}

Group Device

Create a Group device with the following config.

{
  "id": "testgroupcast",      // id for usage within Pimatic
  "name": "testgroupcast",    // name for usage within Pimatic
  "class": "GroupDevice"
  "playInit": true            // plays initSound.mp3 after (re)start of device
  "devices": [                // list of SoundsDevices
    "name": "id of a SoundDevice"
    ]
  "xAttributeOptions": [],
}

The GroupDevice is combining existing SoundsDevices to be used as an extra device. In the GroupsDevice config you can select and add existing SoundsDevices. In the rules the groups device will be available as an extra play device option.

Controlling the devices

The function of a device is controlled via rules The ACTION rule syntax is:

play [text|file] ["$variable"|"text for tts"]|["audio filename"|"$variable"] [vol [number|$variable]] on [ChromecastDevice | SonosDevice | GroupDevice]

Some examples of command lines are:

  1. play text "this is a nice text" vol 50 on mysoundsdevice
  2. play file "nice-music.mp3" vol 25 on mysoundsdevice
  3. play file "$that-funky-music" vol $loud-music on mysoundsdevice

In the main directory of Pimatic (mostly /home/pi/pimatic-app) a directory sounds is created. You can put mp3 files in that directory. You can create subdirectories in sounds and can use them in the rule.

In the text string you can use variables to create dynamic voice text.

In the file string you can also use variables to create dynamic selection of audio files. A variable-only file string must still be enclosed by "". The resulting filenames must be without spaces!

For the volume variable a number or a variable can be used.

The 'vol [0-100]' after text or file is optional and will override the mainvolume. If not set, the value of the mainvolume is 20.

When a TuneIn stream is playing and Sounds plays a text or file, the TuneIn stream stops and is resumed after the Sounds play is finished.

Credits

This plugin is build from several existing pieces of software. Sometimes the ideas and sometimes the real pieces of code. To mention are:

  • castv2-client from thibauts
  • node-red-contrib-castv2 from i8beef
  • node-sonos from bencevans

The plugin is only Node v8 or v10 compatible and in development.

You could backup Pimatic before you are using this plugin!

Plugin Config Options

pimatic-sounds configuration options
OptionDescriptionDefault
port
number
8088
language
string
"en"
debug
boolean
Debug mode. Writes debug messages to the pimatic log, if set to true.
false

Device Config Options

pimatic-sounds device config schemas

ChromecastDevice

ChromecastDevice config options
OptionDescriptionDefault
ip
string
port
number
8009
playInit
boolean
true

SonosDevice

SonosDevice config options
OptionDescriptionDefault
ip
string
playInit
boolean
true

GroupDevice

GroupDevice config options
OptionDescriptionDefault
devices
array of objects
Sounds devices
[]
Elements
pimatic-sounds is written by Bert Gierveld (bertreb)