GithubHelp home page GithubHelp logo

paolotremadio / homebridge-automation-chromecast Goto Github PK

View Code? Open in Web Editor NEW
35.0 6.0 12.0 51 KB

Expose Chromecast/Chromecast Audio devices in Homebridge to enable automations

JavaScript 100.00%
homebridge-plugin homekit chromecast chromecast-audio nodejs

homebridge-automation-chromecast's Introduction

Automation - Chromecast / Chromecast Audio

Installation

Install dependencies

This command will work on Raspbian. Please Google the right comand for your platform.

sudo apt-get install libavahi-compat-libdnssd-dev

Config example

Example config.json:

{
  "accessories": [
    {
      "accessory": "AutomationChromecast",
      "name": "Test",
      "chromecastDeviceName": "<The device Name of your Chromecast>",
      "switchOffDelay": 10000
    }
  ]
}

This accessory will create a switch linked with the status of a Chromecast or Chromecast Audio device.
It will also create a Motion Sensor, to trigger automation.

When you stream some audio/video to the Chromecast / Chromecast Audio, the switch turns on and the Sensor detects movement. Stop the streaming will turn the switch off and the sensor will stop detecting movements.

Turning On the switch will play the currently casted stream. Turning Off the switch will stop the stream.

The switch has the following properties:

Name Description Example
Type The type of the device. Chromecast Audio
IP Address The full IP address + port of the device 192.168.1.100:8009
ID The Chromecast UUID a80722d5aa123456e408635c475988ca
Volume The volume slider, to adjust the volume of the device (it can be also used within automations) n/a

Note: some properties are not compatible with iOS Home app, use Elgato Eve app instead.

Configuration options

Attribute Required Usage Example
name Yes A unique name for the accessory. It will be used as the accessory name in HomeKit. Living Room TV
chromecastDeviceName Yes The name of your Chromecast device as shown in your Google Home App (case insensitive). This plugin will use Bonjour/mdns to detect the IP address of the Chromecast based on this name. Living Room
switchOffDelay No (default: 0) The number of milliseconds to wait before the motion sensor stops detecting movement after stop casting. By default it is set to zero: as soon as you stop playing, the motion sensor will switch off. If you want to add a delay, set it to a value greater than zero. This config is useful for automations (see later example on this readme). 5000 (milliseconds, equal to 5 seconds)

Credits

This project as been largely inspired by the work of @robertherber

Examples

Dim the lights when I stream some video to my Chromecast

  1. Create an accessory in Homebridge (code example at the top of this readme)
  2. Create a new automation in iOS Home/HomeKit: when the Motion Sensor detects movement, trigger a scene of your choice (e.g. "Movie lights")
  3. Start streaming to the Chromecast. The Motion Sensor will detect a movement, triggering the scene

Turn on/off the speakers when I streaming music

Let's assume you have some powered speakers that need to be turned on before use (I have for example the Yamaha HS8).

You can connect the speakers to a Chromecast Audio device and connect the to an Elgato Eve Energy) switch.

You want to turn On the speakers automatically when streaming music and turning them Off once done.

Here's how:

  1. Create an accessory in Homebridge (code example at the top of this readme). Set the switchOffDelay to 30000 (30 seconds)
  2. Create a new automation in iOS Home/HomeKit: when the Motion Sensor exposed by this plugin detects movement, turn on the speaker plug
  3. Create a new automation in iOS Home/HomeKit: when the Motion Sensor exposed by this plugin stop detecting movement, turn off the speaker plug
  4. Start streaming music to the Chromecast. The Motion Sensor will detect a movement, turning on the speakers
  5. Stop / pause streaming. The motion sensor will wait 30 seconds before stop detecting movement, turning off the speakers

Using a delay will prevent the speakers from switching on and off constantly when you momentarily stop/start a stream (to avoid damages to the speakers)

Other examples

  • Mute your Chromecast Audios when playing something from your Chromecast Video
  • Pause your Chromecast when leaving home

Other useful plugins

Do you want to play some audio/video on demand from your automation?

Check my homebridge-automation-chromecast-play plugin.

homebridge-automation-chromecast's People

Contributors

donavanbecker avatar paolotremadio avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

homebridge-automation-chromecast's Issues

Can't get it to work, homebridge keeps crashing

Everytime i try to install the accesory in the accesory tab, my homebridge is stuck. It's searching for the device, and then this error shows up and it reboots

[12/31/2019, 3:23:12 PM] Error: getaddrinfo -3008
    at errnoException (/homebridge/node_modules/mdns/lib/resolver_sequence_tasks.js:199:11)
    at getaddrinfo_complete (/homebridge/node_modules/mdns/lib/resolver_sequence_tasks.js:112:10)
    at GetAddrInfoReqWrap.oncomplete (/homebridge/node_modules/mdns/lib/resolver_sequence_tasks.js:120:9)

[12/31/2019, 3:23:12 PM] Got SIGTERM, shutting down Homebridge...

Homebridge crash

This can happen 1-3 times a day.

