dxdc / homebridge-blinds

:sunrise: Homebridge Plugin to control my blinds over HTTP
https://www.npmjs.com/package/homebridge-blinds
ISC License
54 stars 26 forks source link

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

Closed dxdc closed 3 years ago

dxdc commented 4 years ago

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

slavikme commented 4 years ago

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 commented 4 years ago

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 commented 3 years ago

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 commented 3 years ago

@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:

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 commented 3 years ago

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 commented 3 years ago

Can you send me your full config @hauni97 ?

dxdc commented 3 years ago

Also @hauni97 , please try:

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

Found a minor issue.

hauni97 commented 3 years ago

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 commented 3 years ago

"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 commented 3 years ago

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

hauni97 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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

Thanks for adding that feature.

dxdc commented 3 years ago

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

dxdc commented 3 years ago

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 commented 3 years ago

Yes, I’m willing to share anonymized scripts with instructions and further info. Please let me know where to provide them.

No, I haven’t used a position URL.

dxdc commented 3 years ago

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

dxdc commented 3 years ago

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

hauni97 commented 3 years ago

Perfect, I’ll add them to the appropriate section in the README.md tomorrow afternoon GMT ( Probably by creating a pull request to the .md.).

dxdc commented 3 years ago

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 commented 3 years ago

@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 commented 3 years ago

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

hauni97 commented 3 years ago

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

hauni97 commented 3 years ago

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 commented 3 years ago

Sorry... try again @hauni97

hauni97 commented 3 years ago

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