rudders / homebridge-http

HTTP Plugin for Homebridge
Apache License 2.0
178 stars 110 forks source link

brightness url #11

Closed bwired-nl closed 8 years ago

bwired-nl commented 8 years ago

Hi great plugin!!

Question, i try to control my leds, on and off is working but im not sure how to get the value on my http server

i use node express to get the url, But how to i get the percentage of the brightness? hope you can give a hint? also how to shoot back the current value

app.get('/ledbright', function (req, res) { console.log('leds led-brstat') console.log('inspect : ' + util.inspect(res)); //res.send('0'); });

this is the json "accessory" : "Http", "name" : "Led verlichting", "switchHandling": "yes", "http_method": "GET", "on_url" : "http://10.0.0.47:3031/ledsaan", "off_url" : "http://10.0.0.47:3031/ledsuit", "status_url": "http://10.0.0.47:3031/ledsstatus", "brightness_url": "http://10.0.0.47:3031/ledbright/%b", "brightness_body": "{\"state\":\"%b\"}", "brightnessHandling": "yes", "brightnesslvl_url": "http://10.0.0.47:3031/led-brstat", "sendimmediately": "", "username" : "", "password" : "",
"service": "Light"

rudders commented 8 years ago

@NovaGL any advice hear?

NovaGL commented 8 years ago

You need to give us more information like make and model. Currently brightness is only a number not a percentage as far as I know. Is it a GET or a POST for brightness. I think homebridge Yamaha converts theirs into percentage.

bwired-nl commented 8 years ago

the device is a chromoflex ledstrip controller it is working :-), at least how to receive it this is in the json: "brightness_url": "http://10.0.0.47:3031/ledbright?tagid=%b",

and this I use in my nodejs (express) webserver at 10.0.0.47 this:

app.get('/ledbright', function(req, res) { console.log("tagId is set to " + req.param('tagid')); tools.mqttClient.publish('command/cflex', '{"address":"1B", "command": ' + req.param('tagid') + '}');
res.send(req.param('tagid')); });

i can tell Siri now to set the Leds at 60% I need to check the status still, also want the current setting (percentage) of the ledstrip send need to figure this out, any tips?

Thanks

NovaGL commented 8 years ago

Can you node express output a value using a GET command or a POST command? And what value does it output.

bwired-nl commented 8 years ago

not sure what you mean :-) i can send a value back to the homebridhe with res.send, see the above example.

what i want to have now is a status, so the first time i open the device (for example in insteon+) I want the status of the ledstrip see the above which is "status_url": "http://10.0.0.47:3031/ledsstatus", i can check the status in my webserver progje and send the status back with res.send but it does not seem to react, need to do something in the index server with the status_url Hope you understand me many thanks!

rudders commented 8 years ago

What does the URL return in a browser? Is it json? Xml? Or just a simple value between 0 and 100?

bwired-nl commented 8 years ago

a simple value, for example 78

NovaGL commented 8 years ago

status_url is only for on or off or 0 or 1.

You have the use "brightnesslvl_url" if you want a value such as 78 to work.

Otherwise check your homebridge logs and look for the words "Led verlichting"

bwired-nl commented 8 years ago

OK clear but how is this fired from for example the insteon+ app if i use brightness_url in the config.json I see a bar being created in the insteon+ app where i can set the brighness from 0 to 100. this brightness value i can send to my webserver. But how do i send the brightnesslvl_url to my webserver and make the Bar in Insteon shift to that value. So insteon needs to pick up the initial value.

NovaGL commented 8 years ago

The plugin polls the address of "brightnesslvl_url" and if the body value changes, it changes the value on the slider.

"brightness_body" is only needed if "http_brightness_method" is set to POST

bwired-nl commented 8 years ago

I had a slightly different index.js , updated and working perfectly now also with the slider :-) even if the device is controlled by other program, this is updated. again great plugin!

rudders commented 8 years ago

So you've got it to work with the standard plugin or have you had to modify it to get it to work?

bwired-nl commented 8 years ago

No modifications, working perfect, just a matter of the putting everything right in the config.json. i was able the have the nodejs webserver send the right values back so you can close this.....

rudders commented 8 years ago

Awesome - thanks for letting us know you got it to work okay. Thanks @NovaGL for your help too! Happy new year!

NovaGL commented 8 years ago

Glad you got it working, maybe you had the version before my enhancements.