Media Player - trigger on "turn on"

I have a few year old Samsung TV which does respond to the media player “turn on” command, as it has no power going to the network interface when it is powered off.

I have an IR blaster (Broadlink RM Pro) and was thinking that if I can trigger an automation when the “media_player.turn_on” event happens I could send the relevant IR command to the TV.

No matter what I try, I can’t seem to trap the “media_player.turn_on” event.

Below is the relevant section of my automations.yaml, which I think is close. If I trigger the automation manually, it turns on the TV using the Broadli, but I can’t get it trigger when I hit the power button on the media player.

- action:
  - data:
      entity_id: switch.familyroom_tv
    service: switch.turn_on
  alias: Familyroom TV On
  condition: []
  id: '1510658541182'
  trigger:
  - event_data:
      entity_id: media_player.familyroom_tv
      service: media_player.turn_on
    event_type: call_service
    platform: event

I had the same issue and made it work via CEC and Kodi running on an RPi connected via HDMI to the TV. Please let me know if you’re interested in further details on this solution.

Usually when this happens, it’s an issue with trigger or conditions for the automation. Can you please share the full automation instead?

Thanks for the reply and for your help.

CEC is not an option in my case, due to odd CEC behaviour with a couple of components, I needed to disable this as the amp was flicking between inputs.

Not sure what you mean by “share the full automation”. I have shared the relevant automation in the original post.

I know the action in the automation works, it is just the trigger which never gets triggered. The name of the media player entity is media_player.familyroom_tv and the name of the IR “switch” that I know works is switch.familyroom_tv

Sorry if this all seems quite dumb … fairly new to HA … but I work in IT, so do know a little about 'puters :slight_smile:

I could not understand what id: '1510658541182' is supposed to represent in your setup, but your automation is definitely not properly indented according to YAML syntax.

Still then, if I got it correctly, the below example should get you started.

automation:
  - alias: 'Familyroom TV On'
    trigger:
      platform: event
      event_type: call_service
      event_data:
        entity_id: media_player.familyroom_tv
        service: media_player.turn_on
    action:
      - service: switch.turn_on
        data:
          entity_id: 'switch.familyroom_tv'

Please let us know how it goes.

Thanks again for the reply, and thanks for your help so far.

The id: '1510658541182' is automatically generated by the HA automation editor. It also does some very weird stuff to formatting which makes the automations.yaml file very hard to read. This automation was created inside the HA automation editor and I did not mess with the indenting at all. There are no errors in the HA logs.

Anyway, I tried your suggested edits, and it ended up with the exact same result … if I manually trigger the automation, it works. When I try it by turning on my media player, nothing. The trigger simply is not working.

I’ve been struggling with the exact same problem - Samsung TV’s (2014) showing up as media devices and using their ‘on’ state as a trigger. I suspect its because the Media Device discovery works in such a way that when the media device is added into home assistant dynamically its state is already ‘on’ and there the change of state doesn’t work as a trigger.

I’m going to test tonight adding the samsung tv’s as permanent media players through my config.yaml and see if that helps this issue. Will report back.

Try turning logger default to ‘info’ and looking at the <call_service> data. Your trigger looks correct on the surface, but there may be a missing piece of the puzzle. If you post the relevant lines in your home-assistant.log file after you turn on ‘info’, I may be able to help.

@privatesam

Well, all I really wanted to do was to get my IR blaster to send the IR code to turn the TV on whenever the media player was turned on. I ended up using the Universal media platform at https://www.home-assistant.io/components/media_player.universal/ to replace the on command for the media player to send the IR code. All working and happy.

2 Likes