mylesagray / homebridge-blueair

BlueAir air purifier plugin for homebridge
Apache License 2.0
39 stars 20 forks source link

BlueAir Classic 405 Support (Wi-Fi controllable with no built-in sensors) #12

Closed d3rw1n closed 6 years ago

d3rw1n commented 6 years ago

I've confirmed using Charles as instructed that they share the same API however I cannot make it work on homebridge.

The log shows the following after homebridge crashes:

/usr/local/lib/node_modules/homebridge-blueair/index.js:474 this.measurements.pm = json.datapoints[0][i]; ^

TypeError: Cannot read property '1' of undefined at BlueAir. (/usr/local/lib/node_modules/homebridge-blueair/index.js:474:52) at BlueAir. (/usr/local/lib/node_modules/homebridge-blueair/index.js:248:6) at Request.self.callback (/usr/local/lib/node_modules/homebridge-blueair/node_modules/request/request.js:186:22) at emitTwo (events.js:126:13) at Request.emit (events.js:214:7) at Request. (/usr/local/lib/node_modules/homebridge-blueair/node_modules/request/request.js:1163:10)

P.S. I'm new to GitHub and not a programmer so I'm not sure where to start.

mylesagray commented 6 years ago

Thanks for the report, definitely related to the lack of sensors, will look into it this weekend.

Will probably need to filter by model and ignore pulling sensor measurements.

d3rw1n commented 6 years ago

I don’t mean to rush but has there been any updates on this?

mylesagray commented 6 years ago

Moving house at the moment - so this is delayed - happy to take patches though :)

d3rw1n commented 6 years ago

Wish I could write my own patches. Unfortunately I’m no programmer and I don’t understand any of the codes. Guess I’ll just have to wait :)

ndlaham commented 6 years ago

Hey mylesgray, thanks for all your work on this. I have been trying to get this to work too, but I got as far as d3rw1n and ran into the same problem because I also have the no-sensor Blueair purifier (Classic 205).

I'm pretty new to homebridge (I have 1 other plugin running), but have I do have some limited programming experience so I would be happy to help and provide any results if this is still something you think you are going to try and update. If not, I would be happy to help but would most definitely need some direction. I have 2 Blueair machines without sensors so I could definitely assist in troubleshooting these logical issues on the more basic models but just let me know how I can help.

Is all the logical code that is throwing this error in index.js? If so, I am going to start looking at this code and see if I can get it working for other models. In the config.json, we could just have a flag (0 or 1) for sensor-less models. Thoughts?

P.S. Checked my global key using Charles, and it's also the same.

Thanks!

mylesagray commented 6 years ago

Sorry for the hiatus, I actually just moved house and have been redoing all my smart home stuff, so I can pay some attention to this again!

Yes it’s all in index.js, it’s hacky, but it works.

There are two issues you may be able to help me with, one is a unit with no sensors, the other is multiple BlueAir devices - as currently the plugin only takes the first device returned (index 0) and will populate that.

The logic will need extended to allow for multiple devices, histories and such but should be fairly trivial.

I think a flag is an easy stop-gap, however a better solution (IMO) is a check to see if the returned JSON includes those variables at all, if not, assume sensorless and just don’t create the extra HomeKit devices.

Sound like a plan? On Sun, 28 Oct 2018 at 20:57, ndlaham notifications@github.com wrote:

Hey mylesgray, thanks for all your work on this. I have been trying to get this to work too, but I got as far as d3rw1n and ran into the same problem because I also have the no-sensor Blueair purifier (Classic 205).

I'm pretty new to homebridge (I have 1 other plugin running), but have I do have some limited programming experience so I would be happy to help and provide any results if this is still something you think you are going to try and update. If not, I would be happy to help but would most definitely need some direction. I have 2 Blueair machines without sensors so I could definitely assist in troubleshooting these logical issues on the more basic models but just let me know how I can help.

Is all the logical code that is throwing this error in index.js? If so, I am going to start looking at this code and see if I can get it working for other models. In the config.json, we could just have a flag (0 or 1) for sensor-less models. Thoughts?

P.S. Checked my global key using Charles, and it's also the same.

Thanks!

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub https://github.com/mylesgray/homebridge-blueair/issues/12#issuecomment-433740750, or mute the thread https://github.com/notifications/unsubscribe-auth/AAlMTButLgSJJHk4dYKpod9bWOiBEQFFks5uphokgaJpZM4T_9bO .

ndlaham commented 6 years ago

Yes, that makes sense. Plus, if you are able to build in multi-device support, I think your solution for the undefined sensor variables would allow someone to have both a sensor model, and a sensorless model on the same configuration. I am realizing now that by using a flag, you are locking yourself in to one type of model, or the other, so I like your suggestion.

Also, I have 2 sensorless models in my home, so I can at least help test out the multiple device support if you are able to determine how to do it.

Are the following variables everything that is looking for a return on a sensor-enabled model, or am I missing something?

measurements.pm measurements.tmp measurements.hum measurements.pm measurements.co2 measurements.airquality measurements.airqualityppm measurements.voc measurements.allpollu

I'm new to this code, so please forgive me if I am not making total sense. I am a pretty quick learner but my background with writing logic is mostly with SQL so I'm kind of picking this up as I go.

ndlaham commented 6 years ago

Ok I have some news. I stumbled upon this by chance from another poster, but I removed the line of code from line 241 of index.js - this.getLatestValues(function(){});

When I ran homebridge after this, I was able to get the sensorless model to connect and show up in HomeKit. I only did some basic testing, but so far it appears I have general functionality and it's working. I will report back further findings as I can dig into this, but if the only line that needs to be ignored is the above, it should be fairly simple to write something to ignore that code based on if those variables are present or not. Am I making sense?

mylesagray commented 6 years ago

Alright, I finally have some time to work on this for you guys.

@ndlaham - Perhaps you can do me a favour and get a dump of the JSON back from the query for your model so I can see what I need to filter on for sensorless models?

I have a POSTman collection built that will pull back all the relevant info:
https://www.getpostman.com/collections/1a8ff6c577e58a7b6f90

How to import a postman collection into postman: https://developer.ft.com/portal/docs-start-install-postman-and-import-request-collection

I have the details on how to run the collection here: https://github.com/mylesgray/homebridge-blueair#api-research

What I would like you to do is populate your postman environment as in the above link, then run through the following queries in order:

  1. Global BlueAir Auth
  2. Get API host name
  3. Login to API
  4. Get user details
  5. Get BlueAir details
  6. Get BlueAir info
  7. Get BlueAir last measurements

What I need is the output from the last query, mine (with sensors) looks like this:

{
    "uuid": "myuuidhere",
    "start": 1542299758,
    "end": 1542299758,
    "sensors": [
        "time",
        "pm",
        "tmp",
        "hum",
        "co2",
        "voc",
        "allpollu"
    ],
    "units": [
        "s",
        "ugm3",
        "C",
        "pc",
        "ppm",
        "ppb",
        "%"
    ],
    "datapoints": [
        [
            1542299758,
            6.0859985,
            17.523,
            58.513,
            886,
            245,
            23.228855
        ]
    ]
}

I am expecting your output to have "sensors": [], but just need confirmation, if this is the case the checking should be trivial :)

ndlaham commented 6 years ago

I'm happy to help. Let me read through your Postman instructions and I will see if I have any questions. That is totally foreign to me right now, but I'm sure I can figure it out once I dig into it and read through your links in a little closer detail. I will try this tonight.

ndlaham commented 6 years ago

mylesgray, here is what I came up with and my output posted below.

What I take from this is "sensors": [] isn't empty, and has all the parameters that your output does, but my "datapoints": [] is empty.

I'm pretty sure I ran your postman collection correctly. I added the environment just as you have it, and the only values I had to populate was user, password, and api key, right? The rest of the keys are auto populated, so I'm assuming that means I don't enter any values.

And each query I ran in Postman returned results. The user details, and blueair details pulled my correct information that I recognize, so I'm pretty sure the below output is correct. If it sounds like I did something wrong just let me know and I can try again.

{
    "uuid": "2503576703009480",
    "start": 0,
    "end": 0,
    "sensors": [
        "time",
        "pm",
        "tmp",
        "hum",
        "co2",
        "voc",
        "allpollu"
    ],
    "units": [
        "s",
        "ugm3",
        "C",
        "pc",
        "ppm",
        "ppb",
        "%"
    ],
    "datapoints": []
}
mylesagray commented 6 years ago

