Thanks for the work here and all the examples everyone! I’ll post mine as well. This is for a Vizio Soundbar. It’s connected to both my TV (over Optical) and Amazon Echo Dot (on Aux 1). I control it over a homemade IR blaster built with an esp8266 with some custom firmware.
configuration.yaml
media_player:
- platform: universal
name: Soundbar
children:
- media_player.living_room
- media_player.everywhere
commands:
turn_on:
service: mqtt.publish
data:
topic: 'irblaster/tx'
# The following command is the correct command for on/off, but HomeKit
# has a quirk where it tries to make sure the soundbar is on before sending
# volume commands. But since the on/off IR codes are the same this ends
# up turning the sound bar off. I'm working around this by just sending the
# volume up command since it also will turn on the sound bar.
# payload: "{\"type\":\"NEC\",\"code\":\"FF02FD\"}"
payload: "{\"type\":\"NEC\",\"code\":\"FF827D\"}"
turn_off:
service: mqtt.publish
data:
topic: 'irblaster/tx'
payload: "{\"type\":\"NEC\",\"code\":\"FF02FD\"}"
volume_up:
service: mqtt.publish
data:
topic: 'irblaster/tx'
payload: "{\"type\":\"NEC\",\"code\":\"FF827D\"}"
volume_down:
service: mqtt.publish
data:
topic: 'irblaster/tx'
payload: "{\"type\":\"NEC\",\"code\":\"FFA25D\"}"
volume_mute:
service: mqtt.publish
data:
topic: 'irblaster/tx'
payload: "{\"type\":\"NEC\",\"code\":\"FF12ED\"}"
select_source:
service: mqtt.publish
data_template:
topic: 'irblaster/tx'
payload: >-
{"type":"NEC","code":"
{%- if source == 'Optical' -%}
FF13EC
{%- elif source == 'Aux 1' -%}
FF8D72
{%- elif source == 'USB' -%}
FF857A
{%- elif source == 'Bluetooth' -%}
FF44BB
{%- elif source == 'Aux 2' -%}
FF4DB2
{%- elif source == 'Digital' -%}
FF936C
{%- endif -%}"}
customize.yaml
media_player.soundbar:
device_class: tv
source_list:
- Optical
- Aux 1
- USB
- Bluetooth
- Aux 2
- Digital
automations.yaml - Automation to automatically switch my soundbar to Aux 1 when I’m using the whole house audio group on Alexa (using alexa_media_player) and switch it back to Optical when done.
- alias: Soundbar to Aux when the Everywhere group is playing
trigger:
- platform: state
entity_id: media_player.everywhere
to: 'playing'
- platform: state
entity_id: media_player.everywhere
from: 'playing'
action:
- service: mqtt.publish
data_template:
topic: 'irblaster/tx'
payload_template: >-
{"type":"NEC","code":"
{%- if trigger.to_state.state == 'playing' -%}
FF8D72
{%- else -%}
FF13EC
{%- endif -%}"}
Everything works including volume control via the phone’s volume buttons while in the Remote app.
The one quirk it has is that after opening the Remote app, the first time I press a volume button, the soundbar turns off. I suspect this is the Remote app’s way of trying to make sure the soundbar is on, but the IR code for the ‘on’ command is the same as the ‘off’ command. Luckily, the volume IR codes also turn the soundbar back on, so subsequent volume button presses turn the soundbar back on. I’ve worked around this quirk by just sending the volume up IR code for turn_on since it appears that also can turn the soundbar on.