Homeassistant + Chromecast + Capturing device without HDMI-CEC + Samsung (or whatever) TV + Ambilight. Correct way to turn off your Chromecast

Hello.
I want to share something with you. Last week i decided to make a Ambilight for my not-so-smart TV Samsung 65’.

My set is:

  • Raspberry Pi Zero 2W,
  • Chromecast 4 with Raspbian and Hyperion,
  • Cheap chineese HDMI => USB Audio Video Grabber without HDMI-CEC (i can’t turn off device with that).
  • Not-so-smart TV Samsung (your tv has to be connected to homeassistant, and has to be found as “media player”.

So, firstly i made integration that turning on/off Chromecast via Homeassistant automation with Google cast integration . I had 2 problems: Splashscreen “WELCOME TO HOMEASSISTANT” on start Chromecast, which is not so nice view, especially with Ambilights. Second thing is that its wasn’t so responsive, i had to click “back” on remote couple of times to turn off this screen. I hate it.

Second problem was that when i used “media_player.turn_off” action it wasn’t turning off my chromecast. It didn’t went sleep. It just stopped streaming from Hass to Chromecast.

Third, Chromecast is weak with state changes. When my CC is turned off i have to wait about 30 seconds for Homeassistant state change. Maybe it works good in your case?

I saw it on preview in Hyperion. Device was working, and sending current Chromecast screen live. I have seen it on animations it wasn’t just “last frame before stop”. Like on image below.

image

So i started to make my research and didn’t found an answer for my problem.
After time i realised that i need something else. I have found Android TV Integration. And it made a job.
Now im sending “WAKEUP” and “SLEEP” adb commands via AndroidTv integration and it works really good.

Okay, so instructions:
Chromecast preparing:

  1. Go to Settings (your picture on right, up corner => settings)
  2. Go to System
  3. Click About
  4. Find Android TV OS build
  5. Pick it from list and “click” on it 7 times. You are developer now!
  6. Go to Remotes and accessories
  7. Find something like “Buttons settings”
  8. Configure power button to power on/off your television (its propably CEC now)
  9. If you can’t do that, try to configure your TV in chromecast settings. It has plenty of futures.
    Make sure your chromecast remote is turning off/on your tv.

Okay, so we are ready to prepare script. You can remove lights from it because i guess its not only problem.

Explanation:

  1. Detect state change of your TV
  2. Ensure what it did (on? off? else?)
  3. Wait a second to hass is informed about change
  4. Make CC actions.
alias: Samsung and chromecast
description: ""
trigger:
  - platform: device
    type: changed_states
    device_id: #pick your TV
    entity_id: #pick your TV
    domain: media_player
condition: []
action:
  - delay:
      hours: 0
      minutes: 0
      seconds: 1
      milliseconds: 0
  - if:
      - condition: state
        entity_id: #pick your TV
        state: "off"
    then:
      - service: androidtv.adb_command
        data:
          command: SLEEP
        target:
          entity_id: #pick your chromecast Android TV Instance
      - service: light.turn_off
        data: {}
        target:
          entity_id: #pick your ambient Hyperion LED instance 
    else:
      - service: androidtv.adb_command
        data:
          command: WAKEUP
        target:
          entity_id:  #pick your chromecast Android TV Instance
      - service: light.turn_on
        data: {}
        target:
          entity_id: #pick your ambient Hyperion LED instance 
mode: single

Now, you don’t have a HASS Splash screen, and you are saving compute power of your Chromecast, and not waisting your electrocity.

Good to know:

  • WAKEUP is just “OK” button on remote. It is described in

Android TV Docs

Bonus: Android tv integration:

  1. Go to AndroidTV Integration in home-assistant website
  2. Click integrate
  3. Set “Auto”
  4. Give Chromecast IP
  5. Do not change anything more
  6. Submit

Test it:

  1. http://your-hass-address/developer-tools/service
  2. Find Android TV: ADB command

  1. Choose entity

  2. Use SLEEP and WAKEUP command, and check your Chromecast reactions.

Thats my case. Thats what i wanted to share with you.
Thanks for reading.

Bonus 2 my setup. White box under HDMI Thief is Raspberry Zero with 3d printed case:


And final effect:

Xmass tree is also made with hyperion and RB Zero :smiley:

Whole stuff has Wife Acceptance Certificate with A+ mark.