Coder Social home page Coder Social logo

paolotremadio / homebridge-automation-chromecast-play Goto Github PK

View Code? Open in Web Editor NEW
14.0 2.0 1.0 16 KB

Play/cast audio and/or video to your Chromecast

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

homebridge-automation-chromecast-play's Introduction

Automation - Chromecast Play

Intro

This accessory will play/cast audio and/or video to your Chromecast on demand. It can be used for automation.

The list of media (audio/video) to be played must be stored on a file. The plugin will pick a random media from the file every time you turn on the switch. If you want to apply always the same, create a json file with only one media.

Media file

Example:

[
  {
    "name": "Ukulele Song",
    "url": "https://freepd.com/music/Ukulele%20Song.mp3",
    "author": {
      "name": "Rafael Krux"
    }
  },
  {
    "name": "Pond",
    "url": "https://freepd.com/music/Pond.mp3",
    "author": {
      "name": "Rafael Krux"
    },
    "mimeType": "audio/mp3",
    "streamType": "BUFFERED"
  }
]

The JSON file must contain an array of objects. Each object will be a media.

Format of each media object:

Attribute Required Description Example
name Yes The name of the media Ukulele Song
url Yes The URL of the media to be streamed https://freepd.com/music/Ukulele%20Song.mp3
author.name No (default: unknown) The name of the author of the media Rafael Krux
mimeType No (default: autodetect based on file extension) The MIME type of the file. See Chromecast supported types audio/mp3
streamType No (default: BUFFERED) The type of stream. For files, use BUFFERED, for live feeds use LIVE BUFFERED

You can find an example file in this repo under media.json. This file contains some public domain audio (but you can stream video too).

Config

Example config.json:

{
  "accessories": [
    {
      "accessory": "AutomationChromecastPlay",
      "name": "Living Room Play",
      "chromecastDeviceName": "Living Room",
      "mediaFile": "./media.json"
    }
  ]
}

This accessory will create a switch. Turning on the switch will stream the media to your Chromecast. The switch will turn off automatically after 1 second.

The switch has the following properties:

Name Description Example
Author The name of the author of the current media Rafael Krux
Media The name of the current applied media Ukulele Song
Status The current media status Playing

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 Play
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
mediaFile Yes The path of the media file (relative to the Homebridge current working directory) ./media.json

Other useful plugins

Do you want to automatically turn on the speakers when you stream some audio? Or adjust the volume of the speakers?

Check my homebridge-automation-chromecast plugin.

homebridge-automation-chromecast-play's People

Contributors

paolotremadio avatar

Stargazers

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

Watchers

 avatar  avatar

Forkers

maeberli

homebridge-automation-chromecast-play's Issues

TypeError with standard configuration

Hi all,

Facing the following issue when compiling with the basic config.json suggestion and media json file:

[06/09/2023, 14:01:18] TypeError: characteristic.internalHAPRepresentation is not a function at /var/lib/homebridge/node_modules/homebridge/node_modules/hap-nodejs/src/lib/Service.ts:962:82 at Array.map (<anonymous>) at Switch.Service.internalHAPRepresentation (/var/lib/homebridge/node_modules/homebridge/node_modules/hap-nodejs/src/lib/Service.ts:962:45) at /var/lib/homebridge/node_modules/homebridge/node_modules/hap-nodejs/src/lib/Accessory.ts:1171:54 at Array.map (<anonymous>) at Accessory.internalHAPRepresentation (/var/lib/homebridge/node_modules/homebridge/node_modules/hap-nodejs/src/lib/Accessory.ts:1171:31) at Bridge.Accessory.internalHAPRepresentation (/var/lib/homebridge/node_modules/homebridge/node_modules/hap-nodejs/src/lib/Accessory.ts:1178:36) at Bridge.<anonymous> (/var/lib/homebridge/node_modules/homebridge/node_modules/hap-nodejs/src/lib/Accessory.ts:1291:25) at step (/var/lib/homebridge/node_modules/homebridge/node_modules/tslib/tslib.js:193:27) at Object.next (/var/lib/homebridge/node_modules/homebridge/node_modules/tslib/tslib.js:174:57)

How to fix this?

Support streaming URL

Hi,

I put my streaming URL from MotionEye in the media.json file but got:
/usr/local/lib/node_modules/homebridge-automation-chromecast-play/chromecast-play.js:13 throw new Error('Mime type not supported');

Are streaming URL's not supported or have I configured the config wrong?

Also, when im trying with a mp3 file I get:
/usr/local/lib/node_modules/homebridge-automation-chromecast-play/node_modules/mdns/lib/resolver_sequence_tasks.js:199 var e = new Error(syscall + ' ' + errorno); ^
This is my media.json

{
"name": "Overvakningskamera1",
"url": "https://---------.se/test1.mp3",
"author": {
"name": "Overvakningskamera"
}
}
]

TypeError: Cannot read property 'launch' of null

Iā€™m seeing a weird problem where starting Audio casting takes down all of Homebridge. Here is the traceback:

Jan 08 16:12:16 raspberrypi homebridge[24529]: [08/01/2023, 16:12:16] TypeError: Cannot read property 'launch' of null
Jan 08 16:12:16 raspberrypi homebridge[24529]: at PlatformSender.launch (/usr/lib/node_modules/homebridge-automation-chromecast-play/node_modules/castv2-client/li
Jan 08 16:12:16 raspberrypi homebridge[24529]: at ChromecastPlay.launchPlayer (/usr/lib/node_modules/homebridge-automation-chromecast-play/chromecast-play.js:79:2
Jan 08 16:12:16 raspberrypi homebridge[24529]: at /usr/lib/node_modules/homebridge-automation-chromecast-play/chromecast-play.js:65:12
Jan 08 16:12:16 raspberrypi homebridge[24529]: at Client. (/usr/lib/node_modules/homebridge-automation-chromecast-play/node_modules/castv2-client/lib/s
Jan 08 16:12:16 raspberrypi homebridge[24529]: at Object.onceWrapper (events.js:421:28)
Jan 08 16:12:16 raspberrypi homebridge[24529]: at Client.emit (events.js:315:20)
Jan 08 16:12:16 raspberrypi homebridge[24529]: at TLSSocket. (/usr/lib/node_modules/homebridge-automation-chromecast-play/node_modules/castv2/lib/clien
Jan 08 16:12:16 raspberrypi homebridge[24529]: at Object.onceWrapper (events.js:421:28)
Jan 08 16:12:16 raspberrypi homebridge[24529]: at TLSSocket.emit (events.js:315:20)
Jan 08 16:12:16 raspberrypi homebridge[24529]: at TLSSocket.onConnectSecure (_tls_wrap.js:1522:10)
Jan 08 16:12:16 raspberrypi homebridge[24529]: at TLSSocket.emit (events.js:315:20)
Jan 08 16:12:16 raspberrypi homebridge[24529]: at TLSSocket._finishInit (_tls_wrap.js:932:8)
Jan 08 16:12:16 raspberrypi homebridge[24529]: at TLSWrap.ssl.onhandshakedone (_tls_wrap.js:706:12)

Iā€™m running version 0.0.7 of the plugin. I have not updated anything in my set up in a long time, not sure what has broken here. Any ideas?

TypeError: characteristic.internalHAPRepresentation is not a function

Hi,
Installing this pluggin it shows this error and Homebridge stops.
Can you help??
TypeError: characteristic.internalHAPRepresentation is not a function
at /usr/local/lib/node_modules/homebridge/node_modules/hap-nodejs/src/lib/Service.ts:648:82
at Array.map ()
at Switch.Service.internalHAPRepresentation (/usr/local/lib/node_modules/homebridge/node_modules/hap-nodejs/src/lib/Service.ts:648:45)
at /usr/local/lib/node_modules/homebridge/node_modules/hap-nodejs/src/lib/Accessory.ts:1097:54
at Array.map ()
at Accessory.internalHAPRepresentation (/usr/local/lib/node_modules/homebridge/node_modules/hap-nodejs/src/lib/Accessory.ts:1097:31)
at Bridge.Accessory.internalHAPRepresentation (/usr/local/lib/node_modules/homebridge/node_modules/hap-nodejs/src/lib/Accessory.ts:1104:36)
at Bridge. (/usr/local/lib/node_modules/homebridge/node_modules/hap-nodejs/src/lib/Accessory.ts:1213:25)
at step (/usr/local/lib/node_modules/homebridge/node_modules/tslib/tslib.js:143:27)
at Object.next (/usr/local/lib/node_modules/homebridge/node_modules/tslib/tslib.js:124:57)
at /usr/local/lib/node_modules/homebridge/node_modules/tslib/tslib.js:117:75
at new Promise ()
at __awaiter (/usr/local/lib/node_modules/homebridge/node_modules/tslib/tslib.js:113:16)
at Bridge.Accessory.publish (/usr/local/lib/node_modules/homebridge/node_modules/hap-nodejs/dist/lib/Accessory.js:928:38)
at BridgeService.publishBridge (/usr/local/lib/node_modules/homebridge/src/bridgeService.ts:215:17)
at Server.publishBridge (/usr/local/lib/node_modules/homebridge/src/server.ts:186:24)
at /usr/local/lib/node_modules/homebridge/src/server.ts:177:24
at Server.start (/usr/local/lib/node_modules/homebridge/src/server.ts:176:5)

Installation fails!

I rock homebridge on a synology nas - I get the following error message when I try to install. Is it a node-thingy? the way I run homebridge or? (I am not a Linux-guy at all :) )


USER: homebridge
DIR: /volume1/@appdata/homebridge
CMD: npm install -g homebridge-automation-chromecast-play@latest

npm ERR! code 1
npm ERR! path /volume1/@appdata/homebridge/lib/node_modules/homebridge-automation-chromecast-play/node_modules/mdns
npm ERR! command failed
npm ERR! command sh -c node-gyp rebuild
npm ERR! gyp info it worked if it ends with ok
npm ERR! gyp info using [email protected]
npm ERR! gyp info using [email protected] | linux | x64
npm ERR! gyp info find Python using Python version 3.8.8 found at "/usr/bin/python3.8"
npm ERR! gyp info spawn /usr/bin/python3.8
npm ERR! gyp info spawn args [
npm ERR! gyp info spawn args '/volume1/@appstore/homebridge/app/lib/node_modules/npm/node_modules/node-gyp/gyp/gyp_main.py',
npm ERR! gyp info spawn args 'binding.gyp',
npm ERR! gyp info spawn args '-f',
npm ERR! gyp info spawn args 'make',
npm ERR! gyp info spawn args '-I',
npm ERR! gyp info spawn args '/volume1/@appdata/homebridge/lib/node_modules/homebridge-automation-chromecast-play/node_modules/mdns/build/config.gypi',
npm ERR! gyp info spawn args '-I',
npm ERR! gyp info spawn args '/volume1/@appstore/homebridge/app/lib/node_modules/npm/node_modules/node-gyp/addon.gypi',
npm ERR! gyp info spawn args '-I',
npm ERR! gyp info spawn args '/var/packages/homebridge/home/.cache/node-gyp/16.13.2/include/node/common.gypi',
npm ERR! gyp info spawn args '-Dlibrary=shared_library',
npm ERR! gyp info spawn args '-Dvisibility=default',
npm ERR! gyp info spawn args '-Dnode_root_dir=/var/packages/homebridge/home/.cache/node-gyp/16.13.2',
npm ERR! gyp info spawn args '-Dnode_gyp_dir=/volume1/@appstore/homebridge/app/lib/node_modules/npm/node_modules/node-gyp',
npm ERR! gyp info spawn args '-Dnode_lib_file=/var/packages/homebridge/home/.cache/node-gyp/16.13.2/<(target_arch)/node.lib',
npm ERR! gyp info spawn args '-Dmodule_root_dir=/volume1/@appdata/homebridge/lib/node_modules/homebridge-automation-chromecast-play/node_modules/mdns',
npm ERR! gyp info spawn args '-Dnode_engine=v8',
npm ERR! gyp info spawn args '--depth=.',
npm ERR! gyp info spawn args '--no-parallel',
npm ERR! gyp info spawn args '--generator-output',
npm ERR! gyp info spawn args 'build',
npm ERR! gyp info spawn args '-Goutput_dir=.'
npm ERR! gyp info spawn args ]
npm ERR! gyp ERR! build error
npm ERR! gyp ERR! stack Error: not found: make
npm ERR! gyp ERR! stack at getNotFoundError (/volume1/@appstore/homebridge/app/lib/node_modules/npm/node_modules/which/which.js:10:17)
npm ERR! gyp ERR! stack at /volume1/@appstore/homebridge/app/lib/node_modules/npm/node_modules/which/which.js:57:18
npm ERR! gyp ERR! stack at new Promise ()
npm ERR! gyp ERR! stack at step (/volume1/@appstore/homebridge/app/lib/node_modules/npm/node_modules/which/which.js:54:21)
npm ERR! gyp ERR! stack at /volume1/@appstore/homebridge/app/lib/node_modules/npm/node_modules/which/which.js:71:22
npm ERR! gyp ERR! stack at new Promise ()
npm ERR! gyp ERR! stack at subStep (/volume1/@appstore/homebridge/app/lib/node_modules/npm/node_modules/which/which.js:69:33)
npm ERR! gyp ERR! stack at /volume1/@appstore/homebridge/app/lib/node_modules/npm/node_modules/which/which.js:80:22
npm ERR! gyp ERR! stack at /volume1/@appstore/homebridge/app/lib/node_modules/npm/node_modules/isexe/index.js:42:5
npm ERR! gyp ERR! stack at /volume1/@appstore/homebridge/app/lib/node_modules/npm/node_modules/isexe/mode.js:8:5
npm ERR! gyp ERR! System Linux 3.10.108
npm ERR! gyp ERR! command "/volume1/@appstore/homebridge/app/bin/node" "/volume1/@appstore/homebridge/app/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
npm ERR! gyp ERR! cwd /volume1/@appdata/homebridge/lib/node_modules/homebridge-automation-chromecast-play/node_modules/mdns
npm ERR! gyp ERR! node -v v16.13.2
npm ERR! gyp ERR! node-gyp -v v8.3.0
npm ERR! gyp ERR! not ok

npm ERR! A complete log of this run can be found in:
npm ERR! /var/packages/homebridge/home/.npm/_logs/2022-02-28T15_18_27_809Z-debug.log

Command failed. Please review log for details


Undefined author object throws TypeError

If the author object is not defined in the media.json file a TypeError is thrown.

[
  {
    "name": "Ukulele Song",
    "url": "https://freepd.com/music/Ukulele%20Song.mp3"
  }
]

The above JSON leads to the following error message:

[8/3/2019, 12:23:10 AM] TypeError: Cannot read property 'name' of undefined
    at AutomationChromecastPlay.playRandomMedia (/homebridge/node_modules/homebridge-automation-chromecast-play/index.js:116:44)
    at AutomationChromecastPlay.setSwitch (/homebridge/node_modules/homebridge-automation-chromecast-play/index.js:85:12)
    at Characteristic.On.emit (events.js:198:13)
    at Characteristic.On.Characteristic.setValue (/usr/local/lib/node_modules/homebridge/node_modules/hap-nodejs/lib/Characteristic.js:321:10)
    at Bridge.<anonymous> (/usr/local/lib/node_modules/homebridge/node_modules/hap-nodejs/lib/Accessory.js:882:22)
    at Array.forEach (<anonymous>)
    at Bridge.Accessory._handleSetCharacteristics (/usr/local/lib/node_modules/homebridge/node_modules/hap-nodejs/lib/Accessory.js:822:8)
    at HAPServer.emit (events.js:198:13)
    at HAPServer._handleCharacteristics (/usr/local/lib/node_modules/homebridge/node_modules/hap-nodejs/lib/HAPServer.js:974:10)
    at HAPServer.<anonymous> (/usr/local/lib/node_modules/homebridge/node_modules/hap-nodejs/lib/HAPServer.js:209:39)

An empty author object works:

[
  {
    "name": "Ukulele Song",
    "url": "https://freepd.com/music/Ukulele%20Song.mp3",
    "author": {
    }
  }
]

As the author.name attribute is not required it shouldn't be required to define an (empty) author object.

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.