Kodi Off -> Turn off Onkyo+Samsung TV

I want to turn off TV+Onkyo reciever when Kodi goes to sleep (‘off’ state), but only if Onkyo source is on ‘HTPC’.

If course this code is not working, because condition: source is a nonexistent thing.
But how else can I achieve what I want to do?

- alias: Kodi Turn Off everything
  trigger:
    - platform: state
      entity_id: media_player.kodi
      from: 'idle'
      to: 'off'
  condition:
    - condition: source
      entity_id: media_player.onkyo_txnr676e
      source: HTPC
  action:
  - service: media_player.turn_off
    entity_id: media_player.onkyo_txnr676e

You need a template condition that checks the appropriate attribute.

Look at is_state_attr in the template docs…

Great thanks, for the upcoming generation, this is the working code:

- alias: Kodi Turn Off everything
  trigger:
    - platform: state
      entity_id: media_player.kodi
      to: 'off'
  condition:
    condition: template
    value_template: "{{ is_state_attr('media_player.onkyo_txnr676e', 'source', 'HTPC') }}"
  action:
  - delay: '00:00:05'
  - service: media_player.turn_off
    entity_id: media_player.onkyo_txnr676e
  - service: media_player.turn_off
    entity_id: media_player.samsung_50f6640
1 Like