Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to call command-line scripts (vs. HTTP requests) #45

Closed
dxdc opened this issue Jul 4, 2020 · 26 comments
Closed

Add ability to call command-line scripts (vs. HTTP requests) #45

dxdc opened this issue Jul 4, 2020 · 26 comments

Comments

@dxdc
Copy link
Owner

dxdc commented Jul 4, 2020

See: https://github.com/hjdhjd/homebridge-blinds-cmd

@slavikme
Copy link
Contributor

slavikme commented Jul 4, 2020

The change is pretty simple, but it's already changes the core purpose of this plugin.
Are you sure you want to go this direction and expand its functionality?

@dxdc
Copy link
Owner Author

dxdc commented Jul 4, 2020

I think it expands a lot of functionality, so I'm open for it. The only thing is how to handle the configuration.

I was thinking maybe the user could use file:///.... in the url config, and if the system detected this protocol, it will redirect to use something like:

const exec = require('child_process').exec;
const url = require('url');

...

exec(url, (err, stdout, stderr) => {
  if (err) {
    //some err occurred
  } else {
   console.log(`stdout: ${stdout}`);
   console.log(`stderr: ${stderr}`);
  }

@hauni97
Copy link

hauni97 commented Dec 27, 2020

Are there already any updates on changing/ adding command-line features to this plugin?
I use the forked version mentioned above of this plugin, but it would be great if the user chooses this plugin to choose between cmd or HTTP request.

dxdc added a commit that referenced this issue Dec 27, 2020
@dxdc
Copy link
Owner Author

dxdc commented Dec 27, 2020

@hauni97 I just pushed some changes in a beta version, would appreciate if you can test them.

e.g.,
npm install -g homebridge-blinds@1.3.23-beta.0

It works as follows:

  • If file:// is added as prefix for URL, it will be processed as a command line script. For example, file://echo "this is a test". Note that this is just used as a prefix and should not be url encoded. The file:// prefix is just stripped off before it is run.

  • Else, normal HTTP processing will occur.

This is a bit of a patch for now, I'm working on additional changes which will be part of a future version, but don't want to break anything for now.

@hauni97
Copy link

hauni97 commented Dec 27, 2020

Thanks. I just tried using it, and it gives me the error no response in HK; the blinds are not moving.

This is the Homebridge log after using it and filling in, up, down, pause + time it takes to upen & close:

[12/27/2020, 17:10:47] TypeError: Cannot read property 'match' of undefined
    at BlindsHTTPAccessory.httpRequest (/usr/local/lib/node_modules/homebridge-blinds/index.js:637:34)
    at BlindsHTTPAccessory.setTargetPosition (/usr/local/lib/node_modules/homebridge-blinds/index.js:402:10)
    at TargetPosition.emit (events.js:315:20)
    at TargetPosition.EventEmitter.emit (/usr/local/lib/node_modules/homebridge/node_modules/hap-nodejs/src/lib/EventEmitter.ts:42:22)
    at TargetPosition.Characteristic._this.setValue (/usr/local/lib/node_modules/homebridge/node_modules/hap-nodejs/src/lib/Characteristic.ts:652:12)
    at /usr/local/lib/node_modules/homebridge/node_modules/hap-nodejs/src/lib/Accessory.ts:1439:24
    at Array.forEach (<anonymous>)
    at Bridge.Accessory._this._handleSetCharacteristics (/usr/local/lib/node_modules/homebridge/node_modules/hap-nodejs/src/lib/Accessory.ts:1281:10)
    at HAPServer.emit (events.js:315:20)
    at HAPServer.EventEmitter.emit (/usr/local/lib/node_modules/homebridge/node_modules/hap-nodejs/src/lib/EventEmitter.ts:42:22)
Got SIGTERM, shutting down Homebridge...

[12/27/2020, 17:11:00] [Blinds Command] Name, up, and down commands are required configuration parameters.

I inserted the following into the UP, DOWN, PAUSE Command Script:

file://python /var/lib/homebridge/Blinds_UP.py

My python script contains the following (based on MQQT, changes depending on up, down, and pause):

import paho.mqtt.client as mqtt

#Copyright

client = mqtt.Client()
client.username_pw_set(username=username”, password=password”)
client.connect(“broker”, port, no)
client.publish(“topic”, “command _to_close_blinds");
client.disconnect();

@dxdc
Copy link
Owner Author

dxdc commented Dec 27, 2020

Can you send me your full config @hauni97 ?

dxdc added a commit that referenced this issue Dec 27, 2020
@dxdc
Copy link
Owner Author

dxdc commented Dec 27, 2020

Also @hauni97 , please try:

npm install -g homebridge-blinds@1.3.23-beta.1

Found a minor issue.

@hauni97
Copy link

hauni97 commented Dec 27, 2020

Sure this is the config of my accessories for this specific plug-in and the test blind:

},
    "accessories": [
        {
            "name": "TEST",
            "up_url": "file://python /var/lib/homebridge/Blinds_UP.py",
            "motion_up_time": 25000,
            "down_url": "file//python /var/lib/homebridge/Blinds_DOWN.py",
            "motion_down_time": 25000,
            "stop_url": "python /var/lib/homebridge/Blinds_Pause.py",
            "accessory": "BlindsHTTP"
        }
  ],

Please let me know if you require any further info.

@dxdc
Copy link
Owner Author

dxdc commented Dec 27, 2020

"down_url": "file//python /var/lib/homebridge/Blinds_DOWN.py",

This needs to be:

"down_url": "file://python /var/lib/homebridge/Blinds_DOWN.py",

"stop_url": "python /var/lib/homebridge/Blinds_Pause.py",

This needs to be:

"stop_url": "file://python /var/lib/homebridge/Blinds_Pause.py",

@dxdc
Copy link
Owner Author

dxdc commented Dec 27, 2020

Btw, please remember to restart homebridge after installing the update and making the config changes.

@hauni97
Copy link

hauni97 commented Dec 27, 2020

Works now without an error, blinds are moving.

[12/27/2020, 17:42:58] [TEST] Requested Move down (to 81%)
[12/27/2020, 17:42:58] [TEST] Requested Move down (to 72%)
[12/27/2020, 17:42:58] [TEST] Move request sent (276 ms), waiting 7s (+ 0s response lag)...
[12/27/2020, 17:42:58] [TEST] Move request sent (211 ms), waiting 7s (+ 0s response lag)...
[12/27/2020, 17:43:02] [TEST] End Move down to 72% (target 72%)
[12/27/2020, 17:43:05] [TEST] Requesting stop
[12/27/2020, 17:43:05] [TEST] Requesting stop
[12/27/2020, 17:43:05] [TEST] Stop request sent
[12/27/2020, 17:43:05] [TEST] Stop request sent

When moving down: It stopped at the desired position for a few seconds but then kept moving down to full without doing anything in HK.
When moving up (in the range of 50%): Some desired positions seem to work after a couple more tests, probably a timing issue.
I will try to troubleshoot systematically later today and keep you up to date.

@dxdc
Copy link
Owner Author

dxdc commented Dec 27, 2020

Thanks @hauni97. It could also depend on your set up and how your MQTT<-->blinds interface is working.

I would also encourage you to add the verbose: true keyword to the config while troubleshooting, could be useful.

@hauni97
Copy link

hauni97 commented Dec 27, 2020

The plugin with the command line addition works perfectly, just tried it with five different binds.

Thanks for adding that feature.

@dxdc
Copy link
Owner Author

dxdc commented Dec 27, 2020

thanks for testing @hauni97! I'll update the docs and push this out as an official release shortly.

@dxdc dxdc closed this as completed Dec 27, 2020
@dxdc
Copy link
Owner Author

dxdc commented Dec 27, 2020

Btw, @hauni97 would you be willing to publish anonymized versions of your scripts? Could be included in the wiki... I imagine useful for other users.

(And, I guess you did not use the position_url feature?)

@hauni97
Copy link

hauni97 commented Dec 27, 2020 via email

@dxdc
Copy link
Owner Author

dxdc commented Dec 27, 2020

Thanks @hauni97 you can post them here: https://github.com/dxdc/homebridge-blinds/wiki

@dxdc
Copy link
Owner Author

dxdc commented Dec 27, 2020

Btw, published as a new (official) release, although no code-based changes from the one you have - just documentation.

@hauni97
Copy link

hauni97 commented Dec 27, 2020 via email

@dxdc
Copy link
Owner Author

dxdc commented Dec 27, 2020

Thx! I would suggest just writing an entry on the Wiki directly, it's user editable (no PR needed). I don't want to clutter the README unnecessarily.

@hauni97
Copy link

hauni97 commented Dec 28, 2020

@dxdc I tried to edit the wiki, are you sure it is publically editable?

When hitting the wiki button it redirects me to the main repo (https://github.com/dxdc/homebridge-blinds), no button to edit the wiki is shown as in other repositories.

@dxdc
Copy link
Owner Author

dxdc commented Dec 28, 2020

@hauni97 can you try again? I didn't have an initial page set up, not sure if that was an issue.

@hauni97
Copy link

hauni97 commented Dec 28, 2020

@dxdc Yes, there is a Wiki now, but no rights to edit it.

@hauni97
Copy link

hauni97 commented Dec 28, 2020

Maybe this helps: https://docs.github.com/en/free-pro-team@latest/github/building-a-strong-community/changing-access-permissions-for-wikis

"Collaborators can edit a public repository's wiki by default, but you can allow anyone with a GitHub account to edit your wiki."

@dxdc
Copy link
Owner Author

dxdc commented Dec 29, 2020

Sorry... try again @hauni97

@hauni97
Copy link

hauni97 commented Dec 29, 2020

@dxdc no worries it works now. I Will work on the wiki in the coming days and add useful content.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants