Nicnl/homebridge-minimal-http-lightbulb-brightness

No issue but a question (for a plugin)

Leonoerlemans opened this issue · 6 comments

Hi, thank you for this plugin. I am new to homebridge. I do know how to use the plugins, but I am getting stuck on altering them. I am hoping that you can and will help me to controle my environment with homebridge. Here is my situation:

I have created an arduino based device which can control 64 relays bij a HTTP command.

  • URL format: http://0.0.0.0/?XpYnnnn
  • X = Board (A-B-C-D-E-F-G-H)
  • p = Pin number (0-7)
  • Y = Action to perform
  •    - H = Relay OFF
    
  •    - L = Relay ON
    
  •    - T = Toggle (ON > OFF & OFF > ON)
    
  •    - P = Pulse nnnnn milliseconds uses toggle
    

a set of two relais is connected to a touch switch. When I:

  • give a short puls (200 ms) to the relay which controles the ON switch, the light goes ON
  • give a short puls (200 ms) to the relay which controles the OFF switch, the light goes OFF
  • keep the ON switch pressed (either bij a long puls or set the relay ON (with an URL) and after a certain time set the relay OFF (with an URL)), the light will turn brighter
  • keep the OFF switch pressed (either bij a long puls or set the relay ON (with an URL) and after a certain time set the relay OFF (with an URL)), the light will get less brighter

so I need to create a plugin with an config.jsn -file with parameters:

  • ON URL
  • OFF URL
  • duration time in ms (from fully off to fully on and visa versa )
  • brighter relay ON URL
  • brighter relay OFF URL
  • less brighter relay ON URL
  • less brighter relay OFF URL

Because I want to create a dimmable lightbulb in Homekit

I realize I ask for a lot, but can and will you help met with that.

Kinds regards,

Leon

Hi, thats not good idea. For dimmable light need only one mosfet for one channel! If you use Arduino

Hi Igor,

Thank you for your answer!
The fact is that the relays are connected to a switch which send a BUS/PLC signal (a pulse over the powercables) to other switches (one of the early domotica (legrand in one)) so by controlling this first switch I can control the light(s). teh relays are soldered to the BUS/PLC-switch. This switch has to touch switches ON and OFF: short pulse ON and the lights go on, short pulse OFF and the lights go off. Long press ON and the lights goe brightre and long press OFF and the lights go less bright. for these action I need tot controle the relays. This I can do bij seperate URL's as described in my first message.
So that's why I need that. Could you please help me on that

Kind regards

Leon

Hi, I think you need another plugin. try to search here npmjs.com

Nicnl, Hi
I have a problem with the plugin
`[2018-6-8 16:55:22] [Kitchen Lightbulb] Updated On to value 0

[2018-6-8 16:55:22] [Kitchen Lightbulb] Target brightness set to 0

[2018-6-8 16:55:22] [Kitchen Lightbulb] Target on_off set to false

[2018-6-8 16:55:24] [Kitchen Lightbulb] calling callback with brightness: 0

[2018-6-8 16:55:24] [Kitchen Lightbulb] Responded to 1 Brightness callbacks!

[2018-6-8 16:55:24] [Kitchen Lightbulb] calling callback with on_off: 0

[2018-6-8 16:55:24] [Kitchen Lightbulb] Responded to 1 On callbacks!

[2018-6-8 16:55:29] [Kitchen Lightbulb] Setting new target on_off: true => http://192.168.0.101/set?power_state=true

[2018-6-8 16:55:29] [Kitchen Lightbulb] Setting new target brightness: 100 => http://192.168.0.101/setto?brightness=100

[2018-6-8 16:55:29] [Kitchen Lightbulb] Target on_off set to true

[2018-6-8 16:55:30] [Kitchen Lightbulb] Target brightness set to 100

[2018-6-8 16:55:30] [Kitchen Lightbulb] Setting new target brightness: 100 => http://192.168.0.101/setto?brightness=100

[2018-6-8 16:55:30] [Kitchen Lightbulb] Updated Brightness to value 100

[2018-6-8 16:55:30] [Kitchen Lightbulb] Setting new target on_off: true => http://192.168.0.101/set?power_state=true

[2018-6-8 16:55:30] [Kitchen Lightbulb] Updated On to value 1

[2018-6-8 16:55:30] [Kitchen Lightbulb] Target brightness set to 100

[2018-6-8 16:55:31] [Kitchen Lightbulb] Target on_off set to true

[2018-6-8 16:55:31] [Kitchen Lightbulb] Setting new target brightness: 0 => http://192.168.0.101/setto?brightness=0

[2018-6-8 16:55:31] [Kitchen Lightbulb] Updated Brightness to value 0

[2018-6-8 16:55:31] [Kitchen Lightbulb] Setting new target on_off: false => http://192.168.0.101/set?power_state=false

[2018-6-8 16:55:31] [Kitchen Lightbulb] Updated On to value 0

[2018-6-8 16:55:31] [Kitchen Lightbulb] Target brightness set to 0

[2018-6-8 16:55:31] [Kitchen Lightbulb] Target on_off set to false`

In HomeKit press ON. LED Lamp ON and OFF. Press only ON

Arduino CODE
`void handleRoot()
{
server.send(200, "text/plain", "Hello World");
}
void handleSet()
{
p_state = server.arg("power_state");
int onoff = p_state.toInt();
if ( onoff == 1 )
{
setBrightness(1000);
s_brightness = "100";
server.send(204, "text/plain");
}
if ( onoff == 0 )
{
setBrightness(0);
s_brightness = "0";
server.send(204, "text/plain");
}
else
{
server.send(401, "text/plain", "401: Wrong Status");
}
}

void handleBrightness()
{
server.send(200, "text/plain", s_brightness);
}

void handleSetto() // set brightness
{
s_brightness = server.arg("brightness");
newbrightness = s_brightness.toInt() * 10;
if( newbrightness > 0 && newbrightness <= 1000 )
{
setBrightness(newbrightness);
onoff = 1;
server.send(204, "text/plain");
}
if(newbrightness == 0)
{
onoff = 0;
setBrightness(newbrightness);
server.send(204, "text/plain");
}
else
{
server.send(401, "text/plain", "401: Wrong Position");
}
}

void handleOnOff()
{
if (s_brightness == "0") {
onoff = 0;}
if (s_brightness != "0") {
onoff = 1;}
server.send(200, "text/plain", String(onoff));
}

void handleNotFound()
{
server.send(404, "text/plain", "404: Not found");
}

void setBrightness(int newbrightness)
{
if (newbrightness > current_brightness)
{
for (int i = current_brightness; newbrightness > i; i++)
{
analogWrite(D2, i);
delay(1);
current_brightness = i;
}

}
else if (newbrightness < current_brightness)
{
for (int i = current_brightness; newbrightness < i; i--)
{
analogWrite(D2, i);
delay(1);
current_brightness = i - 1;
}

} else if (newbrightness == current_brightness) {

analogWrite(D2, current_brightness);

}

}`
What you think about?

@IgorFX Did you change brightness polling interval from default 500ms? Because the code on your controller takes 1000ms to turn on the light and after that it sets that s_brightness property. But before it manages to turn the light fully on the plugin polls current brightness and controller responds with 0 as it is still turning the light on, so it updates the state in homekit back to 0.
Try setting the s_brightness before you actually start dimming, or set polling to longer interval.

Hi. There is an error in the description of this module. The on/off option is not 0 or 1, but true or false. I spent 5 days to make it work.