From d6d0876fff7148dc8fceb9284543af76a06f25f8 Mon Sep 17 00:00:00 2001 From: Jeff Irion Date: Tue, 20 Oct 2020 04:32:22 -0700 Subject: [PATCH] Convert Kodi `turn_on_action` / `turn_off_action` examples to automations (#15324) --- source/_integrations/kodi.markdown | 156 ++++++++++++++++------------- 1 file changed, 89 insertions(+), 67 deletions(-) diff --git a/source/_integrations/kodi.markdown b/source/_integrations/kodi.markdown index 6326575770c..dfe5c051b9f 100644 --- a/source/_integrations/kodi.markdown +++ b/source/_integrations/kodi.markdown @@ -36,7 +36,34 @@ If you do not remove it, your configuration will be imported with the following ### Turning On/Off -You can customize your turn on and off actions through automations. Simply use the relevant Kodi device triggers and your automation will be called to perform the `turn_on` or `turn_off` sequence. +You can customize your turn on and off actions through automations. Simply use the relevant Kodi device triggers and your automation will be called to perform the `turn_on` or `turn_off` sequence; see the [Kodi turn on/off samples](#kodi-turn-onoff-samples) section for scripts that can be used. + +These automations can be configured through the UI (see [Device Triggers](/automation/trigger/#device-triggers) for automations). If you prefer YAML, you'll need to get the device ID from the UI automation editor. Automations would be of the form: + +```yaml +automation: + - id: kodi_turn_on + alias: "Kodi: turn on" + trigger: + - platform: device + device_id: !secret kodi_device_id + domain: kodi + entity_id: media_player.kodi + type: turn_on + action: + - service: script.kodi_turn_on + + - id: kodi_turn_off + alias: "Kodi: turn off" + trigger: + - platform: device + device_id: !secret kodi_device_id + domain: kodi + entity_id: media_player.kodi + type: turn_off + action: + - service: script.kodi_turn_off +``` ### Services @@ -75,17 +102,16 @@ result: ### Kodi turn on/off samples -With the `turn_on_action` and `turn_off_action` parameters you can run any combination of Home Assistant actions to turn on/off your Kodi instance. Here are a few examples of this usage, including the **migration instructions for the old `turn_off_action` list of options**. +The following scripts can be used in automations for turning on/off your Kodi instance; see [Turning on/off](#turning-onoff). You could also simply use these sequences directly in the automations without creating scripts. #### Turn on Kodi with Wake on LAN With this configuration, when calling `media_player/turn_on` on the Kodi device, a _magic packet_ will be sent to the specified MAC address. To use this service, first you need to configuration the [`wake_on_lan`](/integrations/wake_on_lan) integration in Home Assistant, which is achieved simply by adding `wake_on_lan:` to your `configuration.yaml`. ```yaml -media_player: - - platform: kodi - host: 192.168.0.123 - turn_on_action: +script: + turn_on_kodi_with_wol: + sequence: - service: wake_on_lan.send_magic_packet data: mac: aa:bb:cc:dd:ee:ff @@ -96,69 +122,64 @@ media_player: Here are the equivalent ways to configure each of the old options to turn off Kodi (`quit`, `hibernate`, `suspend`, `reboot`, or `shutdown`): -- **Quit** method (before was `turn_off_action: quit`) +- **Quit** method ```yaml -media_player: - - platform: kodi - host: 192.168.0.123 - turn_off_action: - service: kodi.call_method - data: - entity_id: media_player.kodi - method: Application.Quit +script: + kodi_quit: + sequence: + - service: kodi.call_method + data: + entity_id: media_player.kodi + method: Application.Quit ``` -- **Hibernate** method (before was `turn_off_action: hibernate`) +- **Hibernate** method ```yaml -media_player: - - platform: kodi - host: 192.168.0.123 - turn_off_action: - service: kodi.call_method - data: - entity_id: media_player.kodi - method: System.Hibernate +script: + kodi_hibernate: + sequence: + - service: kodi.call_method + data: + entity_id: media_player.kodi + method: System.Hibernate ``` -- **Suspend** method (before was `turn_off_action: suspend`) +- **Suspend** method ```yaml -media_player: - - platform: kodi - host: 192.168.0.123 - turn_off_action: - service: kodi.call_method - data: - entity_id: media_player.kodi - method: System.Suspend +script: + kodi_suspend: + sequence: + - service: kodi.call_method + data: + entity_id: media_player.kodi + method: System.Suspend ``` -- **Reboot** method (before was `turn_off_action: reboot`) +- **Reboot** method ```yaml -media_player: - - platform: kodi - host: 192.168.0.123 - turn_off_action: - service: kodi.call_method - data: - entity_id: media_player.kodi - method: System.Reboot +script: + kodi_reboot: + sequence: + - service: kodi.call_method + data: + entity_id: media_player.kodi + method: System.Reboot ``` -- **Shutdown** method (before was `turn_off_action: shutdown`) +- **Shutdown** method ```yaml -media_player: - - platform: kodi - host: 192.168.0.123 - turn_off_action: - service: kodi.call_method - data: - entity_id: media_player.kodi - method: System.Shutdown +script: + kodi_shutdown: + sequence: + - service: kodi.call_method + data: + entity_id: media_player.kodi + method: System.Shutdown ``` #### Turn on and off the TV with the Kodi JSON-CEC Add-on @@ -166,28 +187,29 @@ media_player: For Kodi devices running 24/7 attached to a CEC capable TV (OSMC / OpenElec and systems alike running in Rasperry Pi's, for example), this configuration enables the optimal way to turn on/off the attached TV from Home Assistant while Kodi is always active and ready: ```yaml -media_player: - - platform: kodi - host: 192.168.0.123 - turn_on_action: - service: kodi.call_method - data: - entity_id: media_player.kodi - method: Addons.ExecuteAddon - addonid: script.json-cec - params: - command: activate - turn_off_action: - - service: media_player.media_stop - data: - entity_id: media_player.kodi +script: + turn_on_kodi_with_cec: + sequence: - service: kodi.call_method data: entity_id: media_player.kodi method: Addons.ExecuteAddon addonid: script.json-cec params: - command: standby + command: activate + + turn_off_kodi_with_cec: + sequence: + - service: media_player.media_stop + data: + entity_id: media_player.kodi + - service: kodi.call_method + data: + entity_id: media_player.kodi + method: Addons.ExecuteAddon + addonid: script.json-cec + params: + command: standby ```