Giter Club home page Giter Club logo

homebridge-cmd4's Introduction

npm npm

Homebridges-cmd4 - CMD4 Plugin for Homebridge - Supports ~All Accessory Types and now all Characteristics, Custom Characteristics and Priority Queued Polling too!!



    Cmd4 is a plugin for Homebridge that lets you see what Homebridge and Homekit are all about, without actually owning a single accessory! For the more advanced user, Cmd4 brings CLI support for all device types (Accessories) and characteristics.

Homebridge UI User. Do not click on any inline links. Homebridge UI does not supprt them. Bug#1098



Table of Contents



About the Cmd4 Plugin

    This plugin allows you to see what Homebridge is all about, without having any home control accessories. If you can run Homebridge and install this plugin, all the possible accessories are now available to you within HomeKit or Eve. (Except Camera Streaming).

    Similar to other command plugins, you can use Cmd4 to execute command line interface (CLI) scripts, but with Cmd4 the devices don't just appear in HomeKit as a Switch or a Light, but now they can appear as a Garage Door opener, Air Purifier ... and you can control all of their characteristics too.



How the Cmd4 Plugin Works

    Cmd4 comes with a fully populated and documented config.json file that is set to using just the cached entry's in the config file itself. This makes HomeKit behave as if you actually have all these Accessories! If you choose to add in your own scripts, the Cmd4 Github pages at http://ztalbot2000.github.io/homebridge-cmd4 have example script templates and further development instructions.



Features

    Cmd4 supports, Lights, Garage Door Openers, Outlets, Switches, Lock Maintenance Systems, Lock Management Systems, Humidity Sensors, Doors, Light Sensors, Temperature Sensors, Contact Sensors, Motion Sensors, Thermostats, Security Systems, Battery Services, Filter Maintenance Systems, Air Purifiers, Television, Television Speaker, Input Sources, Irrigation Systems, ... everything but Camera Streaming since it is not pliable to a command line Interface.

    Cmd4 Polling is a way to in the background update the state of devices via the 'polling' dirctive.

  • "polling": "on" - Implements polling of the default characteristics of the defined "timeout" and "stateChangeResponseTime".
  • "polling": [{ "characteristic": "", [ "timeout": , "stateChangeResponseTime": ] }] - implements per characteristic polling.

    Cmd4 supports Fakegato History and retaining previous state over restarts.

    Since version 2.0 Cmd4 has supported linked Accessories and the latest 3.0 Version supports both Platform plugin and Accessory plugin configurations as documented on developers.homebridge.io.

    Cmd4 Version 3.5 adds in support for Custom Characteristics.

    Cmd4 Version 3.6 allows you to configure Priority Queued Polling so that the accessory only receives one request at a time; with priority to all IOS requests first and polling second.



Screenshots



Installation Details

Step 1. Install Homebridge

See homebridge for complete details.

Step 2. Install Cmd4 Plugin

   *SHELL*> sudo npm install -g --unsafe-perm homebridge-cmd4

Step 3. Install/Update your config.json file

    Use the provided config.json file or add it to your own.

   *SHELL*> cp /usr/local/lib/node_modules/homebridge-cmd4/Extras/config.json $HOME/.homebridge/

Step 4. Restart homebridge

See homebridge for complete details.

Step 5. Try Homekit

    If you are not already familiar with Homekit, you may wish to look at the documentation for Homebridge and how to configure it with Homekit. The gist of it is that you enter the manual code defined in the config.json file. I chose 5555555 for simplicity.

That's it! Enjoy all your new Virtual Accessories!. ✅



Demo Mode

    The config.json provided has no polling defined. Demo mode is achieved when no polling of any kind for that accessory is defined. In this way all values are retrieved and set from cache.



Basic Troubleshooting

Error: Command failed

    This error is indicative to many situations. The most common is that the command took to long to run.

  Error: Command failed: /homebridge/Server.sh Get 'Server' 'On'

    at ChildProcess.exithandler (child_process.js:297:12)
    at ChildProcess.emit (events.js:193:13)
    at maybeClose (internal/child_process.js:1001:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:266:5)
  killed: true
  code: null
  signal: SIGTERM,
  cmd: "/homebridge/Server.sh Get Server On"

Check that the command exists, but also that the timeout value in your config.json for that accessory is not too low.

Debug Steps

New in Cmd4 v4.0.0 is how to enable Debug mode. The logs are 100% the same, except that now that Cmd4 has its own logging system ( Copied from Homebridge for compatability ); Enabling Debug logs will not enable Debug logs in other plugins.
There are two ways to enable Cmd4 Debug logs.

Method 1. Modifying the Cmd4 Platform section

    The Cmd4 Platform section can contain the enable Debug directive.

   {
      "platform": "Cmd4",
      "name": "Cmd4",
      "debug": true
   }

Method 2. Add DEBUG environental variable

   *SHELL*> DEBUG=Cmd4

Note: For Homebridge-config-ui-x, you only need to write Cmd4 in the Environmental variable section.



Rationale

    After playing with homebridge-cmd and then homebridge-cmdswitch2, I really wanted to control as much as I could. I did not have all the devices, but I did have a light and a Sony Android TV. I wanted to control these and see what else I could do.
    If you were wondering what happened to version 3, well I learned a lot, hence the working cmd4.



Todo

  • Become Homebridge Certified. ( The schema file for Homebridg-ui would be very difficult )



Contributing

    Best ways to contribute

Promotion

    Like the project? Please support to ensure continued development going forward:

  • Star this repo on [GitHub][homebridge-cmd4-repo]
  • Follow the repo on [GitHub][homebridge-cmd4-repo]
  • Follow me



Inspiration and special thanks

Based on the best of:



License

See LICENSE

homebridge-cmd4's People

Contributors

caseyro avatar ibmr avatar michlw avatar mitch7391 avatar nano9g avatar ztalbot2000 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

