Code Monkey home page Code Monkey logo

yamaha-nodejs's Introduction

Yamaha-nodejs

NPM Downloads Dependency Status

A node module to control your yamaha receiver. Tested with RX-V775, should work with all yamaha receivers with a network interface.

Install

npm install yamaha-nodejs

Example

var YamahaAPI = require("yamaha-nodejs");
var yamaha = new YamahaAPI("192.168.0.100");
yamaha.powerOn().then(function(){
	console.log("powerOn");
	yamaha.setMainInputTo("NET RADIO").then( function(){
		console.log("Switched to Net Radio");
		yamaha.selectWebRadioListItem(1).then(function(){
			console.log("Selected Favorites");
			yamaha.selectWebRadioListItem(1).then(function(){});
		});

	});
});

Prerequisites

  • To power on the yamaha, network standby has to be enabled
  • The Yamaha reveiver is stateful. Some commands only work work if the receiver is in the right state. E.g. to get web radio channels, the "NET RADIO" input has to be selected.

Methods

var yamaha = new Yamaha("192.168.0.100")
var yamaha = new Yamaha() // Auto-Discovery
yamaha.powerOff(zone) // or "System" for sytem power
yamaha.powerOn(zone)  // or "System" for sytem power
yamaha.isOn(zone)
yamaha.isOff(zone)

//Volume
yamaha.setVolumeTo(-500, zone) // Value must be divisble by 5 or value will be rejected
yamaha.volumeUp(50, zone)
yamaha.volumeDown(50, zone)
yamaha.muteOn(zone)
yamaha.muteOff(zone)

//Extended Volume Settings
yamaha.setBassTo(60)          //-60 to 60 (may depend on model)
yamaha.setTrebleTo(60)        //-60 to 60 (may depend on model)
yamaha.setSubwooferTrimTo(60) //-60 to 60 (may depend on model)
yamaha.setDialogLiftTo(5)     //0 to 5 (may depend on model)
yamaha.setDialogLevelTo(3)    //0 to 3 (may depend on model)
yamaha.YPAOVolumeOn()
yamaha.YPAOVolumeOff()
yamaha.extraBassOn()
yamaha.extraBassOff()
yamaha.adaptiveDRCOn()
yamaha.adaptiveDRCOff()

//Playback
yamaha.stop(zone)
yamaha.pause(zone)
yamaha.play(zone)
yamaha.skip(zone)
yamaha.rewind(zone)

//Remote (Case Sensitive Values)
yamaha.remoteCursor(command) // 'Up', 'Down', 'Left', 'Right', 'Return', 'Sel'
yamaha.remoteMenu(command)   // 'Option', 'Display'

//Switch Input
yamaha.setInputTo("USB", 2)
yamaha.setMainInputTo("NET RADIO")

//Party Mode
yamaha.partyModeOn()
yamaha.partyModeOff()
yamaha.partyModeUp()
yamaha.partyModeDown()

//Basic
yamaha.SendXMLToReceiver()

//Get Info
yamaha.getBasicInfo(zone).done(function(basicInfo){
    basicInfo.getVolume();
    basicInfo.isMuted();
    basicInfo.isOn();
    basicInfo.isOff();
    basicInfo.getCurrentInput();
    basicInfo.isPartyModeEnabled();
    basicInfo.isPureDirectEnabled();
    basicInfo.getBass();
    basicInfo.getTreble();
    basicInfo.getSubwooferTrim();
    basicInfo.getDialogueLift();
    basicInfo.getDialogueLevel();
		basicInfo.getZone();
    basicInfo.isYPAOVolumeEnabled();
    basicInfo.isExtraBassEnabled();
    basicInfo.isAdaptiveDRCEnabled();
})

yamaha.isHeadphoneConnected()
yamaha.getSystemConfig()
yamaha.getAvailableInputs()
yamaha.isMenuReady("NET_RADIO")

// FM Tuner
yamaha.getTunerInfo()
yamaha.getTunerPresetList()
yamaha.selectTunerPreset(1)
yamaha.selectTunerFrequency(band, frequency)

//Select Menu Items
yamaha.selectUSBListItem(1)
yamaha.selectWebRadioListItem(1)

// Single Commands, receiver has to be in the right state
yamaha.getWebRadioList()
yamaha.selectWebRadioListItem(1)

// Chained Commands, they ensure the receiver is in the right state
yamaha.switchToFavoriteNumber()
yamaha.gotoFolder('/NET_RADIO/Radio/Favorites', 'NET_RADIO')

// Find the index of a list item to select using the name of the item,
// returns -1 if not found. Will move the list page down so index will always
// between 1 and 8.
yamaha.getIndexOfMenuItem(
    await yamaha.getWebRadioList(), 
    'BBC Radio 1', 
    'NET_RADIO'
)

// Zone Commands
yamaha.getAvailableZones()
yamaha.getZoneConfig(zone)

Zones

The zone parameter is optional, you can pass a number or a string

Promises

All these methods return a promise:

yamaha.isOn().then(function(result){
	console.log("Receiver is:"+result);
})

Execute Tests

mocha mochatest.js --ip 192.168.0.25
or with autodiscovery
mocha mochatest.js

Discovery

If the IP is omitted in the constructor, the module will try to discover the yamaha ip via a SSDP call. Thanks @soef @mwittig

Changelog

0.8:

  • FIX Remove get request delays

yamaha-nodejs's People

Contributors

acdr avatar alanbacon avatar anthony-ngu avatar charlie89 avatar maxcanna avatar northernman54 avatar novagl avatar pietervisser avatar pseitz avatar soef 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  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  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

yamaha-nodejs's Issues

Yamaha AVR Discovery

I've just read your note on Discovery. I think it can be done using the Simple Service Discovery Protocol (SSDP) used as part of UPnP. I'll do a proof-of-concept implementation and will eventualy get back to you.

Tailor to multiple zones

Not sure if anyone is updating this but this plugin seems tailored to one zone as most do, but I would like it to work will more than one I am happy to do a pull request.

Yamaha amps can go upto 4 zones as far as I know. I would like the word "Main Zone" replaced everywhere with a zone variable.

If that zone is not filled out it goes to "Main Zone" otherwise it goes to "Zone 2" 3 etc.

It makes it much more usable.

Issue with OpenSSL between yams and alexandra install

Great little application which I have been able to get running with my alexa and my yamaha receiver. Note that there is an error in the package installation of OpenSSL which I was able to work around. I'm relatively new to python so I'm not sure if there is a way to update the installers to prevent it from occurring.

When you install yams the OpenSSL package that gets installed will fail with an error about an undefined environment variable.

The work around is to go into the python directory \Lib\site-packages and delete the OpenSSL and pyOpenSSL directories. You then need to use pip to reinstall the pyOpenSSL package. This resolved the issue on my machine.

There is a second issue I had with Alexandra running on my windows PC. It will attempt to parse the site certificate path from amazon and puke because the path after the server name doesn't match /echo.api/. In util.py _get_certificate() I needed to change the following line to remove the startswith statement. I printed out the path and it was correct but apparently startswith doesn't parse the path correctly. Might be a windows path issue.

# Sanity check location so we don't get some random person's cert.
if url.scheme != 'https' or \
   host not in ['s3.amazonaws.com', 's3.amazonaws.com:443'] or \
   **not path.startswith('/echo.api/'):** <- this fails
    log.error('invalid cert location %s - host %s - path %s', cert_url, host, path)
    return

Otherwise I'm digging it and was able to get everything running without too much pain for a python noob.

What does that mean?

Fatal TypeError: Cannot set property 'getVolume' of null
at enrichBasicStatus (D:\Coding\YamahaContoller\src\simpleCommands.js:359:27)
at D:\Coding\YamahaContoller\src\simpleCommands.js:350:16
at tryCatcher (D:\Coding\YamahaContoller\node_modules\bluebird\js\release\util.js:16:23)
at Promise._settlePromiseFromHandler (D:\Coding\YamahaContoller\node_modules\bluebird\js\release\promise.js:547:31)
at Promise._settlePromise (D:\Coding\YamahaContoller\node_modules\bluebird\js\release\promise.js:604:18)
at Promise._settlePromise0 (D:\Coding\YamahaContoller\node_modules\bluebird\js\release\promise.js:649:10)
at Promise._settlePromises (D:\Coding\YamahaContoller\node_modules\bluebird\js\release\promise.js:729:18)
at Promise._fulfill (D:\Coding\YamahaContoller\node_modules\bluebird\js\release\promise.js:673:18)
at Promise._resolveCallback (D:\Coding\YamahaContoller\node_modules\bluebird\js\release\promise.js:489:14)
at Promise._settlePromiseFromHandler (D:\Coding\YamahaContoller\node_modules\bluebird\js\release\promise.js:559:17)
at Promise._settlePromise (D:\Coding\YamahaContoller\node_modules\bluebird\js\release\promise.js:604:18)
at Promise._fulfillPromises (D:\Coding\YamahaContoller\node_modules\bluebird\js\release\promise.js:704:14)
at Promise._settlePromises (D:\Coding\YamahaContoller\node_modules\bluebird\js\release\promise.js:730:18)
at Promise._fulfill (D:\Coding\YamahaContoller\node_modules\bluebird\js\release\promise.js:673:18)
at Promise._resolveCallback (D:\Coding\YamahaContoller\node_modules\bluebird\js\release\promise.js:466:57)
at Promise._settlePromiseFromHandler (D:\Coding\YamahaContoller\node_modules\bluebird\js\release\promise.js:559:17)

delay is inserted regardless of PUT or GET

The logic below is flawed. isPutCommand always evaluates to true and the delay is always present even on GET.

var isPutCommand = xml.indexOf("cmd="PUT"" >= 0);
var delay = isPutCommand ? this.responseDelay * 1000 : 0;

Can we make PRs that use http requests?

There is a certain feature I wanted to make a PR for, but the feature only works over HTTP, and not with the XML interface.

Can you see a problem with this? Are you trying to support devices that don't support the JSON API?

Handle request timeout error

Hi, I succeed to create my own web app using your api. It's my first nodejs application.
I have one problem: from time to time my wireless network break, and in this case
Yamaha.prototype.SendXMLToReceiver method throw and timeout error, that cause my nodejs app to crash. I tried a lot of method to avoid app exit, without success.
Can you you help me?
Thx.

Integration with homebridge

Hi,
I use homebridge https://github.com/nfarina/homebridge to control my Nest thermostat and also have the homebridge-yamaha https://github.com/neonightmare/homebridge-yamaha plugin working.

The problem is that the homebridge-yamaha plugin only supports basic commands (on/off and source on zone1) but I need it to support multi-zone, volume and source and it needs to work with homekit.

I'm not sure what I can do to help (i'm not a developer) but I think the options are:

  1. further development of homebridge-yamaha to implement some of the functionality of yamaha-nodejs
  2. development of yamaha-nodejs to interact with homebridge

I would like to know if there are other options and to understand the best (and easiest) way to progress this.

Any help or advice greatly appreciated.

Scene Feature suggestion.

Hi ๐Ÿ‘‹

I'm working on homebridge-yamaha-home plugin.
I've added scenes as inputs there.
That plugin fully depends on yamaha-nodejs.

But I have found that there is no method to obtain scene information (at least scene name).
I have found some TCP commands in YNCA protocol, for example @main:SCENENAME=?

What I'm trying to do is to convert it into xml request, and add new method to yamaha-nodejs functionality which can obtain information about scene.

But I'm not sure that I'm doing it in the right way.

May I ask for a bit of advice here? Thanks!

Can't import the module

I cloned to my local machine. Just try to run the test.js by typing
node test.js

