I’ve added to the code for the JSON-CEC on Kodi so that it will conditionally stop playback and then turn off the television.
Before, I had this:
media_player:
- platform: kodi
host: 192.168.86.2
name: "Living Room Kodi"
turn_on_action:
service: media_player.kodi_call_method
data:
entity_id: media_player.living_room_kodi
method: Addons.ExecuteAddon
addonid: script.json-cec
params:
command: activate
turn_off_action:
service: media_player.kodi_call_method
data:
entity_id: media_player.living_room_kodi
method: Addons.ExecuteAddon
addonid: script.json-cec
params:
command: standby
Which is less than ideal. If I was streaming or using Live TV, the turn_off_action would turn off the television, but leave the stream going. So I added this:
turn_off_action:
- service: media_player.stop
- service: media_player.kodi_call_method
data:
entity_id: media_player.living_room_kodi
method: Addons.ExecuteAddon
addonid: script.json-cec
params:
command: standby
… which was better, but if a ‘turn_off_action’ was issued for any reason (Alexa, for instance), then the television would “Wake up” because it received a Stop command, and then go on standby again. I wrote code to fix that, now it simply says:
turn_off_action:
service: media_player.kodi_call_method
data:
entity_id: media_player.living_room_kodi
method: Addons.ExecuteAddon
addonid: script.json-cec
params:
command: stop_and_standby
And now it performs as expected.
This integrates very well with Alexa:
homeassistant:
customize:
media_player.living_room_kodi:
emulated_hue: true
emulated_hue_name: "TV"
Code is available at https://github.com/YankeeGreggo/script.json-cec/tree/feature_stop_and_standby if you wish to update your JSON-CEC on Kodi to support this.