Code Monkey home page Code Monkey logo

homebridge-cmdaccessory's Introduction

homebridge-cmdaccessory npm version

CMD Plugin for HomeBridge (API 2.0)

Based off of: homebridge-cmdswitch2

Special Thanks

Special thanks to @luisiam for cmdswitch2. It's great. This is 95% that plugin, but I met a friend who wanted certain "switches" to appear as different types of accessories.

What this plugin does

This plugin works much like [homebridge-cmdswitch2], it allows you to run Command Line Interface (CLI) commands via HomeKit. This means you can run a simple commands such as ping, shutdown, or wakeonlan just by telling Siri to do so. An example usage for this plugin would be to turn on your PS4 or HTPC, check if it’s on, and even shut it down when finished.

This plugin also adds a type property for the config.json to support a few different HAP types. At this time, the following types are supports:

  • Switch
  • Lightbulb
  • Outlet
  • LockMechanism

How this plugin works

  1. on_cmd: This is the command issued when the accessory is set to "ON" (or Locked, etc).
  2. off_cmd: This is the command issued when the accessory is turned OFF (or Unlocked, etc).
  3. state_cmd: This is the command issued when HomeBridge checks the state of the accessory.
  4. If there is no error, HomeBridge is notified that the accessory is ON (or Locked, etc).
  5. If there is an error, HomeBridge is notified that the accessory is OFF (or Unlocked, etc).

Things to know about this plugin

This plugin can only run CLI commands the same as you typing them yourself. In order to test if your on_cmd, off_cmd, or state_cmd are valid commands you need to run them from your CLI. Please keep in mind you will want to run these commands from the same user that runs (or owns) the HomeBridge service if different than your root user.

Installation

  1. Install homebridge using npm install -g homebridge.
  2. Install this plugin using npm install -g homebridge-cmdaccessory.
  3. Update your configuration file. See configuration sample below.

Configuration

Edit your config.json accordingly. Configuration sample:

"platforms": [{
   "platform": "cmdAccessory"
}]

Advanced Configuration (Optional)

This step is not required. HomeBridge with API 2.0 can handle configurations in the HomeKit app.

"platforms": [{
   		"platform": "cmdAccessory",
   		"name": "CMD Accessory",
   		"switches": [{
   				"name": "iTunes Switch Test",
   				"on_cmd": "start /B c:/start_itunes.cmd",
   				"off_cmd": "Taskkill /IM itunes.exe /F",
   				"state_cmd": "c:/itunes.cmd",
   				"polling": true,
   				"interval": 3,
   				"manufacturer": "Apple",
   				"type" : "Switch"
   			},{
   				"name": "Test Outlet",
   				"on_cmd": "start /B c:/start_itunes.cmd",
   				"off_cmd": "Taskkill /IM itunes.exe /F",
   				"state_cmd": "c:/itunes.cmd",
   				"polling": true,
   				"interval": 3,
   				"manufacturer": "Apple",
   				"type" : "Outlet"
   			},{
   				"name": "Test Lock 2",
   				"on_cmd": "start /B c:/start_itunes.cmd",
   				"off_cmd": "Taskkill /IM itunes.exe /F",
   				"state_cmd": "c:/itunes.cmd",
   				"polling": true,
   				"interval": 3,
   				"manufacturer": "Apple",
   				"type" : "LockMechanism"
   			},{
   				"name": "Test Bulb 3",
   				"on_cmd": "start /B c:/start_itunes.cmd",
   				"off_cmd": "Taskkill /IM itunes.exe /F",
   				"state_cmd": "c:/itunes.cmd",
   				"polling": true,
   				"interval": 3,
   				"manufacturer": "Apple",
   				"type" : "Lightbulb"
   			}
   		]
   	}
   ]
Fields Description Required
platform Must always be cmdSwitch2. Yes
name For logging purposes. No
switches Array of switch config (multiple accesories supported). Yes
|- name* Name of your device. Yes
|- type* Type of accessory. Yes
|- on_cmd Command to turn on your device. No
|- off_cmd Command to turn off your device. No
|- state_cmd Command to detect an ON state of your device. No
|- polling State polling (Default false). No
|- interval Polling interval in s (Default 1s). No
|- manufacturer Manufacturer of your device. No
|- model Model of your device. No
|- serial Serial number of your device. No
*Changing the switch name in config.json will create a new switch instead of renaming the existing one in HomeKit. It's strongly recommended that you rename the switch using a HomeKit app only.

homebridge-cmdaccessory's People

Contributors

entmike avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar

homebridge-cmdaccessory's Issues

Impossible to delete Homkit switch

