From e564f8a139b2ab5fcc2df5195234073045e34c08 Mon Sep 17 00:00:00 2001 From: nicobo Date: Wed, 9 Jun 2021 23:25:19 +0200 Subject: [PATCH] + on/off sync scenario --- README.md | 14 ++++++++ scripts/standby-together.js | 66 +++++++++++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+) create mode 100644 scripts/standby-together.js diff --git a/README.md b/README.md index 7c1ad12..9177246 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,20 @@ On the command line, use `-s scripts/sync-volume.js` to enable this script and u Top-level options (e.g. `--source`) and configuration file are also valid (see instructions below). +### Sync standby mode of several devices + +It sometimes happens that wirelessly-linked devices don't go to standby mode or don't awake together with the main one. +It may be a bug or a reliability issue with network protocols ; however the result is that this forces you to physically put them on/off. + +This script will automatically forces a given list of devices to power on or off following the main device power status. + +On the command line, use `-s scripts/standby-together.js` to enable this script and use the following options : +- `--conf.standby-together.source` sets the hostname or IP address of the *master* receiver +- `--conf.standby-together.target` lists the *slave* devices that will follow the master's power status. You can separate them with a space or pass the option several times. + +Top-level options (e.g. `--source`) and configuration file are also valid (see instructions below). + + ## Command line usage This program requires [Node.js](https://nodejs.org) to run. diff --git a/scripts/standby-together.js b/scripts/standby-together.js new file mode 100644 index 0000000..2c231b7 --- /dev/null +++ b/scripts/standby-together.js @@ -0,0 +1,66 @@ +const log = require('../logging'); +const YamahaYXC = require('yamaha-yxc-nodejs'); + +module.exports = class Scenario { + + /** + Expects a configuration in the form : + + { + "source": , + "target": [ ] + + E.g. { "source": "192.168.1.42", "target": [ "192.168.1.43", "192.168.1.44" ] } + */ + constructor( configuration ) { + + // Instanciates the source device and enrich with technical infos + var source = new YamahaYXC(configuration.source); + source.getDeviceInfo(). + then( result => { + source.deviceInfo = JSON.parse(result); + log.debug("Source : %s",source); + } + ); + this.source = source; + + // Instanciates the target devices + this.targets = []; + if ( Array.isArray(configuration.target) ) { + for ( var t=0 ; t we filter out those events + if ( typeof event.device_id != undefined && event.device_id != this.source.deviceInfo.device_id ) { + return; + } + + log.info("<<< Received power change event : %j", event); + + for ( var t=0 ; t>> Sending power '%s' to %s", event.main.power, this.targets[t].ip ); + // Possible values for 'power' are : 'on' or 'standby' (see https://github.com/foxthefox/yamaha-yxc-nodejs) + this.targets[t].power(event.main.power); + } + } + +}