Got the following errors:
simpleCommands.js:14
return this.getOrDiscoverIP().then(ip => {
^^
SyntaxError: Unexpected token =>
at exports.runInThisContext (vm.js:73:16)
at Module._compile (module.js:443:25)
at Object.Module._extensions..js (module.js:478:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Module.require (module.js:365:17)
at require (module.js:384:17)
at Object. (/Users/andysio/workspace/test/yamaha.js:1:84)
at Module._compile (module.js:460:26)
at Object.Module._extensions..js (module.js:478:10)

Now, I have tried to install from npm npm install yamaha-nodejs. Run the test and it worked fine. What's the difference with the files comparing to one in npm?

Extracting the ID or ULR of an Album_Art

Hi PSeitz,

thank you for creating this piece of code. I'm trying to use it for creating a driver for my NEEO remote.

Can you please add some commands for extracting info about the playback?

The Request for this would be:
<YAMAHA_AV cmd="GET"><SERVER><Play_Info>GetParam</Play_Info></SERVER></YAMAHA_AV>

Response is then for example:
<YAMAHA_AV rsp="GET" RC="0"><SERVER><Play_Info><Feature_Availability>Ready</Feature_Availability><Playback_Info>Play</Playback_Info><Play_Mode><Repeat>One</Repeat><Shuffle>Off</Shuffle></Play_Mode><Time><Elapsed>1:26</Elapsed></Time><Meta_Info><Artist>A.A. Milne read by Alan Bennett</Artist><Album>Winnie the Pooh</Album><Song>Eeyore, The Old Grey Donkey...</Song></Meta_Info><Album_ART><URL>/YamahaRemoteControl/AlbumART/AlbumART6475.jpg</URL><ID>64752</ID><Format>JPEG</Format></Album_ART></Play_Info></SERVER></YAMAHA_AV>

I would love to integrate the Album_ART into my project so i need the ID or URL of the Album_Art that is played back.

Can you please help to extract this information? I have a very basic knowledge of coding so help would be really appreciated.

NPM version doesn't match GitHub

@PSeitz I got a couple of bug reports and found that the version of the package on NPM doesn't match GitHub. I think you need to publish in NPM.

Github has this on line 346 basicStatus.getZone = function() {

And NPM has this on 346 basicStatus.isOff = function() {

I think a NPM push is needed

Zone B Control

I am using a RX-V577, which has a Zone B within the Main Zone. Would it be possible to control the Zone B power and volume using this module? (Zone B doesn't have it's own source, but allows for separate volume and power control)

Offical API found

Hi guys,

I found your Project while searching for a possibility to Control The Yamaha Music cast System in combination with my Smart Home implementation.
Very nice coding and excellent work!
I recently found the Official API on a Forum and like to Share it with You since You probably might be interested in it.
It also includes the necessary Http calls for linking devices together which might be very useful in this project as well:
Basic API: https://community-openhab-org.s3-eu-central-1.amazonaws.com/original/2X/9/931ea88e30cf0f05fcdee79816eb4d3f12dd4d70.pdf
Advanced API (eg linking devices): https://community-openhab-org.s3-eu-central-1.amazonaws.com/original/2X/f/f788d96dc1d4c3caaadd4eb1d87457c0b253d7f2.pdf

How to figure out the RC-Codes?

In the simpleCommands.js there is a function sendRCode which in theory allows me to send codes to the receiver which are then processed as if the corresponding button on the remote was pressed. There are various formats presented in the comments and I already figured out which one is the right for my receiver. But how do I figure out the codes now? I tried 7C80 (which is presented as an example in the comments to simulate the power button) but the receiver responded with an error. I then tested 5EA1CE30 which is what I recorded with lirc a while ago for the button HDMI6 (still have all the codes for lirc in a file) and the receiver no longer responded with an error, but it also didn't do nothing at all. The response looked ok though (RC="0"). So the format lirc is using seems to be correct, but still those codes are not 100% correct.

This is the command I send to the receiver as a test which should simulate a press of the HDMI6 button:
<YAMAHA_AV cmd="PUT"><System><Misc><Remote_Signal><Receive><Code>5EA1CE30</Code></Receive></Remote_Signal></Misc></System></YAMAHA_AV>

The response is:
<YAMAHA_AV rsp="PUT" RC="0"><System><Misc><Remote_Signal><Receive></Receive></Remote_Signal></Misc></System></YAMAHA_AV>

I already searched google for a reference sheet for my receiver since the "RX AX10 VX71 Series Function Tree.xls" explicitly states that these codes are provided seperately from that file.

There are some header infos in the lirc remote file, maybe I need to add some of this as well? I attached the lirc remote file so you can have a look at it:
Yamaha.txt

Edit: The Receiver is a Yamaha RX-V477

Error: socket hang up

Hitting an error based on some weird network condition, but I'm not sure how to catch this since it's asynchronous:

/usr/local/lib/node_modules/homebridge-yamaha/node_modules/yamaha-nodejs/node_modules/deferred/_ext.js:75
                        throw this.value;
                                  ^
Error: socket hang up
    at createHangUpError (_http_client.js:215:15)
    at Socket.socketOnEnd (_http_client.js:300:23)
    at Socket.emit (events.js:129:20)
    at _stream_readable.js:908:16
    at process._tickCallback (node.js:355:11)

You can see the downstream code here; it's possible that it's not defining an error callback in some case and that could be the problem...do you know if this should be properly caught if an error callback is always provided? Or is this something that needs to be (or can't easily be) caught at the yamaha-nodejs level?

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.