I’ve been spending more hours than I care to admit working on a custom mqtt device (an R2D2 sphero toy). It’s been going well so far, but I’m confused on something.
I setup a handful of sensors through mqtt discovery with the /config
topic and corresponding payload. I end up with an mqtt device page that shows all my sensors. This is nice and expected behavior.
MQTT Discovery holoprojector config payload
homeassistant/sensor/r2d2/holoprojector/config
{
"availability_topic": "homeassistant/sensor/r2d2/availability",
"icon": "mdi:led-on",
"unique_id": "d1c1af96a0e956c89f1625533620be82",
"device": {
"identifiers": "r2d2",
"manufacturer": "Sphero",
"model": "R201",
"name": "R2D2",
"sw_version": "2022.09.29"
},
"name": "R2D2 Holoprojector LED",
"expire_after": 5,
"state_topic": "homeassistant/sensor/r2d2/holoprojector/state",
"platform": "mqtt"
}
Now, what I am confused about is when I want to make a control to set the state of one of his lights, legs, or dome, I have to setup custom mqtt devices in my configuration.yaml
file. So, what I’m left with in my python library is something like the following. Let’s take his holoprojector led for example (simple on/off and 0-255 no rgb)
- 1 topic to report the state (on/off)
- 1 topic to report the value (0-255)
- 1 topic to receive the state from the UI (on/off)
- 1 topic to receive the value from the UI (0-255)
That’s 4 topics for just a simple led. First question, is this correct?
Second question, is in my configuration.yaml
file I have the following custom light entry for him:
- name: "R2D2 Holoprojector"
unique_id: "r2d2_df12b4032fe411e4800bcd1fd09bffdc"
state_topic: "homeassistant/switch/r2d2/holoprojector/state"
command_topic: "homeassistant/switch/r2d2/holoprojector/switch"
brightness_state_topic: "homeassistant/switch/r2d2/holoprojector/brightness"
brightness_command_topic: "homeassistant/switch/r2d2/holoprojector/brightness/set"
on_command_type: "brightness"
optimistic: false
retain: false
brightness_scale: 255
payload_on: "ON"
payload_off: "OFF"
Is this not achievable with just the mqtt discovery or do I need both the configuration.yaml
entry and the discovery topic?