homebridge-cmd4's Issues

No support for decimal temperatures.

iOS 12 adds support for viewing decimal temperatures in Home. When I pass a decimal temperature to a cmd4 accessory it always rounds down. For reference, homebridge-dht22 does not round and shows decimal temperatures in Home.

Television

Hi trying to add tv to the plugin just need on, off , state , through url or curl
Thanks

No update while in background.

Hi,
GREAT PLUGIN!!! Thank you!
I have only one problem,
when I update a status,
for example the status of my door with the

/usr/local/bin/node /Users/user01/.homebridge/Cmd4Scripts/State.js Set Door TargetPosition 100

it work well but I have to open the Home App on my iPhone to update the door status.

So in this way a never have the alert.

Is my config problem or some bug?

Thank you!!

Delay after changing characteristics

Hi there,

I noticed a short delay after e.g. switching on/off a switch. The HomeKit app shows a small rotating gear after pressing the button and Siri says something like "checking your home ..." after performing an action. The action is executed nearly instant tho. It's just like the homebridge/cmd4 takes some time to report the result back to the HomeKit app.

Did not have this behavior with the cmdswitch2 plugin which I used before changing to cmd4. The initial status check after opening the HomeKit app takes longer as well.

Is there anything I can do about that?

Best regards

Ability to run PowerShell commands?

Does this plugin allow us to run PowerShell commands? I have homebridge installed on both Windows and Ubuntu. Both support PowerShell. Is there a way to run PowerShell commands/scripts allowing me to control different things?

Switch no longer working

Cmd4 Warning: Unknown characteritic 'On' to update for accessory 'Server'

That's the error spammed in log. This was working up til about a couple weeks ago. I didnt change anything so i can only assume an update broke it.

config.json

       {
            "platform": "Cmd4",
            "name": "Cmd4",
            "accessories": [
                {
                    "type": "Switch",
                    "name": "Server",
                    "on": false,
                    "state_cmd": "sh /homebridge/Server.sh",
                    "polling": true,
                    "interval": 5,
                    "timeout": 2000
                }
            ]
        }

Server.sh

#!/bin/sh

if [ "$1" = "Get" ]; then
   # $2 would be the name 'PS4'
   # $3 would be the charactersistic 'On'
   ping -c 2 -W 1 192.168.1.90 | grep -i '2 packets received' >> /dev/null
   rc=$?
   if [ "$rc" = "0" ]; then
      echo "1"
      exit 0
   else
      echo "0"
      exit 0
   fi
fi

if [ "$1" = "Set" ]; then
   # $2 would be the name 'PS4'
   # $3 would be the the charactersistic 'On'
   # $4 would be '0' for 'On' and '1' for 'Off'

   if [ "$4" = "true" ]; then
      curl localhost:3001/api/commands/run/server_on
      exit $?
   fi
   if [ "$4" = "false" ]; then
      curl localhost:3001/api/commands/run/server_off
      exit $?
   fi
fi

exit -1

How to use the television?

How do i use the television? I want to be able to switch inputs and turn it on and off with an command.

Non Virtual usage?

I would like to use this plugin for controlling different switches and Devices with the Shell...all Scripts i used previusly with the cmdswitch2 Plugin...this plugin is interesting because i can choose from a huge number of differend characterristics and Device Types...but how i can actually Control a real Device with this plugin? Like with the cmd_on and cmd_off Argument...?

Try to find a way to get rid of the underscores in device names if possible

Hi, I have to say I haven't had a close enough look yet to tell if you have, but...

  • Did you get a chance to see if you can escape the spaces with backslashes?
  • Maybe even extract them afterwards if necessary?
  • Is there any way you can replace the spaces with underscores before proceeding to use it in variable names, or anywhere throughout the code?
  • Could you maybe introduce a new unique identifier field to use around the rest of the code?

So that the user can still pick the same type of device name they'd choose with regular homekit devices. Because imho the requirement of underscores in device names is a very unfortunate shortcoming, given the fact that the overall features in this project seem very promising.

Does not support carbonDioxideLevel of CarbonDioxideSensor?

CarbonDioxideDetected works in my Home.app, but carbonDioxideLevel are not displayed.
Am I wrong?

2019-06-05 23 35 47

This is part of a config.txt.

{
  "type": "CarbonDioxideSensor",
  "name": "CO2",
  "carbonDioxideDetected": 0,
  "carbonDioxideLevel": 0,
  "polling": false,
  "interval": 540,
  "stateChangeResponseTime": 3,
  "state_cmd": "ruby ~/.homebridge/cmd4.rb"
},

This is part of a ruby script.

mode, acs_name, chara, value = ARGV
case acs_name
when "CO2"  
  field = "co2"
  ppm = current_value(field,location)
  case chara
  when "CarbonDioxideDetected"
    puts ppm > 1000 ? 1 : 0
  when "CarbonDioxideLevel"
    puts ppm
  end
  exit

Thank you for the great repository!

On/Off action

Hi there!

I really appreciate the work you've put into this plugin as it's made adding different types of accessories far easier and customisable. However, I'm having one slight problem which I'm hoping you could help me out with. I've managed to add a number of accessories to my home app which is great but where in the config.json file I've put both an "on_cmd": "<executable>" and an "off_cmd": "<executable>" with <executable> being the command I wish the accessory to carry out but so far this does nothing. Despite the fact that when I click the accessory in the app and it correctly changes state to show either on or off, it does not actually carry out the respective command.
I apologise if the solution is glaringly obvious but would really appreciate it if someone could point me in the right direction to have the accessory actually carry out a command.

Thank you in advance,
Tom

Motion Sensor notification

Hi, I added some motion sensors and enable notifications for them. They work if the Home app is open, because when I open the app all the sensors are updated. How can I automatically update the added motion sensor with cmd4 in the background so that I always receive notifications?

"No Response" in Home whenever I add polling to config.json

