ChromecastControls icon indicating copy to clipboard operation
ChromecastControls copied to clipboard

Home Assistant integration

Open ProLoser opened this issue 5 years ago • 8 comments

This seems like a service that would be useful to run as a plug-in on the Home Assistant platform.

ProLoser avatar Jan 14 '20 20:01 ProLoser

Good idea, but I haven't delved into HA much yet. Might even be possible to implement much of this directly inside HA since it has pychromecast support built in, and CEC available as well I think. But I don't know how well it handles chromecast events for triggering actions. Feel free to contribute an HA integration if you have an idea on how to implement it.

askvictor avatar Jan 16 '20 01:01 askvictor

You know what I just realized I can probably do this using a simple home Assistant automation? How do you subscribe to state changes of Chromecast? If home Assistant also monitors the state in the same way setting up an automation to do this should be really easy

ProLoser avatar Jan 16 '20 04:01 ProLoser

But sending a power off command to the Chromecast doesn't turn off the TV. I guess I'd have to figure out how you send cec commands through the Chromecast and see if home Assistant supports it

ProLoser avatar Jan 16 '20 04:01 ProLoser

You'd need to send a CEC power command to the TV or receiver. It would look something vaguely like this: `automation:

  • alias: "Stereo Off" initial_state: true trigger:
    • platform: state entity_id: media_player.chromecast_stereo to: "off" action:
      • service: switch.turn_off entity_id: switch.stereo` (borrowed this from https://community.home-assistant.io/t/intercepting-google-assistant-when-casting-to-google-chromecast-audio/104419/3)

You'd need to change the action to use CEC (see https://www.home-assistant.io/integrations/hdmi_cec/), and it would be useful to have a timeout.

I'll have a play with it when I have a minute.

askvictor avatar Jan 16 '20 07:01 askvictor

OK; here's what I got kind of working in hass

first up, I can't get the hdmi_cec integration to work, so I've gone for shell commands instead. You need to add your homeassistant user to the video group for this to work.

In configuration.yaml add (replace 5 with the number of the device from running a cec-client scan):

shell_command:
        cec_off: "echo 'standby 5' | cec-client -s"

Then add an automation such as:

- id: '1579176804226'
  alias: CEC off from ChromeCast
  description: ''
  trigger:
  - entity_id: media_player.living_room_tv_2
    platform: state
    to: 'off'
  action:
  - service: shell_command.cec_off

This doesn't include a delay, and probably needs a little bit of logic to handle transitions a bit better, but works as a proof of concept. Should also work for volume, though will need some more work to determine if the volume is going up or down.

Let us know if you come up with anything!

askvictor avatar Jan 16 '20 12:01 askvictor

The HDMI CEC in home Assistant is for sending CEC commands from the rpi or HA device to the TV over the HDMI port.

I am a little confused, does your script send the CEC commands from the device running the script or does it remotely tell the Chromecast device to send a CEC command to it's connected tv?

My HA device is not connected to the chromecasted TV so I can't send the command from the device, it needs to come from the Chromecast

ProLoser avatar Jan 16 '20 16:01 ProLoser

You need a Raspberry Pi (or other computer with CEC, such as a pulse-8 adapter) connected to your TV. The Chromecast only sends CEC commands that Google has blessed, which is the whole reason this project exists - to fill in the gaps in Google's implementation. But we can't control the Chromecast's CEC bus.

To directly answer your question, this system sends CEC commands directly from the device the script runs on.

askvictor avatar Jan 16 '20 22:01 askvictor

Thank you for that clarification, I think I only realized all that after iterating on the idea. Damnit Google.

ProLoser avatar Jan 17 '20 04:01 ProLoser