Trigger adb command when Harmony Activity runs

Hey guys ,

Trying to setup an automation for Harmony and my AndroidTV Box (Mibox 3) that works following way :

  1. Start an Harmony Activity
  2. Launch an App on my Android TV after that activity starts

So far I have the following code :

- alias: "Netflix Mode"
  trigger:
    platform: state
    entity_id: remote.living_room~
  condition:
    condition: template
    value_template: '{{ trigger.to_state.attributes.current_activity == "Watch Netflix" }}'
  action:
    service: androidtv.adb_command
    data:
      entity_id: media_player.mibox3_android_tv
      command: am start -n com.netflix.ninja/.MainActivity

However, I want it to work so that even if my Netflix activity is already active it will still execute the adb action .

Possible scenarios :

  • Current activity is poweroff or any other activity and it starts netflix activity
  • Current activity is already netflix activity but it will still run the action when I try to run netflix activity on harmony hub .

Just started messing around with Homeassistant / Hassio a couple of days ago so not really sure how to tackle this , what kind of aditional conditions do I need to add in order to achieve my goal ?

Edit : Just realized there is a huge delay before the netflix app is actually launched ! When I call the service directly through Hassio it launches the app instantly, but with this automation it takes a good 15 to 20seconds before netflix is opened ! Any clues ?

Thanks !

Does your code work currently?

How can you even do this on the Harmony? For me this is not possible, when an activity is running I can’t press the button again.

Edit: If you launch the activity directly from home assistant it overrides that. So for example, let’s suppose your harmony hub states activity is netflix but your dvr is off and your tv input is not the right one. The activity will still run and turn on dvr and change tv input to what you programmed in your activity !

However the netflix app part only seems to run if the activity isn’t already previously running…

I am getting a huuuge delay before netflix app is launched in the android tv, not sure what’s wrong !

Maybe someone could try run this automation on their side to check if they also get the delay I am experiencing before launching netflix app, that would help sorting out if issue is script related or not .

Do you control your devices in multiple ways or how can the TV input be wrong when the activity is as you defined?

Try to see how long it takes until home assistant recognizes that the activity changed to Netflix. I think the delay could come from there. You could also try to turn on a light when the activity changes to Netflix and see if it takes equally long for this.

The TV input can be wrong if you manually override it for instance, or if you turn off the tv or dvr with the netflix activity running . The activity state will still be current activity: Your activity if you change any of these manually .

No issues there, the state is changing immediatly after the activity runs, just tested !

If I call netflix adb command manually it also runs instantly so feeling a bit lost here .

Ok I understand, even though I don’t see a reasom to turn off the TV manually instead of using the activity Power Off or why would one change the TV input manually instead of switching to another activity.

Could you try to change your trigger to this:

  trigger:
    - platform: template
      value_template: "{{ is_state_attr('remote.living_room', 'current_activity', 'Watch Netflix') }}"
1 Like

Thanks buddy, that works perfect ! No delays whatsoever now :slight_smile:

Now just need to figure how to make the netflix app open in case the netflix activity is already stated as active ! Although the activity still runs as previously stated, it does not trigger the adb command action

Guess I will need an automation that will detect my harmony activity state and based on that either run the activity if it’s a different one or just send an adb command if it already matches the current activity .