Is it something obvious or should I leave it debugging?

[2018-4-19 23:41:38] [Chromecast] Chromecast found on 172.16.1.31:8009
[2018-4-19 23:41:38] [Chromecast] Connecting to Chromecast on 172.16.1.31:8009
[2018-4-19 23:41:38] [Chromecast] Chromecast connection: connected
Error: write EPIPE
    at ChildProcess.target._send (internal/child_process.js:713:20)
    at ChildProcess.target.send (internal/child_process.js:597:19)
    at Timeout.setInterval [as _onTimeout] (C:\Users\pax07\node_modules\homebridge-config-ui-x\src\index.ts:60:10)
    at ontimeout (timers.js:466:11)
    at tryOnTimeout (timers.js:304:5)
    at Timer.listOnTimeout (timers.js:267:5)

Homebridge crashing

Hello, I seem to be having similar issues to #11 and #9. But my circumstances are different. I am running HB on my Arch server with avahi-daemon installed. I am getting a similar if not identical error message and my HB crashes and restarts.

Error: getaddrinfo -3008 at errnoException (/usr/local/lib/node_modules/homebridge-automation-chromecast/node_modules/mdns/lib/resolver_sequence_tasks.js:199:11) at getaddrinfo_complete (/usr/local/lib/node_modules/homebridge-automation-chromecast/node_modules/mdns/lib/resolver_sequence_tasks.js:112:10) at GetAddrInfoReqWrap.oncomplete (/usr/local/lib/node_modules/homebridge-automation-chromecast/node_modules/mdns/lib/resolver_sequence_tasks.js:120:9)

Any ideas as to what this could be? I've been trying to find a way to link my Chromecasts to HomeKit and the other plugins out there all don't seem to work either.

Feature request: please support Chromecast IP and port configuration

This is exactly what I need to turn on my HomeKit controlled receiver when I stream and turn it off with a delay once I stop streaming. I run Homebridge in docker on QNAP NAS which doesn’t have mDNS.

I would love to be able to configure this for my chromecasts that have static ip addresses on my QNAP docker.

If anyone has a solution or alternative then please reply.

Fail to load plugin. `SyntaxError: Unexpected token )`

Installed the plugin with ``, added the accessory to configuration.

When homebridge initializes exits with an error that could not load the plugin because of an Unexpected token.

[8/5/2018, 1:54:24 AM] ====================
[8/5/2018, 1:54:24 AM] ERROR LOADING PLUGIN homebridge-automation-chromecast:
[8/5/2018, 1:54:24 AM] /usr/lib/node_modules/homebridge-automation-chromecast/index.js:245
          );
          ^
SyntaxError: Unexpected token )
    at Object.exports.runInThisContext (vm.js:78:16)
    at Module._compile (module.js:543:28)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:488:32)
    at tryModuleLoad (module.js:447:12)
    at Function.Module._load (module.js:439:3)
    at Module.require (module.js:498:17)
    at require (internal/module.js:20:19)
    at Plugin.load (/usr/lib/node_modules/homebridge/lib/plugin.js:72:22)
    at Server.<anonymous> (/usr/lib/node_modules/homebridge/lib/server.js:142:14)
[8/5/2018, 1:54:24 AM] ====================

TypeError: Cannot read property 'toLowerCase' of undefined

I've added my Chromecast with hardcoded IP. Because name detection didn't worked.
After this i found this in the log.

Maybe this was the problem the whole time.

Still it doesn't work to detect my chromecast....

[01/03/2021, 20:14:05] TypeError: Cannot read property 'toLowerCase' of undefined at Browser.<anonymous> (/usr/local/lib/node_modules/homebridge-automation-chromecast/index.js:112:60) at Browser.emit (events.js:315:20) at on_resolver_done (/usr/local/lib/node_modules/homebridge-automation-chromecast/node_modules/mdns/lib/browser.js:31:14) at next (/usr/local/lib/node_modules/homebridge-automation-chromecast/node_modules/mdns/lib/browser.js:106:7) at Array.makeAddressesUnique (/usr/local/lib/node_modules/homebridge-automation-chromecast/node_modules/mdns/lib/resolver_sequence_tasks.js:177:5) at next (/usr/local/lib/node_modules/homebridge-automation-chromecast/node_modules/mdns/lib/browser.js:109:21) at /usr/local/lib/node_modules/homebridge-automation-chromecast/node_modules/mdns/lib/resolver_sequence_tasks.js:160:11 at getaddrinfo_complete (/usr/local/lib/node_modules/homebridge-automation-chromecast/node_modules/mdns/lib/resolver_sequence_tasks.js:108:7) at GetAddrInfoReqWrap.oncomplete (/usr/local/lib/node_modules/homebridge-automation-chromecast/node_modules/mdns/lib/resolver_sequence_tasks.js:120:9)

Problem with IP-address resolving