Hello,
I uninstalled the plugin cause i didn’t need it anymore but whatever i do the switch remains in the Home app and it’s impossible to get rid of it. Do you have an hint ? Thnx.

Window covering?

Thanks for creating what looks to be the answer to some of the things I'd love to be able to do.

Looking through your code it appears to also work with a WindowCovering accessory type, but the documentation doesn't indicate this...is the code supporting WindowCovering complete?

I've tried using a type of WindowCovering, and it errors out with:

[3/26/2017, 10:58:08 AM] [CMD Platform] Service not found for undefined...
[3/26/2017, 10:57:51 AM] [CMD Platform] Initializing platform accessory 'LLR1' type 'WindowCovering'...
/usr/local/lib/node_modules/homebridge-cmdaccessory/index.js:201
var prop = this.getStatePropertyName(data.type);
^

ReferenceError: data is not defined
at cmdAccessoryPlatform.getInitState (/usr/local/lib/node_modules/homebridge-cmdaccessory/index.js:201:40)
at cmdAccessoryPlatform.addAccessory (/usr/local/lib/node_modules/homebridge-cmdaccessory/index.js:113:7)
at cmdAccessoryPlatform.didFinishLaunching (/usr/local/lib/node_modules/homebridge-cmdaccessory/index.js:38:8)
at emitNone (events.js:91:20)
at API.emit (events.js:188:7)
at Server.run (/usr/local/lib/node_modules/homebridge/lib/server.js:93:13)
at module.exports (/usr/local/lib/node_modules/homebridge/lib/cli.js:40:10)
at Object. (/usr/local/lib/node_modules/homebridge/bin/homebridge:17:22)
at Module._compile (module.js:571:32)
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.runMain (module.js:605:10)
at run (bootstrap_node.js:427:7)
at startup (bootstrap_node.js:148:9)
at bootstrap_node.js:542:3

On the next restart of homebridge I'll see:

[3/26/2017, 10:58:23 AM] [CMD Platform] Service not found for undefined...
[3/26/2017, 10:58:23 AM] [CMD Platform] Initializing platform accessory 'LLR1' type 'WindowCovering'...
/usr/local/lib/node_modules/homebridge/node_modules/hap-nodejs/lib/Accessory.js:222
throw new Error("Cannot add a bridged Accessory with the same UUID as another bridged Accessory: " + existing.UUID);
^

Error: Cannot add a bridged Accessory with the same UUID as another bridged Accessory: c28015a1-0ba2-48ad-afb6-4b044f41be69
at Bridge.Accessory.addBridgedAccessory (/usr/local/lib/node_modules/homebridge/node_modules/hap-nodejs/lib/Accessory.js:222:13)
at Bridge.Accessory.addBridgedAccessories (/usr/local/lib/node_modules/homebridge/node_modules/hap-nodejs/lib/Accessory.js:268:10)
at Server._handleRegisterPlatformAccessories (/usr/local/lib/node_modules/homebridge/lib/server.js:437:16)
at Server. (/usr/local/lib/node_modules/homebridge/lib/server.js:36:10)
at emitOne (events.js:96:13)
at API.emit (events.js:191:7)
at API.registerPlatformAccessories (/usr/local/lib/node_modules/homebridge/lib/api.js:155:8)
at cmdAccessoryPlatform.addAccessory (/usr/local/lib/node_modules/homebridge-cmdaccessory/index.js:78:12)
at cmdAccessoryPlatform.didFinishLaunching (/usr/local/lib/node_modules/homebridge-cmdaccessory/index.js:38:8)
at emitNone (events.js:91:20)
at API.emit (events.js:188:7)
at Server.run (/usr/local/lib/node_modules/homebridge/lib/server.js:93:13)
at module.exports (/usr/local/lib/node_modules/homebridge/lib/cli.js:40:10)
at Object. (/usr/local/lib/node_modules/homebridge/bin/homebridge:17:22)
at Module._compile (module.js:571:32)
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.runMain (module.js:605:10)
at run (bootstrap_node.js:427:7)
at startup (bootstrap_node.js:148:9)

The relevant section of my config is:

    {
        "platform": "cmdAccessory",
        "name": "CMD Platform",

        "switches" : [
      {
	"name": "LLR1",
	"on_cmd": "/some/command/here",
	"off_cmd": "/other/command/here",
	"type": "WindowCovering"
      }
    ]
}

Thoughts on what's going on here?

No more notifications with LockMechanism

With iOS 13, LockMechanism accessories do not trigger notifications anymore during polling.
Look like polling should only update LockCurrentState, not LockTargetState.

Works better after patching index.js to get:

cmdAccessoryPlatform.prototype.statePolling = function (name) {
	var accessory = this.accessories[name];
	var thisSwitch = accessory.context;
	var prop = this.getStatePropertyName(accessory.context.type);
	var arrProp = prop.split(",");
	var self = this;
	// Clear polling
	clearTimeout(this.polling[name]);

	this.getState(thisSwitch, function (error, state) {
		// Update state if there's no error
		if (!error && state !== thisSwitch.state) {
			thisSwitch.state = state;
			// Update only the LockCurrentState
			for (var i = 0; i < 1 /*arrProp.length*/; i++) {

Usable as Button instead of Switch?

Is it possible to use ist as Button and just run 1 Command by push this Button?

Would be Great for commands like „Reboot“ or something like this :)

config.json

Im unable to use this plugin.. get several errors. I think might be possible I misunderstood config.json structure for this plugin. Could you please plublish an entire config.json file functional.

I was using cmdswitch2, but I liked the posibility of configure in homebridge the types of accesories (this is not available on cmdsw2).

This is the functional config on cmdsw2:
{
"bridge":{
"name":"Homebridge Casa",
"username":"CC:22:3D:E3:CE:30",
"port":51925,
"pin":"031-45-154"
},
"description":"iHome",
"accessories":[

],
"rooms":[{

}],
"platforms":[
{
"platform":"cmdSwitch2",
"switches":[
{
"name":"Lampara Living",
"on_cmd":"/var/homebridge/commands/poweron.sh 16",
"off_cmd":"/var/homebridge/commands/poweroff.sh 16",
"state_cmd":"/var/homebridge/commands/status.sh 16"
}
]
}
]
}

And this is the config.json Ive tried for cmdaccessory but did't work
{
"bridge":{
"name":"Homebridge Casa",
"username":"CC:22:3D:E3:CE:30",
"port":51925,
"pin":"031-45-154"
},
"description":"iHome",
"accessories":[

],
"rooms":[{

}],
"platforms":[
{
"platform":"cmdAccessory",
"name": "CMD Accessory",
"switches":[
{
"name":"Luz Living",
"on_cmd":"/var/homebridge/commands/poweon.sh 10",
"off_cmd":"/var/homebridge/commands/poweroff.sh 10",
"state_cmd":"/var/homebridge/commands/status.sh 10",
"type":"Switch"
}

     ]
  }

]
}

Homebridge crashes every time

Everytime I got this error message after I unlock the LockMachanism:

[2018-8-25 19:04:58] Homebridge is running on port 51826.
[2018-8-25 19:05:16] [Haustür] Haustür is on.
[2018-8-25 19:05:16] [Haustür] Haustür is on.
[2018-8-25 19:06:17] [Haustür] 0
[2018-8-25 19:06:17] [Haustür] Haustür is turned off.
[2018-8-25 19:06:18] [Haustür] This probably won't work yet.
/usr/lib/node_modules/homebridge-cmdaccessory/index.js:309
				self.accessories[thisSwitch.name].getService(Service[that.config.type])
				                                                                 ^

TypeError: Cannot read property 'type' of undefined
    at Timeout._onTimeout (/usr/lib/node_modules/homebridge-cmdaccessory/index.js:309:70)
    at ontimeout (timers.js:498:11)
    at tryOnTimeout (timers.js:323:5)
    at Timer.listOnTimeout (timers.js:290:5)

This is my config.json:

{  
         "platform":"cmdAccessory",
         "name":"Haustür",
         "switches":[  
            {  
               "name":"Haustür",
               "off_cmd":"/home/pi/Haustür/haustür1.sh",
               "polling":true,
               "interval":1,
               "manufacturer":"Apple",
               "type":"LockMechanism"
            }
         ]
      },

Whats wrong?

Switch not updating state

Hey,
I’ve tried setting up cmdaccessory to control a number of accessories around my house, however, I’m having a few issues. Previously, I had my garage which is controlled by RF set up with the cmdswitch2 plugin which worked great with the omission that I was unable to change the switch type to Garage Door Opener and I was hoping that this plugin would provide that solution. I set it all up and it appeared in my home app as a garage which was great. However, the problem came that I was unable to change the state of the garage inside that app as it would appear to be loading . I believe this is because I do not have a “state_cmd" in the config.json as I am not quite sure what to put in here. I was wondering if there would be a way to omit the status check inside the config.json so it assumes the garage has changed state and not wait for confirmation. I may be completely wrong in my assumption and have come here in hopes that someone could offer me some advice/a solution. Thank you very much in advance,
Tom

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.