Native support for Android TV / Android devices


#142

Hi,
could someone please tell me how I use the below as a script, as I would like to create a button that triggers an app or youtube video ect on my shield.

I’m currently on hassio and plan to install the newly created add-on


#143

I managed to get it working, using hass.io + shield combination! So far so good, just 2 questions:

  • there is a 5 second delay between state changes. Will this be better if I use docker or hassbian?
  • I have set up light automations based on the ‘playing’, ‘paused’ or ‘idle’ state. However, I want to excluse spotify from the automations. Is there anyway I can let it ignore Spotify? I don’t need the lights to dim when I play some music :sweat_smile:

#144

@StimpyMGS can you share your automotion for light dimming based on media status?


#145
scene:
  - name: playing
    entities:
      light.dining_1:
        state: off
        transition: 2
      light.dining_2: 
        state: off
        transition: 2
      light.dining_3:
        state: off
        transition: 2
      light.living_1:
        state: on
        transition: 2
        brightness_pct: 3
      light.living_2: 
        state: on
        transition: 2
        brightness_pct: 3     
      light.living_3:
        state: on
        transition: 2
        brightness_pct: 3 
      light.living_penguin:
        state: on
        transition: 2
        brightness_pct: 3
      light.hallway_main:
        state: off
        transition: 3        
  - name: paused
    entities:
      light.living_1:
        state: on
        transition: 2
        brightness_pct: 35
      light.living_2: 
        state: on
        transition: 2
        brightness_pct: 35     
      light.living_3:
        state: on
        transition: 2
        brightness_pct: 35 
      light.living_penguin:
        state: on
        transition: 2
        brightness_pct: 60
      light.dining_1:
        state: on
        transition: 2
        brightness_pct: 35         
      light.dining_2: 
        state: on    
        transition: 2
        brightness_pct: 35         
      light.dining_3:
        state: on  
        transition: 2
        brightness_pct: 35        

And the automation:

  - alias: "Media player paused/stopped"
    initial_state: true
    trigger:
      - platform: state
        entity_id:  media_player.shieldtv
        from: 'playing'
        to: 'paused'
      - platform: state
        entity_id:  media_player.shieldtv
        from: 'playing'
        to: 'idle'       
      - platform: state
        entity_id:  media_player.shieldtv
        from: 'playing'
        to: 'off'        
    condition:  
       condition: and
       conditions:
         - condition: template
           value_template: "{{ states.sun.sun.attributes.elevation  | int < 3 }}"
    action:
        service: scene.turn_on
        entity_id: scene.paused

  - alias: "Media player playing"
    initial_state: true  
    trigger:
      - platform: state
        entity_id:  media_player.shieldtv
        from: 'paused'        
        to: 'playing'
      - platform: state
        entity_id:  media_player.shieldtv
        from: 'idle'        
        to: 'playing' 
      - platform: state
        entity_id:  media_player.shieldtv
        from: 'off'        
        to: 'playing'        
    condition:  
       condition: and
       conditions:
         - condition: template
           value_template: "{{ states.sun.sun.attributes.elevation  | int < 3 }}"
    action:
        service: scene.turn_on
        entity_id: scene.playing

#146

Hi @phairplay, I’ve been working on something similar to what you requested. Here’s a screen shot of my Picture Elements Card: -

I drew the image in Powerpoint and then I’ve placed some invisible buttons over the images, so they behave like buttons. I’ve followed the documentation from adb addon and then the code for one of the buttons looks like this: -

  - entity: input_boolean.androidtv
    image: /local/RemoteButtonClear.png
    style:
      height: 22%
      left: 17%
      top: 15%
      width: 10%
    tap_action:
      action: call-service
      service: media_player.androidtv_key
      service_data:
        entity_id: media_player.android_tv
        key: KEYCODE_DPAD_UP
    type: image

I found this: -


from @mcfrojd really helpful. Most of the Key commands work but I had to find out the specific intents from my device to get it working.

Hope it helps


#147

This is so cool! Do you have your config on github or are you willing to share the lovelace yaml code used to make this?


#148

Hi bobokun,
There’s really not much going on with code. Each button is basically the same. I’ve drawn the entire picture in Powerpoint and then saved it as a png. I’ve found Powerpoint to be useful because of all the built in icons and the alignment tools are very useful. I created a coloured button (RemoteButton.png), which is just a square shape that I saved as its own png file, and then positioned that over each of the icons. When I was happy with the placement I swapped the coloured button for an invisible one (RemoteButtonClear.png). When I say invisible, I just changed the shape in Powerpoint, so it had no outline or fill, then saved that as a png file. All these images are in the www folder in config. The DPAD cursor type buttons use the code I shared above and the intent buttons (for apps etc) use this code: -

      - entity: input_boolean.androidtv
        image: /local/RemoteButtonClear.png
        style:
          height: 22%
          left: 41%
          top: 34%
          width: 10%
        tap_action:
          action: call-service
          service: media_player.androidtv_intent
          service_data:
            entity_id: media_player.android_tv
            intent: '-n org.xbmc.kodi/.Splash'

The difference is the type of service that is called and ‘key’ is replaced with ‘intent’. You need to follow all the steps of adding the adb addon: -


You also have to add the androidtv.py file to the relevant location and create the media_player entity.

The input_boolean entity is a dummy that allows you to have an element on this card. Everything is actually controlled from the service calls.

Hope that helps.


#149

Does anybody know how to turn on / off Ambilight + Hue on a philips android TV using this component?


#150

I tried to use it with Philips TV 55POS900212 and experience the same issue when it correctly shows which app is running but it doesn’t change idle status to playing when the app is actually playing. I can provide details if it helps to debug it.