My homebridge says that there is a problem with this [6/26/2020, 9:58:07 PM] The plugin "homebridge-control-chromecast" defines 'homebridge' and/or 'hap-nodejs' in their 'dependencies' section, meaning they carry an additional copy of homebridge and hap-nodejs. This not only wastes disk space, but also can cause major incompatibility issues and thus is considered bad practice. Please inform the developer to update their plugin!

and every time when it starts it finds my Chromecast as 172.0.0.200

but my home network has 192.168.1.X/24 mask

Homebridge based on Raspberry pi and homebridge.io OS image 1.0.6

Help me please to solve it - b/c your plug-in is very nice and usefull

Audio only

Hi, it works only when I stream audio.

Should playing stream to ChromecastAudio turn the Homebridge switch "On"?

Hello, and thanks for the plugin. I'm just getting into the world of Homebridge and plugins, and really like the concept of the plugin.

I'm confused, however, as to if the switch for the plugin's accessory in Elgato Eve app (simple on/off toggle) is supposed to turn ON when I begin casting to the device. My understanding is that it is supposed to, yes, and it also activates the virtual motion sensor with positive "movement" too. And that, once the stream is stopped and no more data is being sent to the device, the switch then goes to OFF and the motion sensor will be turned off after the switchOffDelay value.

The reason I ask is because I'm experiencing an issue where I can stream audio to my ChromecastAudio, but the plugin does not activate the "ON/OFF" switch. Neither is there any information in the Homebridge .err or .log files for activation (or errors related thereunto).

If I go into the Elgato Eve app and manually activate the switch, or turn it off, I see in the homebridge.log:

[1/25/2019, 1:43:16 AM] [ChromecastAudio] Searching for Chromecast device named "ChromecastAudio>"
[1/25/2019, 1:45:17 AM] [ChromecastAudio] Chromecast is now playing
[1/25/2019, 1:45:17 AM] [ChromecastAudio] Motion sensor is detecting movements
[1/25/2019, 1:48:40 AM] [ChromecastAudio] Chromecast is now stopped
[1/25/2019, 1:48:50 AM] [ChromecastAudio] Motion sensor stopped detecting movements

However, that's it. Any ideas? stats are:

Ubuntu 18.04 LTS
node v11.7.0
homebridge v0.4.45
homebridge-hue v0.11.11
homebridge-automation-chromecast v1.0.3

(this is my very first post to Git, so please forgive me if I've missed any information)

unable to load the plugin

I get this error: /usr/local/lib/node_modules/homebridge-automation-chromecast/node_modules/mdns/build/Release/dns_sd_bindings.node: invalid ELF header

homebridge doesn't run because of that error.

Impossible to install

Hi, I am having problem installing this plugin with homebridge


> [email protected] install /usr/lib/node_modules/homebridge-automation-chromecast/node_modules/mdns
> node-gyp rebuild

make: Entering directory '/usr/lib/node_modules/homebridge-automation-chromecast/node_modules/mdns/build'
  CXX(target) Release/obj.target/dns_sd_bindings/src/dns_sd.o
In file included from ../src/dns_sd.cpp:1:
../src/mdns.hpp:32:10: fatal error: dns_sd.h: No such file or directory
 #include <dns_sd.h>
          ^~~~~~~~~~
compilation terminated.
make: *** [dns_sd_bindings.target.mk:177: Release/obj.target/dns_sd_bindings/src/dns_sd.o] Error 1
make: Leaving directory '/usr/lib/node_modules/homebridge-automation-chromecast/node_modules/mdns/build'
gyp ERR! build error 
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/usr/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:194:23)
gyp ERR! stack     at ChildProcess.emit (events.js:315:20)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:275:12)
gyp ERR! System Linux 4.19.118-v7+
gyp ERR! command "/usr/bin/node" "/usr/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /usr/lib/node_modules/homebridge-automation-chromecast/node_modules/mdns
gyp ERR! node -v v12.18.2
gyp ERR! node-gyp -v v5.1.0
gyp ERR! not ok 
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] install: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the [email protected] install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/homebridge/.npm/_logs/2020-07-22T05_50_24_606Z-debug.log

Command failed. Please review log for details.

Homebridge crashes

Hello,
This always crashes. I am getting below error.

What may be the problem?

Error: getaddrinfo -3008
    at errnoException (/homebridge/node_modules/homebridge-automation-chromecast/node_modules/mdns/lib/resolver_sequence_tasks.js:199:11)
    at getaddrinfo_complete (/homebridge/node_modules/homebridge-automation-chromecast/node_modules/mdns/lib/resolver_sequence_tasks.js:112:10)
    at GetAddrInfoReqWrap.oncomplete (/homebridge/node_modules/homebridge-automation-chromecast/node_modules/mdns/lib/resolver_sequence_tasks.js:120:9)

Loading issue and request

Hello,

first of all, its a great plugin. Im using it with my sony ty which has chromecast built in

Issue:
I think you have forgotten "hap-nodejs" in your package.json as dependency , without hap-nodejs the plugin will not load

Request:
After turning off the tv, the sensor/switch says 'no response'. So is it possible to turn off the sensor/switch if there is no connection anymore instead of 'no response' ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.