parautenbach / hass-shairport-sync

A custom media player for Home Assistant that allows you to control and get updates from a Shairport Sync installation using MQTT.
Apache License 2.0
69 stars 12 forks source link

What Should I set my Topic to? #17

Closed PablaV closed 5 days ago

PablaV commented 1 year ago

New to the world of MQTT, and am stuck on what I should set me topic for on the custom component and shairport-sync.conf file. Here is what I have so far for my config but when I try listening to the shairport/connection/test topic on HA nothing is being published. I made sure to rebuild my shairport-sync to include the MQTT config flags and I have the broker addon and integration on HA, so I am fairly sure I am just getting the topic incorrect.

mqtt =
{
//  enabled = "yes"; // set this to yes to enable the mqtt-metadata-service
//  hostname = "http://192.168.8.85"; // Hostname of the MQTT Broker
//  port = 1883; // Port on the MQTT Broker to connect to
//  username = NULL; //set this to a string to your username in order to enable username authentication
//  password = NULL; //set this to a string you your password in order to enable username & password authentication
//  capath = NULL; //set this to the folder with the CA-Certificates to be accepted for the server certificate. If not set, TLS is not used
//  cafile = NULL; //this may be used as an (exclusive) alternative to capath with a single file for all ca-certificates
//  certfile = NULL; //set this to a string to a user certificate to enable MQTT Client certificates. keyfile must also be set!
//  keyfile = NULL; //private key for MQTT Client authentication
//  topic = "shairport/connection/test"; //MQTT topic where this instance of shairport-sync should publish. If not set, the general.name value is used.
//  publish_raw = "no"; //whether to publish all available metadata under the codes given in the 'metadata' docs.
//  publish_parsed = "yes"; //whether to publish a small (but useful) subset of metadata under human-understandable topics
//  empty_payload_substitute = "--"; // MQTT messages with empty payloads often are invisible or have special significance to MQTT brokers and readers.
//    To avoid empty payload problems, the string here is used instead of any empty payload. Set it to the empty string -- "" -- to leave the payload empty.
//  Currently published topics:artist,album,title,genre,format,songalbum,volume,client_ip,
//  Additionally, messages at the topics play_start,play_end,play_flush,play_resume are published
//  publish_cover = "yes"; //whether to publish the cover over mqtt in binary form. This may lead to a bit of load on the broker
//  enable_remote = "yes"; //whether to remote control via MQTT. RC is available under `topic`/remote.
//  Available commands are "command", "beginff", "beginrew", "mutetoggle", "nextitem", "previtem", "pause", "playpause", "play", "stop", "playresume", "shuffle_songs", "volumedown", "volumeup"
};
stephenmetzger commented 1 year ago

You'll need to uncomment the lines you want active by removing the // in front of them. You can set your topic to anything you want. I keep it simple, just the name of the shairport instance. For example, my topic is "officeshairport" for the instance in my office.

Here is my mqtt section:

mqtt = { enabled = "yes"; // set this to yes to enable the mqtt-metadata-service hostname = "10.0.1.50"; // Hostname of the MQTT Broker port = 1883; // Port on the MQTT Broker to connect to username = "[WICKEDUNIQUEUSERNAME]"; //set this to a string to your username in order to ena> password = "[SUPERSECRETPASSWORD]"; //set this to a string you your password in order to ena> // capath = NULL; //set this to the folder with the CA-Certificates to be accept> // cafile = NULL; //this may be used as an (exclusive) alternative to capath wit> // certfile = NULL; //set this to a string to a user certificate to enable MQTT > // keyfile = NULL; //private key for MQTT Client authentication topic = "officeshairport"; //MQTT topic where this instance of shairport-sync> publish_raw = "no"; //whether to publish all available metadata under the cod> publish_parsed = "yes"; //whether to publish a small (but useful) subset of m> empty_payload_substitute = "--"; // MQTT messages with empty payloads often a> // To avoid empty payload problems, the string here is used instead of any empty p> // Currently published topics:artist,album,title,genre,format,songalbum,volume,c> // Additionally, messages at the topics play_start,play_end,play_flush,play_resu> publish_cover = "yes"; //whether to publish the cover over mqtt in binary for> enable_remote = "yes"; //whether to remote control via MQTT. RC is available > // Available commands are "command", "beginff", "beginrew", "mutetoggle", "nexti> };

agneevX commented 1 year ago

I've deployed a broker and configured both HA and Shairport sync:

mqtt =
{
    enabled = "yes"; // set this to yes to enable the mqtt-metadata-service
    hostname = "broker"; // Hostname of the MQTT Broker
    port = 1883; // Port on the MQTT Broker to connect to
    topic = "shairport"; //MQTT topic where this instance of shairport-sync should publish. If not set, the general.name value is used.
    publish_parsed = "yes"; //whether to publish a small (but useful) subset of metadata under human-understandable topics
    publish_cover = "yes"; //whether to publish the cover over mqtt in binary form. This may lead to a bit of load on the broker
    enable_remote = "yes"; //whether to remote control via MQTT. RC is available under `topic`/remote.
};
image

I've configured the component:

image

If I play something over AirPlay, this what the player shows:

image
parautenbach commented 1 year ago

Can you download MQTT explorer and confirm that you can connect to your broker?

parautenbach commented 1 year ago

No, topics must not have a leading slash.

https://www.hivemq.com/blog/mqtt-essentials-part-5-mqtt-topics-best-practices/

MQTT Best practices Never use a leading forward slash A leading forward slash is permitted in MQTT. For example, /myhome/groundfloor/livingroom. However, the leading forward slash introduces an unnecessary topic level with a zero character at the front. The zero does not provide any benefit and often leads to confusion.

agneevX commented 1 year ago

Thanks, I was able to get this working. Apologies for deleting my comments though.