Emulated Roku and Power Commands

Does anyone know if the emulated ROKU component can detect poweron/poweroff button presses. I’m trying to fix a minor but annoying issue I have with my harmony remote and my sony TV. I use lan control to turn the tv on/off, and every once it a while it looses it shared key and I have to go into the app and reenter it for the remote to start working again.

I never have that issue with HA, so I was thinking about adding the emulated Roku, and basically having a “failsafe” that would send a poweron command to my TV when the roku turned on, and a poweroff when the roku turned off. If I use buttons like fwd, etc, I’m confident that the harmony will end up turning on/off the TV when it should not.

Anyway here are the example automations, now I just need to see of poweroff/on are valid

- id: tv_force_on
  alias: TV Force On
  trigger:
  - platform: event
    event_type: roku_command
    event_data:
      source_name: Home Assistant
      type: keypress
      key: PowerOn  #this does not work
  action:
  - service: media_player.turn_on
    entity_id: media_player.living_room_tv

- id: tv_force_off
  alias: TV Force Off
  trigger:
  - platform: event
    event_type: roku_command
    event_data:
      source_name: Home Assistant
      type: keypress
      key: PowerOff
  action:
  - service: media_player.turn_off
    entity_id: media_player.living_room_tv

Edit: Answering my own question, thanks to the event monitor. There is not a power on, but there is a poweroff. I think this will work perfectly.

Just wanted to share what I came up with. Basically when the harmony loses the PreShared Key, I have to go back into the app and reload it. It’s not the end of the world, and I realize what has happened almost immediately. But… it always seems to happen when I’m not home and my wife is the one not able to get the TV to come on, ends up having to dig out the TV remote turn it on and often change the input.

So added the emulated Roku to two activities. The most common ones. The Tivo one sends a fwd command and the apple tv sends the Rev command. The automation might be a bit overkill, but I figure this way, it should only try to “help” if things really are not working as they should, and it will send me a message so I know it’s happening, and I can go in and fix it when I get a chance. Once the TV is on, i really only use it for the picture anyway.

- id: tv_force_on_tivo
  alias: TV Force On for Tivo
  trigger:
  - platform: event
    event_type: roku_command
    event_data:
      source_name: Home Assistant
      type: keypress
      key: Fwd
  action:
  - delay:
      seconds: 10
  - condition: or
    conditions:
    - condition: template
      value_template: {{ (states.media_player.living_room_tv.attributes.source) == "HDMI 2" }}
    - condition: state
      entity_id: media_player.living_room_tv
      state: 'off'
  - service: media_player.turn_on
    entity_id: media_player.living_room_tv
  - delay:
      seconds: 10
  - service: media_player.select_source
    data:
      entity_id: media_player.living_room_tv
      source: 'HDMI 3/ARC'
  - service: notify.pushbullet_notifications
    data_template:
      target:
      - !secret pauls_secret_email
      title: Sony TV lost Key
      message: Fix Harmony

- id: tv_force_on_apple_tv
  alias: TV Force On for Apple TV
  trigger:
  - platform: event
    event_type: roku_command
    event_data:
      source_name: Home Assistant
      type: keypress
      key: Rev
  action:
  - delay:
      seconds: 10
  - condition: or
    conditions:
    - condition: template
      value_template: {{ (states.media_player.living_room_tv.attributes.source) == "HDMI 3/ARC" }}
    - condition: state
      entity_id: media_player.living_room_tv
      state: 'off'
  - service: media_player.turn_on
    entity_id: media_player.living_room_tv
  - delay:
      seconds: 10
  - service: media_player.select_source
    data:
      entity_id: media_player.living_room_tv
      source: 'HDMI 2'
  - service: notify.pushbullet_notifications
    data_template:
      target:
      - !secret pauls_secret_email
      title: Sony TV lost Key
      message: Fix Harmony

- id: tv_force_off
  alias: TV Force Off
  trigger:
  - platform: event
    event_type: roku_command
    event_data:
      source_name: Home Assistant
      type: keypress
      key: PowerOff
  action:
  - delay:
      seconds: 10
  - condition: state
    entity_id: media_player.living_room_tv
    state: 'on'
  - service: media_player.turn_off
    entity_id: media_player.living_room_tv

I also have a similar issue with there not being a PowerOn option too, it’s driving me crazy. Did you figure this out? Or does anyone have a solution, I though I worked it out by using ‘type: launch’ in my HA automation but it didn’t work.