Custom capabilities in MQTT templates
-
Hi,
I'm trying to integrate the sonos-mqtt (https://sonos2mqtt.svrooij.io/) with the MSR and it's coming along nicely so far.
But cannot wrap my head around how to define custom capabilities in MQTT templates. I need this for the TTS announcements and similarly for the notification sounds where I would pass the sound file as parameter.So this is what I have in the local_mqtt_devices.yaml
capabilities: x_sonos_announcement: attributes: actions: speak: arguments: text: type: string volume: type: int delay: type: int
And this is the template:
templates: sonos-announcement: capabilities: - x_sonos_announcement actions: x_sonos_announcement: speak: topic: "sonos/cmd/speak" payload: expr: > { "text": parameters.text, "volume": parameters.volume, "delayMs": parameters.delay, "onlyWhenPlaying": false, "engine": "neural" } type: json
So the speak action should send something like this to topic sonos/cmd/speak
{ "text": "message goes here", "volume": 50, "delayMs": 100, "onlyWhenPlaying": false, "engine": "neural" }
At startup the MSR seems to be quite unhappy with my configuration:
reactor | [latest-25016]2025-02-09T08:19:59.029Z <MQTTController:WARN> MQTTController#mqtt entity Entity#mqtt>sonos-announcement unable to configure capabilities [Array][ "x_sonos_announcement" ] reactor | i18n: missing fi-FI language string: Configuration for {0:q} is incomplete because the following requested capabilities are undefined: {1} reactor | i18n: missing fi-FI language string: Configuration for {0:q} has unrecognized capability {1:q} in actions reactor | Trace: Configuration for {0:q} is incomplete because the following requested capabilities are undefined: {1} reactor | at _T (/opt/reactor/server/lib/i18n.js:611:28) reactor | at AlertManager.addAlert (/opt/reactor/server/lib/AlertManager.js:125:25) reactor | at MQTTController.sendWarning (/opt/reactor/server/lib/Controller.js:627:30) reactor | at MQTTController.start (/var/reactor/ext/MQTTController/MQTTController.js:268:26) reactor | at async Promise.allSettled (index 0)
Configuration for "sonos-announcement" has unrecognized capability "x_sonos_announcement" in actions Controller: MQTTController#mqtt Last 10:21:37 AM Configuration for "sonos-announcement" is incomplete because the following requested capabilities are undefined: x_sonos_announcement Controller: MQTTController#mqtt Last 10:21:37 AM
This is probably a pretty stupid question and the approach may not even work at all, but maybe someone or @toggledbits for sure, could point me to the right direction.
Basically the idea is to be able to send TTS messages from reactions using entity actions. I've previously used HTTP requests to Sonos HTTP API (https://hub.docker.com/r/chrisns/docker-node-sonos-http-api/) for the same functionality, but since moving to sonos-mqtt, I need a way to send the TTS notifications using MQTTController. Along with the actual message, volume and delay must also be parameterizable.br,
mgvraMSR latest-25016-d47fea38 / MQTTController [0.2.24293]
-
As you can see from
this should be:
capabilities: x_sonos_announcement: actions:
and the way you nest and indent is very important.
Well thanks for your reply, but didn't get it working.
This is my config now:capabilities: x_sonos_announcement: actions: speak: arguments: text: type: string volume: type: int delay: type: int templates: sonos-announcement: capabilities: - x_sonos_announcement actions: x_sonos_announcement: speak: topic: "sonos/cmd/speak" payload: expr: > { "text": parameters.text, "volume": parameters.volume, "delayMs": parameters.delay, "onlyWhenPlaying": false, "engine": "neural" } type: json
I just fail to see what is the problem here.
br,
mgvra -
Start by moving your capability definition into
local_mqtt_capabilities.yaml
and seeing how far that gets you.Also, you'll get complaints because your capability name doesn't start with
x_mqtt
, which you can either ignore, or switch to something likex_mqtt_sonos_...
. -
Start by moving your capability definition into
local_mqtt_capabilities.yaml
and seeing how far that gets you.Also, you'll get complaints because your capability name doesn't start with
x_mqtt
, which you can either ignore, or switch to something likex_mqtt_sonos_...
.Thank you for your reply! Well this is what I mean, the answer is right in your face (local_mqtt_capabilities.yaml) and you just can't see it.
Now it works like charm and I can even refactor my existing KNX templates using the custom capabilities.For anyone else who might be struggling with the same problem, here's my config:
local_mqtt_capabilities.yaml
capabilities: x_mqtt_sonos_announcement: actions: speak: arguments: text: type: string volume: type: int default: 50 delay: type: int default: 500
local_mqtt_devices.yaml
templates: sonos-announcement: capabilities: - x_mqtt_sonos_announcement actions: x_mqtt_sonos_announcement: speak: topic: "sonos/cmd/speak" payload: expr: > { "text": parameters.text, "volume": parameters.volume, "delayMs": parameters.delay, "onlyWhenPlaying": false, "engine": "neural" } type: json
FYI there's a subtle layout issue with the login screen background image when using ultra wide monitors, just to let you know.
-
Showing off all your cool toys, eh?
Thanks for letting me know. I'll see what I can do to make it look more presentable.
-
Showing off all your cool toys, eh?
Thanks for letting me know. I'll see what I can do to make it look more presentable.
@toggledbits said in Custom capabilities in MQTT templates:
Showing off all your cool toys, eh?
Well I wouldn't boast with employer provided montitor, and definitely wouldn't call it cool, just damn wide.
But speaking of showing off cool toys, this is something I bet you've never seen before, one of my weird projects:
A custom made flow through heater for my summer cottage's outdoor shower. Based on old used Webasto ThermoTop EVO 5kW car engine diesel
heater and controlled by ESP32 which provides WiFi AP and web UI. Fully modular, so that the heating unit can be removed before the winter.
Wouldn't call this cool either (no pun intented) but unique. Works pretty well, at least @tunnus agrees.Old WIP photo
Thanks for letting me know. I'll see what I can do to make it look more presentable.
np
br,
mgvra -
That is cool. I really love stuff that combines simple, available IoT bits with the old greasy bits to solve problems. It appeals to my libertarian steampunk fantasy of how I'd run my home, which unfortunately far exceeds my wife's tolerance for the lower limits of luxury over sustainability.