Excellent thanks, that’s very helpful, strange they report the sensors even though it doesn’t have them, but still - I can test for presence of datapoints and not assume they are present.

Leave it with me :)

ndlaham commented 6 years ago

No problem, thank you! Also, I saw in one of the outputs for what multiple devices connected looks like as well if that helps you figure out how to handle multiple devices. This is from Get BlueAir details:

[
    {
        "uuid": "2503576703009480",
        "userId": 12905,
        "mac": "ACCF23D96A70",
        "name": "Master Bedroom"
    },
    {
        "uuid": "27035767232094C0",
        "userId": 12905,
        "mac": "ACCF23DFC8AA",
        "name": "Family Room"
    }
]
mylesagray commented 6 years ago

Excellent thank you man! On Fri, 16 Nov 2018 at 13:39, ndlaham notifications@github.com wrote:

No problem, thank you! Also, I saw in one of the outputs for what multiple devices connected looks like as well if that helps you figure out how to handle multiple devices. This is from Get BlueAir details:

,,, [ { "uuid": "2503576703009480", "userId": 12905, "mac": "ACCF23D96A70", "name": "Master Bedroom" }, { "uuid": "27035767232094C0", "userId": 12905, "mac": "ACCF23DFC8AA", "name": "Family Room" } ] ,,,

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub https://github.com/mylesgray/homebridge-blueair/issues/12#issuecomment-439395618, or mute the thread https://github.com/notifications/unsubscribe-auth/AAlMTB3WsW9I5n40bnukLsFZHFZ83DaYks5uvsAWgaJpZM4T_9bO .

mylesagray commented 6 years ago

@ndlaham Changes made and pushed to the develop branch here: https://github.com/mylesgray/homebridge-blueair/tree/develop

If you don't mind testing, install git on your Homebridge machine if you haven't already got it: https://git-scm.com/downloads

Then clone the testing branch to your Homebridge machine: git clone -b develop https://github.com/mylesgray/homebridge-blueair.git

And run Homebridge with that path included as a plugin: DEBUG=* homebridge -D -P \path\to\plugin\here

Let me know if it's working for you or if you need some more help on testing!

M

ndlaham commented 6 years ago

Done! It appears to have booted right up without any problems. I'm connected, and using HomeKit as I type to adjust the fan speed, and toggle power on and off.

One thing I noticed a few weeks ago when I was tinkering with your version 0.3.1 code and commented out line 241 - I had it working then, but homebridge did crash once during my testing of that. Not sure why, but probably because my change was just a band-aid. So I will continue to test v0.3.2, and see if I can break it. But so far, so good. Thanks a lot for this. I'm sure the other sensorless people will be happy too.

P.S. I did notice the 2nd air purifier didn't pull in though, but I am pretty sure you have not even looked at that yet and v0.3.2 is just for testing sensorless. If you did do something with it though, I just wanted to check in case I a might be doing something wrong or need to add the accessory in HomeKit or something like that.

Let me know if you need me to try anything else or test something for you.

ndlaham commented 6 years ago

Hey mylesgray,

I’ve been testing for about a week and overall, it’s running well with a single minor issue. I don’t think the issue I’m experiencing is related to the sensorless logic and it’s not a big deal anyway, but thought I’d share in case you had any ideas.

Sometimes when I change fan speed, it can get a little glitchy. For example, if I lower the fan speed, I’ll see the actual fan speed reduce physically, but then the HomeKit UI will quickly switch or change back to a fan speed that doesn’t match the physical speed of the fan. It almost jumps around and then adjusting the speed again doesn’t make sense. It seems to correct itself sometimes but the fan will sometimes respond in a way I don’t expect.

Have you had any issues like this?

With that, I’m still very happy I can control this device now and appreciate the work you have put in.

P.S. If you have any thoughts or plans on how to implement multiple units, I’m ready to help testing on my end if you get time to work on it. I wish I knew more js to be able to help more.

mylesagray commented 6 years ago

@ndlaham Excellent, I've published 0.3.2 to npm, so will be available though npm install homebridge-blueair.

As for the other (glitchiness) issue, can you maybe capture a video and open another issue, I can't repro?

I am closing this issue now as the senseless logic has been added, but I opened another issue to track the multiple device control (#15) I would appreciate your help with that once I get some code to make it work (today or tomorrow).