I’ve implemented a very simple REST API on top of bluetoothctl to allow me to connect and disconnect various bluetooth headphones/speakers on a headless media streaming server.
In HA I have a switch
switch:
- platform: rest
name: "WH-1000XM4"
resource: "http://192.168.0.2:5000/bluetoothctl/88:C9:E8:1C:F7:B2"
body_on: '{"connect":"true"}'
body_off: '{"connect":"false"}'
is_on_template: "{{ value_json.connected }}"
headers:
Content-Type: application/json
Which allows me to connect and disconnect the headphones. But I would also like to be able to query the current codec and be able to change it. At this point I’m completely lost. Can this all be done within the switch entity, or do I need to be using a dfferent entity type?
The API response is this
{
"connected": true,
"active_codec": "ldac_hq",
"available_codecs": [
{
"name": "sbc",
"description": "SBC"
},
{
"name": "sbc_xq_453",
"description": "SBC XQ 453kbps"
},
{
"name": "sbc_xq_512",
"description": "SBC XQ 512kbps"
},
{
"name": "sbc_xq_552",
"description": "SBC XQ 552kbps"
},
{
"name": "ldac_hq",
"description": "LDAC (High Quality)"
},
{
"name": "ldac_sq",
"description": "LDAC (Standard Quality)"
},
{
"name": "ldac_mq",
"description": "LDAC (Mobile Quality)"
}
]
}
So I’d need to store active codec and supported codecs in attributes and then have a way of selecting from the available list in HA to trigger a POST call back to the API.
Any pointers on how to implement this? It’s way beyond my current HA knowledge.