Creating custom entity based on MQTT?

Is it possible to create my own custom entity along with a few well defined exposed attributes ?

I have a rpi running an airplay endpoint using shairport-sync.
This airplay implementation supports MQTT.

It has a few useful topics like:
/play_start (no playload)
/play_end (no playload)
/volume
etc.

I want to create a new entity type called “airplay.kitchen”.
It should expose a few attributes like:
“playerstate” which is either play_start or play_end
“volume” : 100%

and more as I get a long I guess.

Is this possible ?

I guess I could use the MQTT light with an “audioplayer icon to match” to somehow emulate the playerstate as either being on or off and also have brightness act as volume.

No idea if this will work, as there is no payload in the published mqtt topics.

1 Like

sure you can, I’ve done exactly this to send to HA the state of PIR sensors on a RPI.
I use this python command:

				MQTT_Command = ["mosquitto_pub", "-h", MQTT_Host, "-p", "1883", "-u", MQTT_User, "-P", MQTT_Password, "-t", "RPi/PIRLivingRoom", "-r", "-m", "ON"]
				ps = subprocess.Popen(MQTT_Command)

Replace “ON” with a JSON message with your state and your attributes.

Also bear in mind the universal media_player component: