Code Monkey home page Code Monkey logo

Comments (13)

jonnyborbs avatar jonnyborbs commented on August 11, 2024

I have exactly this same issue with Inovelli fan control switches, where the Home app sends 5 speed commands to Homebridge, and the funky math in the functions from lines 1983-2003 causes wrong values to be sent to the controller.

Most 3 speed fans, which is really just "most fans" expect 0 [off], low [33], medium [66], high [100]

I have tried messing with the values in the map and removing the rounding/percentage/toInt math that I don't quite understand the purpose of and it still just keeps sending "medium-low" requests that my fans can't understand.

Would really appreciate a way to make these configurable as well, or at least some clarity around what the private static Integer getFanSpeedInteger function is doing here. I'm not sure why the changes I attempted didn't work.

private static Integer getFanSpeedInteger(String speed, Integer numberOfSpeeds = 3) {
    Map<String, Integer> speedMappings = [
//        "low": 0,
//        "medium-low": 25,
//        "medium": 50,
//        "medium-high": 75,
//        "high": 100,
//JS changed values here
        "low": 33,
        "medium-low" : 33,
        "medium" : 66,
        "medium-high": 66,
        "high": 100,
        "on": 100,
        "off": 0,
        "auto": 50  // You can adjust this based on your needs
    ]

    Integer speedPercentage
    speedPercentage = speedMappings[speed] ?: 0
    // Adjust percentage based on the number of speeds
    //  -1 because index is 0-based
    //speedPercentage = Math.round( ((speedPercentage / 100.0) * (numberOfSpeeds - 1)) * 100).toInteger()
    //JS removed above line
    return speedPercentage

}

from homebridge-hubitat-tonesto7.

jonnyborbs avatar jonnyborbs commented on August 11, 2024

Actually, digging around a bit more I think the issue lies in these two functions here:

fanSpeedConversion(speedVal) {

And here

fanSpeedToLevel(speedVal, opts = {}) {

This is on the JS side within Homebridge itself, and is sending string values based on rigidly defined numerics. Those string values are sent to the devices and interpreted for zwave/zigbee execution.

I don't think the issue is really within the Groovy code at all but something that needs manipulation in the homebridge plugin itself

from homebridge-hubitat-tonesto7.

jonnyborbs avatar jonnyborbs commented on August 11, 2024

Yeah, this tracks with what I am observing in the logs perfectly.

Assume the slider in the Home app has 4 positions:
0=Off
1=33%
2=66%
3=100%

When I set the slider in Apple Home to position 1, which reads "33%" on the slider, this is the log output I see in Homebridge

[25/10/2023, 18:15:54] [Hubitat-v2] Sending Device Command: setSpeed | Value: {"value1":"medium-low"} | Name: (Living Room Fan) | DeviceID: (30) | UsingCloud: (false)
[25/10/2023, 18:15:56] [Hubitat-v2] [Device Event]: (Living Room Fan) [LEVEL] is 99
[25/10/2023, 18:15:56] [Hubitat-v2] [Device Event]: (Living Room Fan) [SPEED] is medium
[25/10/2023, 18:15:56] [Hubitat-v2] [Device Event]: (Living Room Fan) [LEVEL] is 58
[25/10/2023, 18:15:58] [Hubitat-v2] [Device Event]: (Living Room Fan) [LEVEL] is 40

Now, look at the conversion function:

    fanSpeedConversion(speedVal) {
        // console.log("speedVal: ", speedVal);
        if (speedVal <= 0) {
            return "off";
        } else if (speedVal > 0 && speedVal <= 20) {
            return "low";
        } else if (speedVal > 20 && speedVal <= 40) {
            return "medium-low";
        } else if (speedVal > 40 && speedVal <= 60) {
            return "medium";
        } else if (speedVal > 60 && speedVal <= 80) {
            return "medium-high";
        } else if (speedVal > 80 && speedVal <= 100) {
            return "high";
        }
    }

So, because the fanSpeedConversion function interprets "33%" as "medium-low" it sends that command to the switch.

Then the following fanSpeedToLevel function is returning a value of 40 for medium-low,

switch (speedVal) {
            case "off":
                return 0;
            case "low":
                return 33;
            case "medium-low":
                return 40;
            case "medium":
                return 66;
            case "medium-high":
                return 80;
            case "high":
                return 100;

But "medium-low" isn't a value a 3 speed switch understands, and so this is causing the bouncing issue.

from homebridge-hubitat-tonesto7.

jonnyborbs avatar jonnyborbs commented on August 11, 2024

It's also worth noting that since a 3 speed switch sees "40" as past the threshold of 33, it runs at medium when you set low, high when you set medium, and has no ability to run at low at all.

So this being the case, I actually think this is not just an enhancement but a bug - the logic for working with 3 speed controls appears to be incomplete, there are accommodations made for it in the Groovy side that are not reflected deeply enough in the plugin side.

from homebridge-hubitat-tonesto7.

tonesto7 avatar tonesto7 commented on August 11, 2024

In the home bridge app under Hubitat are you guys placing the device under the correct fan speed inputs

from homebridge-hubitat-tonesto7.

jonnyborbs avatar jonnyborbs commented on August 11, 2024

Yup, for sure all of mine are in the fan3speed list
CleanShot 2023-10-27 at 13 21 26

I have tried them in the 4 and 5 speed lists to see if it would make the behavior more predictable, even if imperfect - but it didn't really help.

from homebridge-hubitat-tonesto7.

tonesto7 avatar tonesto7 commented on August 11, 2024

image
Those inputs help the HomeKit plugin know how many available speeds there which then defines what each increment is on the slider

from homebridge-hubitat-tonesto7.

jonnyborbs avatar jonnyborbs commented on August 11, 2024

Yeah, our messages crossed paths here! Confirmed I am using the correct list, cannot speak for OP but I suspect the same

from homebridge-hubitat-tonesto7.

jonnyborbs avatar jonnyborbs commented on August 11, 2024

And that aspect works per #206 (comment) - the sliders in HomeKit have 3 steps, but the values get all out of wack on the backend.

from homebridge-hubitat-tonesto7.

jonnyborbs avatar jonnyborbs commented on August 11, 2024

Hi @tonesto7 was just wondering if you had any other ideas we could try here! I've been trying to follow the logic used in the plugin to see if I could author a PR here, but I think I'm missing something. I know you asked whether the fans were in the proper speed list, but I can't seem to find where that list is used for anything other than setting the number of stops on the slider control. The trail goes cold for me there, trying to connect that to the logic used to translate the text speeds to numeric values.

Appreciate any help and thanks for creating this/looking into the question!

from homebridge-hubitat-tonesto7.

Related Issues (20)

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.