I get a "No Response" error in the Home app whenever I add polling to my config.json for either a door or a motinon sensor.

I've implemented polling on a Door as it is outlined in the Cmd4 Extras config.json:

{
   "type": "Door",
   "name": "My_Door",
   "currentPosition": 0,
   "targetPosition": 0,
   "positionState": 0,
   "polling": [{"statusActive":   1, "interval": 80, "timeout":1000},
               {"statusFault" : 10, "interval": 50, "timeout":2000}
              ],
   "stateChangeResponseTime": 3,
   "state_cmd": "python ~/.homebridge/Cmd4Scripts/back_door_state.py"
}

It works just fine without polling. But whenever I add polling it breaks.

Here's the homebridge log for when I add polling...seems like the script fails to execute whenever I add polling, but this same error isn't present when I remove polling:

0|homebridge  | [5/7/2019, 9:57:44 AM] [Cmd4] getGeneric TargetPosition function for: Back Door cmd: python ~/.homebridge/Cmd4Scripts/back_door_state.py Get 'Back Door' 'TargetPosition' failed.
0|homebridge  | [5/7/2019, 9:57:44 AM] [Cmd4] { Error: Command failed: python ~/.homebridge/Cmd4Scripts/back_door_state.py Get 'Back Door' 'TargetPosition'
0|homebridge  |     at ChildProcess.exithandler (child_process.js:294:12)
0|homebridge  |     at ChildProcess.emit (events.js:189:13)
0|homebridge  |     at maybeClose (internal/child_process.js:970:16)
0|homebridge  |     at Process.ChildProcess._handle.onexit (internal/child_process.js:259:5)
0|homebridge  |   killed: true,
0|homebridge  |   code: null,
0|homebridge  |   signal: 'SIGTERM',
0|homebridge  |   cmd:
0|homebridge  |    'python ~/.homebridge/Cmd4Scripts/back_door_state.py Get \'Back Door\' \'TargetPosition\'' }
0|homebridge  | [5/7/2019, 9:57:44 AM] [Cmd4]
0|homebridge  | [5/7/2019, 9:57:44 AM] [Cmd4]
0|homebridge  | [5/7/2019, 9:57:44 AM] [Cmd4] getGeneric CurrentPosition function for: Back Door cmd: python ~/.homebridge/Cmd4Scripts/back_door_state.py Get 'Back Door' 'CurrentPosition' failed.
0|homebridge  | [5/7/2019, 9:57:44 AM] [Cmd4] { Error: Command failed: python ~/.homebridge/Cmd4Scripts/back_door_state.py Get 'Back Door' 'CurrentPosition'
0|homebridge  |     at ChildProcess.exithandler (child_process.js:294:12)
0|homebridge  |     at ChildProcess.emit (events.js:189:13)
0|homebridge  |     at maybeClose (internal/child_process.js:970:16)
0|homebridge  |     at Process.ChildProcess._handle.onexit (internal/child_process.js:259:5)
0|homebridge  |   killed: true,
0|homebridge  |   code: null,
0|homebridge  |   signal: 'SIGTERM',
0|homebridge  |   cmd:
0|homebridge  |    'python ~/.homebridge/Cmd4Scripts/back_door_state.py Get \'Back Door\' \'CurrentPosition\'' }
0|homebridge  | [5/7/2019, 9:57:44 AM] [Cmd4]
0|homebridge  | [5/7/2019, 9:57:44 AM] [Cmd4]

How to use the TLV8 characteristics within Television accessory?

Could someone please give me a hint how to use the TLV8 characteristics within the Television accessory? I have a Grundig TV with a single HDMI input from a Raspberry Pi running Kodi (passed through a denon receiver).

RasPi --(HDMI)--> Denon --(HDMI)--> TV

With this awesome homebridge plugin I have already implemented the following using only one Television accessory:

  • Control the power state of my TV using HDMI CEC commands send from the Raspberry Pi
  • Choose the audio input of my Denon receiver (Kodi or Apple AirPlay) using HTTP with curl
  • Read out the actual input source of my Denon Receiver using HTTP with curl

Now I try to implement the functionality of the iOS built in Remote App to control my Kodi on Raspberry Pi for:

  • currentMediaState and targetMediaState
  • remoteKey PLAY, PAUSE, UP, DOWN, ...

My problem is, that I do not understand how to activate/enable the TLV8 options. What does the "... unless 'allowTLV8' is set, at your own peril." mean? I used it in config.json within my Television accessory but nothing happens.

I hope someone can point me in the right direction.

Thanks in advance.
Michael

Homebridge 1.0.4 compatible?

Raspberry Pi 3, debian 10.0

I get errors after migrating to homebridge 1.0.4. Most other plugins still work, cmd4 fails when launching any of my scripts, e.g.

[06/05/2020, 17:14:28] [Cmd4] getGeneric On function for:Alarm cmd:node /var/homebridge/Cmd4Scripts/Alarm.js Get 'Alarm' 'On' failed.
[06/05/2020, 17:14:28] [Cmd4] { Error: Command failed: node /var/homebridge/Cmd4Scripts/Alarm.js Get 'Alarm' 'On'

    at ChildProcess.exithandler (child_process.js:294:12)
    at ChildProcess.emit (events.js:198:13)
    at maybeClose (internal/child_process.js:982:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:259:5)
  killed: true,
  code: null,
  signal: 'SIGTERM',
  cmd:
   'node /var/homebridge/Cmd4Scripts/Alarm.js Get \'Alarm\' \'On\'' }

negative temperatures not showing in TemperatureSensor

is there a way to set the range of temperatures in a temperature sensor? right now on my HomeKit app it clamps between 32 and 212 when I see the temperature sensor in the iOS app, even though I'm sending back negative floating point values for "CurrentTemperature" requests.

I'm actually using the temperature sensor for another purpose, it's a power meter for my electric vehicle charger. it seems to be the best sensor for the purpose (just to report a floating point value so I can see how much power the EV is pulling when it is plugged in)

version check error causes homebridge instance to exit

the plugin worked well for me until I restart homebridge and could not get it run again. Found this in the log:

SyntaxError: Unexpected token A in JSON at position 0 Oct 10 10:46:42 raspberrypi homebridge[27444]: at JSON.parse (:null:null) Oct 10 10:46:42 raspberrypi homebridge[27444]: at IncomingMessage.res.on (/var/homebridge/node_modules/homebridge-cmd4/node_modules/github-version-checker/lib/check.js:64:21)

I had to downgrade to version 2.1 and it works well

[Cmd4] Warning, Retrieving On, expected only one word value for:

Hi,

Thank you for the great effort you put in to build the CMD4 accessory. I would appreciate your feedback on the following error I am receiving.

On and OFF states/ commands execute fine however, the status is not cooperating. At pooling time, I am getting the warning message below and the switch turns OFF

[4/9/2020, 10:49:25 AM] [Cmd4] Warning, Retrieving On, expected only one word value for:TV, using first of:2 packets transmitted, 2 received, 0% packet loss, time 17ms
true

I have tried a lot of iteration to get the status of the device but all give me same results.

ps4-waker search | grep -i '200 Ok'

sudo ps4-waker search -d 192.168.50.25 | grep "200 Ok" > null && (echo "true") || (echo "false")

Get current state of MAC address (Is device ON or OFF?)

Ping media server player if it is ON

If the host is up, you should see something like "1 packets transmitted, 1 received, 0% packet loss

###    Homebridge-cmd4 will interpret the result of false to be 1 
###    and true to be 0 so either 0/1  or true/false can be returned.

ping -c 1 -W 1 192.168.1.55 | grep -i '1 received'

ping -c 2 -W 1 192.168.1.110 | grep -i '2 received'

ping -c 2 -W 1 192.168.1.110 | grep -i '2 received' > null && (echo "true") || (echo "false")

ping -c 2 -W 1 192.168.1.110 | grep -i '2 received' > null && (echo "true") || (echo "false") >> /dev/null

curl -s GET '192.168.1.55' | grep -i '0'

My current switch bash script is as following:

#!/bin/bash

Notes

1) This script is called as defined by the config.json file as:

"state_cmd": "bash .homebridge/Cmd4Scripts/PS4.sh"

$1 = 'Get'

$2 = DO NOT USE SPACES IN DEVICE NAME. It causes problems parsing the command line.

$3 =

$4 =

2) For a set of On, the command issued would be:

bash $HOME/.homebridge/Cmd4Scripts/PS4.sh Set PS_4 On false

or

bash $HOME/.homebridge/Cmd4Scripts/PS4.sh Set PS_4 On true

3) For a Get of On, the command issued would be:

bash $HOME/.homebridge/Cmd4Scripts/PS4.sh Get PS_4 On

Homebridge-cmd4 will interpret the result of false to be 1

and true to be 0 so either 0/1 or true/false can be returned.

echo "$1='$1' $2='$2' $3='$3' $4='$4'"

This is only here for the first run.

if [ ! -f "/tmp/fileVariableHolder" ]; then
echo "0" > "/tmp/fileVariableHolder"
fi

if [ "$1" = "Get" ]; then

This line is commented out and would be

interchangeable with ps4-waker. It is here

as an example

ps4-waker search | grep -i '200 Ok'

ping -c 2 -W 1 192.168.1.110 | grep -i '2 received'
cat /tmp/fileVariableHolder
rc=$?
if [ "$rc" = "0" ]; then
exit 0
else
echo "failed"
exit -1
fi
fi

.
.
.

Much appreciated

Temperature from DHT22

I'm trying to use the thermostat accesory with data from a DHT22, what have to change into the code?

Unable to run .sh file

Hi,

I want to run a .sh file, but I always get this error:

Apr 06 01:34:31 raspberrypi homebridge[6956]: [2019-4-6 01:34:31] [Cmd4] Cmd4 getGeneric On function for: PiHole cmd: bash /var/homebridge/cmd4/pihole.sh Get 'PiHole' 'On' failed.
Apr 06 01:34:31 raspberrypi homebridge[6956]: [2019-4-6 01:34:31] [Cmd4] { Error: Command failed: bash /var/homebridge/cmd4/pihole.sh Get 'PiHole' 'On'
Apr 06 01:34:31 raspberrypi homebridge[6956]: /var/homebridge/cmd4/pihole.sh: Zeile 7: Syntaxfehler beim unerwarteten Wort newline' Apr 06 01:34:31 raspberrypi homebridge[6956]: /var/homebridge/cmd4/pihole.sh: Zeile 7: '
Apr 06 01:34:31 raspberrypi homebridge[6956]: at ChildProcess.exithandler (child_process.js:281:12)
Apr 06 01:34:31 raspberrypi homebridge[6956]: at emitTwo (events.js:126:13)
Apr 06 01:34:31 raspberrypi homebridge[6956]: at ChildProcess.emit (events.js:214:7)
Apr 06 01:34:31 raspberrypi homebridge[6956]: at maybeClose (internal/child_process.js:915:16)
Apr 06 01:34:31 raspberrypi homebridge[6956]: at Socket.stream.socket.on (internal/child_process.js:336:11)
Apr 06 01:34:31 raspberrypi homebridge[6956]: at emitOne (events.js:116:13)
Apr 06 01:34:31 raspberrypi homebridge[6956]: at Socket.emit (events.js:211:7)
Apr 06 01:34:31 raspberrypi homebridge[6956]: at Pipe._handle.close [as _onclose] (net.js:561:12)
Apr 06 01:34:31 raspberrypi homebridge[6956]: killed: false,
Apr 06 01:34:31 raspberrypi homebridge[6956]: code: 2,
Apr 06 01:34:31 raspberrypi homebridge[6956]: signal: null,
Apr 06 01:34:31 raspberrypi homebridge[6956]: cmd: 'bash /var/homebridge/cmd4/pihole.sh Get 'PiHole' 'On'' }
Apr 06 01:34:31 raspberrypi homebridge[6956]: [2019-4-6 01:34:31] [Cmd4]
Apr 06 01:34:31 raspberrypi homebridge[6956]: [2019-4-6 01:34:31] [Cmd4] /var/homebridge/cmd4/pihole.sh: Zeile 7: Syntaxfehler beim unerwarteten Wort newline' Apr 06 01:34:31 raspberrypi homebridge[6956]: /var/homebridge/cmd4/pihole.sh: Zeile 7: '

The pihole.sh file looks like this:

#!/bin/bash

if [ "$1" = "Get" ]; then

$2 would be the name 'PiHole'

$3 would be the charactersistic 'On'

state=$(pihole status | grep -c Enabled)
if [[ "$state" = "0" ]]; then
echo "$state"
exit 0
elif [[ "$state" = "1" ]]; then
echo "$state"
exit 0
fi
fi

if [ "$1" = "Set" ]; then

$2 would be the name 'PiHole'

$3 would be the the charactersistic 'On'

$4 would be '0' for 'Off', '1' for 'On'

if [ $4 = true ]; then
pihole enable
exit $?
elif [ $4 = false ]; then
pihole disable
exit $?
fi
fi

exit -1

And my config.json looks like this:

{
"platform": "Cmd4",
"name": "Cmd4",
"accessories": [
{
"type": "Switch",
"name": "PiHole",
"on": false,
"polling": true,
"interval": 5,
"timeout": 2000,
"state_cmd": "bash /var/homebridge/cmd4/pihole.sh"
}
]
},

Does anyone see where the issue is?

Thanks in advance!

Command

Hey please could you point me in the right direction of how to add a command that would be performed when an accessory is controlled as I can't see anything about it in your README.
Thanks for your help, David

Garage Door issue

Hi,

At first I want to say thank You for this module. It's great!

I have problem with GarageDoorOpener.

Two problems:

  1. My garage doors (default closed) is saying "Opening..." after fresh Homebridge start. CurrentDoorState returning right value (1, as doors are closed). Something is wrong with TargetDoorState. Any ideas?

  2. I have another gate, that is working similar to garage doors, but is auto-closing after some interval of time. I write some bash scripts to operate this gate using Cmd4 and everything is working smooth, but after auto-closing (again, as above - CurrentDoorState returning right value - 1 - as gate is closed) gate switch to "Opening..." state.

Please, help. I'm out of ideas digging in sources and analyzing HomeKit SDK.

Thanks!

State.js errors, including ERR_INVALID_CALLBACK

Fascinating plugin! I'm keen to see if I can create some fake, triggerable Motion Sensors in order to get some push notifications.

Have installed, then installed State.js, and plucked the relevant config for the devices out of config.json. It all initialises without error, but as soon as I view anything in Home.app, homebridge try to run State.js, and fails continuously with errors like these:

[7/24/2018, 7:39:09 PM] [Cmd4] Cmd4 getGeneric On function for: My_OnOff_Light cmd: node .homebridge/Cmd4Scripts/State.js Get 'My_OnOff_Light' 'On' failed.
[7/24/2018, 7:39:09 PM] [Cmd4] { Error: Command failed: node .homebridge/Cmd4Scripts/State.js Get 'My_OnOff_Light' 'On'
internal/modules/cjs/loader.js:596
    throw err;
    ^

Error: Cannot find module '/.homebridge/Cmd4Scripts/State.js'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:594:15)
    at Function.Module._load (internal/modules/cjs/loader.js:520:25)
    at Function.Module.runMain (internal/modules/cjs/loader.js:744:10)
    at startup (internal/bootstrap/node.js:240:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:564:3)

    at ChildProcess.exithandler (child_process.js:291:12)
    at ChildProcess.emit (events.js:182:13)
    at maybeClose (internal/child_process.js:961:16)
    at Socket.stream.socket.on (internal/child_process.js:380:11)
    at Socket.emit (events.js:182:13)
    at Pipe._handle.close (net.js:595:12)
  killed: false,
  code: 1,
  signal: null,
  cmd:
   'node .homebridge/Cmd4Scripts/State.js Get \'My_OnOff_Light\' \'On\'' }
[7/24/2018, 7:39:09 PM] [Cmd4] 
[7/24/2018, 7:39:09 PM] [Cmd4] internal/modules/cjs/loader.js:596
    throw err;
    ^

Error: Cannot find module '/.homebridge/Cmd4Scripts/State.js'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:594:15)
    at Function.Module._load (internal/modules/cjs/loader.js:520:25)
    at Function.Module.runMain (internal/modules/cjs/loader.js:744:10)
    at startup (internal/bootstrap/node.js:240:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:564:3)

The error is seemingly "cannot find module". So, I tried just running State.js by itself in Terminal from the homebridge user's home directory, but I get a different error:

$ node .homebridge/Cmd4Scripts/State.js Set 'My_ContactSensor' 'ContactSensorState' 0
fs.js:141
    throw new ERR_INVALID_CALLBACK();
    ^

TypeError [ERR_INVALID_CALLBACK]: Callback must be a function
    at makeCallback (fs.js:141:11)
    at Object.mkdir (fs.js:720:16)
    at Object.<anonymous> (/Users/anyone/.homebridge/Cmd4Scripts/State.js:77:4)
    at Module._compile (internal/modules/cjs/loader.js:702:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:713:10)
    at Module.load (internal/modules/cjs/loader.js:612:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:551:12)
    at Function.Module._load (internal/modules/cjs/loader.js:543:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:744:10)
    at startup (internal/bootstrap/node.js:240:19)

Feature request: integrate fakegato-history module

First of all - HUGE thank you for this plugin!!! I successfully connected my dumb aircon wi-fi controller and Oregon BLE weather station to HomeKit using simple bash scripts

This issue is to ask you to please consider integrating support for fakegato-history to be used with temperature/humidity sensors

This module saves a log with temp/humidity values and exposes it to Eve app. The app draws very nice graphs so you can see historical values

https://www.npmjs.com/package/fakegato-history

Thank you again!

Window cover still open

Hi!

First of all, thanks for your tool.
I have a small issue. I set up two window covers but if the cover is closed or open the homekit still highlight the ikon and notify my that 2 blind are open.
Please help me...

Screenshot 2020-01-12 at 19 14 41

/usr/lib/node_modules/homebridge-cmd4/index.js:1354

/usr/lib/node_modules/homebridge-cmd4/index.js:1354
if (characteristicStrincharacteristicString == "TargetTemperature")
^

ReferenceError: characteristicStrincharacteristicString is not defined
at /usr/lib/node_modules/homebridge-cmd4/index.js:1354:19
at ChildProcess.exithandler (child_process.js:267:7)
at emitTwo (events.js:126:13)
at ChildProcess.emit (events.js:214:7)
at maybeClose (internal/child_process.js:925:16)
at Process.ChildProcess._handle.onexit (internal/child_process.js:209:5)

SyntaxError at JSON.parse (<anonymous>) in github-version-checker

SyntaxError: Unexpected token A in JSON at position 0
at JSON.parse ()
at IncomingMessage.res.on (/usr/local/lib/node_modules/homebridge-cmd4/node_modules/github-version-checker/lib/check.js:64:21)
at IncomingMessage.emit (events.js:203:15)
at endReadableNT (_stream_readable.js:1145:12)
at process._tickCallback (internal/process/next_tick.js:63:19)

When homebridge-cmd4 is installed in oznu/homebridge Docker Container i get the upper error message right after activating the first accessory. This happens nearly all the time, but in rare cases i managed to get it working, but i did not know why. My config.json is absolutely without errors.

That behavior was not the case in the past. I tried to use previous version 2.2.1 with rare success. I also tried to use newest Docker image of homebridge. Nothing helped. In the cases when it works a single restart sometimes is enough to break my installation by this error. Actually i spent hours to investigate with no success.

And finally i did not find any solution on Google.

Please help.

Testing PS4.sh

Tried setting up PS4. When testing PS4.sh using command line the device on and off code doesn't do anything. However getting the device status works.

Example with migration cmdswitch

Hello!
It's sophisticated for me to migrate from cmdswitch to your plugin.
I'm using .sh scripts in state_cmd, on_cmd and off_cmd, for example:

"on_cmd": "sudo /home/pi/on.sh MAC on",
"off_cmd":` "sudo /home/pi/off.sh MAC off",
"state_cmd": "sudo /home/pi/status.sh MAC | grep -l 'ON'"

Is it possible to link in your state_cmd my on.sh, off.sh and status.sh?
Probably you can help with solution of my problem.
Thanks in advance,
Maxim.

I am getting errors when I try to run this program

I have homebridge working and all the state.js stuff working but I am getting some errors when I run it. Here they are.

[2/24/2019, 6:06:07 PM] Loaded config.json with 1 accessories and 1 platforms.
[2/24/2019, 6:06:07 PM] ---
[2/24/2019, 6:06:07 PM] Plugin /usr/local/lib/node_modules/homebridge-cmd4 requi4.0.0. You may need to upgrade your installation of Node.
[2/24/2019, 6:06:07 PM] Loaded plugin: homebridge-cmd4
[2/24/2019, 6:06:07 PM] Registering accessory 'homebridge-cmd4.Cmd4'
[2/24/2019, 6:06:07 PM] Registering platform 'homebridge-cmd4.Cmd4'
[2/24/2019, 6:06:07 PM] ---
[2/24/2019, 6:06:07 PM] Loading 1 platforms...
[2/24/2019, 6:06:07 PM] [Cmd4] Initializing Cmd4 platform...
[2/24/2019, 6:06:07 PM] [Cmd4] Cmd4:Fetching config.json devices.
[2/24/2019, 6:06:07 PM] [Cmd4] Cmd4:Found PS4
[2/24/2019, 6:06:07 PM] [Cmd4] Initializing platform accessory 'PS4'...
[2/24/2019, 6:06:07 PM] Loading 1 accessories...
/usr/local/lib/node_modules/homebridge/lib/api.js:50
if (name.indexOf('.') == -1) {
^

TypeError: Cannot read property 'indexOf' of undefined
at API.accessory (/usr/local/lib/node_modules/homebridge/lib/api.js:50:11)
at Server.str.replace.Server._loadAccessories (/usr/local/lib/node_modules/homebridge/lib/server.js:286:42)
at Server.str.replace.Server.run (/usr/local/lib/node_modules/homebridge/lib/server.js:87:38)
at module.exports (/usr/local/lib/node_modules/homebridge/lib/cli.js:45:10)
at Object. (/usr/local/lib/node_modules/homebridge/bin/homebridge:17:22)
at Module._compile (module.js:434:26)
at Object.Module._extensions..js (module.js:452:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Function.Module.runMain (module.js:475:10)

I dont know how to fix it. Please help.

Telnet also?

Will this plugin work with telnet commands? Many thanks!

Homebridge dependency warning

Hi there,

We've noticed your plugin is using homebridge as a prod-dependency.

Homebridge should only be included in plugins as a dev-dependency and used for TypeScript types.

In the next release of we are changing Homebridge to only export types and const enums which can be safely used in your code and not result in Homebridge becoming a runtime dependency.

You can test this out using the current beta of Homebridge:

npm install --save-dev homebridge@beta

Fan Accessory Question

Hi, I was wondering if any of the fan accessories in cmd4 accommodate a fan that has speeds low, medium high and auto? I have not been able to find out whether Homekit itself allows this, so no doubt it is a limitation of Homekit if anything :) If so can you show me how the config would differ from the example already in your sample config? Thanks in advance :)

Where to put State.js when running Homebridge as systemd service?

Hey,

first of all thanks for this great plugin!

Sadly I'm kinda stuck at the moment... in your readme you said I'd have to put the State.js file in ~/.homebridge/Cmd4Scripts but I'm running Homebridge as systemd service and my main directory (which contains the config.json etc) are located at /var/homebridge so I put my Cmd4Scripts folder with the State.js file in there... I just tested my first On/Off script but I'm not sure if it doesn't work as expected because I made a mistake in the script or if the state.js file doesn't work because it's in the right place.

I hope my question is no duplicate.

Thanks in advance,
Niko :)

Misleading example(s)

Hi there,

I just tested your plugin and got the string values true/false passed for the On characteristic instead of 0/1 like described in the README.

You might want to fix this.

Best regards

hi thermostat q

is there way for cmd4 to have thermostat accessory that has only 3 func heat cold off on http post commands ?

thanks

"No Response" in Home app

I'm trying to get a door sensor set up by using data returned from the py-august api for my August door locks. When I run the script in my shell I correctly get a 1 or 0 for open or closed state. But, when I add it to my config.json the Home app shows the device with a "No Response" error.

Here's my the portion of my config.json file for the door sensor:

   {
      "platform": "Cmd4",
      "name": "Cmd4",
      "accessories":
      [
        {
          "type": "Door",
          "name": "Front Door",
          "currentPosition": 0,
          "targetPosition": 0,
          "positionState": 0,
          "stateChangeResponseTime": 3,
          "state_cmd": "python ~/.homebridge/Cmd4Scripts/front_door_state.py"
        }
      ]
    }

Here's the python script returning the state values:

#!/home/pi/berryconda3/bin/python

import sys
from august.api import Api
from august.authenticator import (
    Authenticator, AuthenticationState, ValidationResult)
import requests


user_name = '<PHONE NUMBER>'
password = '<PASSWORD>'

use_session = True
combine_status = True

api = Api(timeout=20)
authenticator = Authenticator(api, "phone", user_name, password,
                              access_token_cache_file=".august.conf")

authentication = authenticator.authenticate()


locks = api.get_operable_locks(authentication.access_token)

front_lock_status = api.get_lock_status(authentication.access_token,'BF4F854D9E9B4786A9FA3A8833AAE09A')
front_door_status = api.get_lock_door_status(authentication.access_token,'BF4F854D9E9B4786A9FA3A8833AAE09A')

back_lock_status = api.get_lock_status(authentication.access_token,'41C161F1D5DB4C30948CE8184C8438F1')
back_door_status = api.get_lock_door_status(authentication.access_token,'41C161F1D5DB4C30948CE8184C8438F1')



open = "LockDoorStatus.OPEN"
closed = "LockDoorStatus.CLOSED"


def frontDoorState():
    if str(front_door_status) == open:
        print(0)
    elif str(front_door_status) == closed:
        print(1)

frontDoorState()

image

Here are some of the error logs I'm getting from homebridge:

0|homebridge  | [5/6/2019, 4:05:03 PM] [Cmd4] getGeneric StatusActive function for: Front Door cmd: python ~/.homebridge/Cmd4Scripts/front_door_state.py Get 'Front Door' 'StatusActive' failed.
0|homebridge  | [5/6/2019, 4:05:03 PM] [Cmd4] { Error: Command failed: python ~/.homebridge/Cmd4Scripts/front_door_state.py Get 'Front Door' 'StatusActive'
0|homebridge  |     at ChildProcess.exithandler (child_process.js:294:12)
0|homebridge  |     at ChildProcess.emit (events.js:189:13)
0|homebridge  |     at maybeClose (internal/child_process.js:970:16)
0|homebridge  |     at Process.ChildProcess._handle.onexit (internal/child_process.js:259:5)
0|homebridge  |   killed: true,
0|homebridge  |   code: null,
0|homebridge  |   signal: 'SIGTERM',
0|homebridge  |   cmd:
0|homebridge  |    'python ~/.homebridge/Cmd4Scripts/front_door_state.py Get \'Front Door\' \'StatusActive\'' }
0|homebridge  | [5/6/2019, 4:05:03 PM] [Cmd4]
0|homebridge  | [5/6/2019, 4:05:03 PM] [Cmd4]
0|homebridge  | [5/6/2019, 4:05:13 PM] [Cmd4] getGeneric StatusFault function for: Front Door cmd: python ~/.homebridge/Cmd4Scripts/front_door_state.py Get 'Front Door' 'StatusFault' failed.
0|homebridge  | [5/6/2019, 4:05:13 PM] [Cmd4] { Error: Command failed: python ~/.homebridge/Cmd4Scripts/front_door_state.py Get 'Front Door' 'StatusFault'
0|homebridge  |     at ChildProcess.exithandler (child_process.js:294:12)
0|homebridge  |     at ChildProcess.emit (events.js:189:13)
0|homebridge  |     at maybeClose (internal/child_process.js:970:16)
0|homebridge  |     at Process.ChildProcess._handle.onexit (internal/child_process.js:259:5)
0|homebridge  |   killed: true,
0|homebridge  |   code: null,
0|homebridge  |   signal: 'SIGTERM',
0|homebridge  |   cmd:
0|homebridge  |    'python ~/.homebridge/Cmd4Scripts/front_door_state.py Get \'Front Door\' \'StatusFault\'' }
0|homebridge  | [5/6/2019, 4:05:13 PM] [Cmd4]
0|homebridge  | [5/6/2019, 4:05:13 PM] [Cmd4]
0|homebridge  | [5/6/2019, 4:06:03 PM] [Cmd4] getGeneric StatusFault function for: Front Door cmd: python ~/.homebridge/Cmd4Scripts/front_door_state.py Get 'Front Door' 'StatusFault' failed.
0|homebridge  | [5/6/2019, 4:06:03 PM] [Cmd4] { Error: Command failed: python ~/.homebridge/Cmd4Scripts/front_door_state.py Get 'Front Door' 'StatusFault'
0|homebridge  |     at ChildProcess.exithandler (child_process.js:294:12)
0|homebridge  |     at ChildProcess.emit (events.js:189:13)
0|homebridge  |     at maybeClose (internal/child_process.js:970:16)
0|homebridge  |     at Process.ChildProcess._handle.onexit (internal/child_process.js:259:5)
0|homebridge  |   killed: true,
0|homebridge  |   code: null,
0|homebridge  |   signal: 'SIGTERM',
0|homebridge  |   cmd:
0|homebridge  |    'python ~/.homebridge/Cmd4Scripts/front_door_state.py Get \'Front Door\' \'StatusFault\'' }
0|homebridge  | [5/6/2019, 4:06:03 PM] [Cmd4]
0|homebridge  | [5/6/2019, 4:06:03 PM] [Cmd4]

Trying to set up Kodi volume control.

I'm trying to set up the volume on my Kodi box as a virtual speaker (I use Kodi's built-in volume control on a dumb speaker system), but I'm having a hard time wrapping my head around how to go about it.

In my JSON, I have:

{
	"platform": "Cmd4",
	"name": "Cmd4",
	"accessories": [
		{
			"type": "Speaker",
			"displayName": "Kodi",
			"mute": "0",
			"volume": 5,
			"name": "Kodi",
			"stateChangeResponseTime": 3,
			"state_cmd": "bash /var/lib/homebridge/scripts/kodivolume.sh"
		}
	]
},

and the kodivolume.sh script is as follows:

#!/usr/bin/env bash

if [ "$1" = "Get" ]; then
    if [ "$3" == "Volume" ] || [ "$3" == "Mute" ]; then
      	#get volume/muted info using curl
      	getinfo=$(curl -s -H 'Content-Type: application/json' -d '{"jsonrpc": "2.0", "method": "Application.GetProperties", "params": { "properties": [ "volume","muted" ] }, "id": 1 }' http://192.168.0.112:8080/jsonrpc )
		#parse the JSON for information
    	kodivolume=$(jq -r '.result.volume' <<<"$getinfo")
     	kodimuted=$(jq -r '.result.muted' <<<"$getinfo")
        if [ "$3" == "Volume" ]; then
        	echo "$kodivolume"
        	exit 0
        else
        	if [[ "$kodimuted" == "true" ]]; then
        		echo 1
        		exit 0
        	else
        		echo 0
        		exit 0
        	fi
        fi
    fi
fi

if [ "$1" = "Set" ] && [ "$3" == "Volume" ]; then
	#check if variable #4 exists, and that it is indeed a number (with optional percent sign)
 	if [ ! -z "$4" ] && [[ "$4" =~ ^[0-9]{1,2}%*$ ]]; then
 		json='{"jsonrpc":"2.0","method":"Application.SetVolume","params":{"volume":%s},"id":1}'
 		#filter out everything but the number
 		number=${4//[!0-9]}
 		#Join number to JSON string
 		jsonstring=$(printf "$json" "$number")
 		#Call JSON
 		curl -s -H 'Content-Type: application/json' -d $jsonstring http://192.168.0.112:8080/jsonrpc
 		exit 0
 	else
 		exit -1
        fi
  	echo 1
  	exit 0
fi
exit -1

If feels like this should work, but I'm new to homebridge.

[Edited to update with newer script, but it's still not working]

All of the sudden...

I install another plugin ("homebridge-tuya-smartlamp") and boom, CMD4 starts throwing:

SyntaxError: Unexpected token A in JSON at position 0
    at JSON.parse (<anonymous>)
    at IncomingMessage.res.on (/usr/local/lib/node_modules/homebridge-cmd4/node_modules/github-version-checker/lib/check.js:64:21)
    at IncomingMessage.emit (events.js:203:15)
    at endReadableNT (_stream_readable.js:1129:12)
    at process._tickCallback (internal/process/next_tick.js:63:19)
homebridge.service: Main process exited, code=exited, status=255/EXCEPTION
homebridge.service: Failed with result 'exit-code'.
homebridge.service: Service RestartSec=3s expired, scheduling restart.
homebridge.service: Scheduled restart job, restart counter is at 2.

Nothing has changed in the CMD4 section of the config, it all validates via JSONlint and the problem continues to happen, even after both the Tuya plugin has been removed and CMD4 removed and reinstalled. If even one piece of CMD4 JSON exists in the config file, the error happens and takes down homebridge. every 10 seconds or so.

As I said, it's just like the plugin is now permanently broken—all (maybe) because of another plugin.

CurrentPosition of WindowCovering is always 1% in the Home app

First of all, thanks for all the great work done so far!

I'm using this plugin to control many different devices, including some shutters. Setting the shutters works fine, however the CurrentPosition value does not seem to be displayed correctly in the Home app. It looks fine in when the script is executed manually though:

/homebridge # sh /homebridge/Cmd4Scripts/franken.sh Set example_shutter TargetPosition 10
202
/homebridge # sh /homebridge/Cmd4Scripts/franken.sh Get example_shutter PositionState
2
/homebridge # sh /homebridge/Cmd4Scripts/franken.sh Get example_shutter CurrentPosition
10

The above example results in 1% shown in the app (instead of 10%).

Screen Shot 2019-06-15 at 10 47 32 PM

Installation

Hi, i'm trying to install this plugin under raspbian buster & homebridge installation guide from smartapfel.de
i cannot install the state.js
Bildschirmfoto 2019-12-23 um 15 28 45

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.