asednev / homebridge-plugin-govee

Govee H-series Thermometer Hygrometer plugin for Homebrige.
Apache License 2.0
52 stars 9 forks source link

Not detecting thermostat on Raspberry Pi #1

Closed apexad closed 4 years ago

apexad commented 4 years ago

Describe Your Problem: I have a 5075, this plugin is not detecting it/not working Thermometer is otherwise working fine and shows data in the Govee app The Thermostat is less than 10 feet away form the Raspberry Pi running homebridge

Logs:

discovered a4c138bc6239 a4c138bc6239 a4:c1:38:bc:62:39 disconnected -63
invalid peripheral, scan for another

Many of these over and over again...

Plugin Config:

{
            "name": "Govee Thermo",
            "batteryThreshold": 25,
            "debug": true,
            "platform": "GoveeHomebridgePlugin"
        }

Screenshots: None Environment:

asednev commented 4 years ago

Hi @apexad,

You can start by cloning https://github.com/asednev/govee-bt-client and debugging the client to understand where the gap is. The error you're getting is due to validPeripheral evaluating to false in the client: https://github.com/asednev/govee-bt-client/blob/master/index.ts#L9

Your MAC address looks like a match, so the problem is likely with the manufacturerData from advertisement.

    const hex = advertisement.manufacturerData.toString('hex');

    // add this line to debug:
    console.log('manufacturerData', hex);

    if (!hex.includes(h5075_uuid_rev)) { return false; }
apexad commented 4 years ago

This is the full log:

=== start discovery
discovered 8263c522f7cf48cab27dbf0405927198 8263c522f7cf48cab27dbf0405927198  disconnected -66
manufacturerData 88ec000359324100
8263c522f7cf48cab27dbf0405927198: 88ec000359324100
{
  uuid: '8263c522f7cf48cab27dbf0405927198',
  address: '',
  model: 'GVH5075_6239',
  battery: 65,
  humidity: 44.2,
  tempInC: 21.9442,
  tempInF: 71.49956,
  rssi: -66
}
discovered 8263c522f7cf48cab27dbf0405927198 8263c522f7cf48cab27dbf0405927198  disconnected -66
manufacturerData 4c000215494e54454c4c495f524f434b535f48575075f2ffc2
invalid peripheral, scan for another
discovered 8263c522f7cf48cab27dbf0405927198 8263c522f7cf48cab27dbf0405927198  disconnected -57
manufacturerData 88ec0003554a4100
8263c522f7cf48cab27dbf0405927198: 88ec0003554a4100
{
  uuid: '8263c522f7cf48cab27dbf0405927198',
  address: '',
  model: 'GVH5075_6239',
  battery: 65,
  humidity: 44.2,
  tempInC: 21.8442,
  tempInF: 71.31956,
  rssi: -57
}
discovered 8263c522f7cf48cab27dbf0405927198 8263c522f7cf48cab27dbf0405927198  disconnected -57
manufacturerData 4c000215494e54454c4c495f524f434b535f48575075f2ffc2
invalid peripheral, scan for another
=== stop discovery
apexad commented 4 years ago

So, the above log is from my Mac, but homebridge running in raspberry pi. pi does not see the Govee thermostat currently despite being very close, but through a cabinet.

asednev commented 4 years ago

I was about to ask whether you ran it on Raspberry Pi. I never tested this setup on Raspberry Pi because I don't have one.

If you were to run homebridge on your Mac, I am pretty sure your Govee thermostat would be detected.

At this point I think it's best for you to continue debugging on your Raspberry Pi. You need advertisement with payload that starts with 88ec in order to decode readings. Could be something with the way your bluetooth module works or returns data.

apexad commented 4 years ago

manufacturerData 4c000215494e54454c4c495f524f434b535f48575075f2ffc2 is? Doing some debugging on my Raspberry Pi I am getting this:

discovered a4c138bc6239 a4c138bc6239 a4:c1:38:bc:62:39 disconnected -27
mData 4c000215494e54454c4c495f524f434b535f48575075f2ffc2
a4c138bc6239: 4c000215494e54454c4c495f524f434b535f48575075f2ffc2
{
  uuid: 'a4c138bc6239',
  address: 'a4:c1:38:bc:62:39',
  model: 'GVH5075_6239',
  battery: 84,
  humidity: 2.2,
  tempInC: 139.5022,
  tempInF: 283.10396,
  rssi: -27
}

...initially I thought it was maybe another Govee product I have (a LED light strip), but see the model number there? Obviously it's totally whack numbers as far as tempInC and tempInF though, so confused.

apexad commented 4 years ago

I don't see the other payload on Raspberry pi.

apexad commented 4 years ago

Alright, so I figured out how to get it working on Raspberry Pi. Apparently it is not broadcasting 'all' bluetooth events so the following is needed to change this behavior:

export NOBLE_REPORT_ALL_HCI_EVENTS=1

(Trying to figure out how to do that in javascript and not as an environment variable)

Then, it also required this change:

-const govee_bt_mac = "a4-c1-38";
+const govee_bt_mac = "a4:c1:38";

I'll investigate further, but otherwise will submit a PR soon. Closing this issue.

asednev commented 4 years ago

Thanks for sharing, I was concerned about - separator being too device specific. Indeed it is. If you don't follow up with PR in the next few days, I will take it upon myself to make the library more robust.

cargueta001 commented 4 years ago

Alright, so I figured out how to get it working on Raspberry Pi. Apparently it is not broadcasting 'all' bluetooth events so the following is needed to change this behavior:

export NOBLE_REPORT_ALL_HCI_EVENTS=1

(Trying to figure out how to do that in javascript and not as an environment variable)

Then, it also required this change:

-const govee_bt_mac = "a4-c1-38";
+const govee_bt_mac = "a4:c1:38";

I'll investigate further, but otherwise will submit a PR soon. Closing this issue.

Hello @apexad I was hoping you could provide some help with getting this plugin to run with RPI. I’m a novice with some of these commands/config setups but have Homebridge successfully running with about 5 plugins. I’d love to see your steps on how you achieved to get the Govee Thermostat sensors in Homebridge. Thanks in advance!

apexad commented 4 years ago

@cargueta001 I’ve already fixed the underlying client code this homebridge plugin uses. @asednev should be updating the homebridge plugin soon.

asednev commented 4 years ago

@cargueta001 I just published an update, go ahead and update your Homebridge Govee plugin to version 1.0.3 and see if that works with your Raspberry Pi.

cargueta001 commented 4 years ago

Thanks @asednev I will give it a try later today. Also, I need to make sure that I’m adding the plug-in config data to the config file correct?

asednev commented 4 years ago

@cargueta001 if you install your Homebridge plugins using web UI, there is no need to manipulate config file directly. You can open plugin settings on the Plugins page. The plugin doesn't require any configuration unless you want to enable debug logs or change low battery threshold.

cargueta001 commented 4 years ago

Unfortunately @asednev I’m running into some errors. I’m attaching two screenshots that show my log and also the errors during install. Any suggestions would be great 👍🏻 CBBF4BA2-55DE-467D-8AB7-51646DC06842 A2B8F2F6-15C1-4C72-B7EF-890F97EC9F1B

apexad commented 4 years ago

@cargueta001 Looks like you may not have installed the pre-reqs:

sudo apt-get install bluetooth bluez libbluetooth-dev libudev-dev

cargueta001 commented 4 years ago

@apexad I’ve verified that it’s installed and also tried to install it globally and still no luck installing the plugin. 2B4332AA-0B65-4B35-BCC0-6AE474A87835

apexad commented 4 years ago

Try sudo setcap cap_net_raw+eip $(eval readlink -f $(which node)) which sets node t be able to use bluetooth by my understanding...

apexad commented 4 years ago

Also, jut to confirm, run the latest version of this plugin which will include latest govee-bt-client

cargueta001 commented 4 years ago

Try sudo setcap cap_net_raw+eip $(eval readlink -f $(which node)) which sets node t be able to use bluetooth by my understanding...

This unfortunately didn’t yield anything 🤷🏻‍♂️

cargueta001 commented 4 years ago

Try sudo setcap cap_net_raw+eip $(eval readlink -f $(which node)) which sets node t be able to use bluetooth by my understanding...

This unfortunately didn’t yield anything 🤷🏻‍♂️

I tried the plugin once again and took some screenshots of the various errors that pop up. Hope this is helpful and thanks for bearing with any misunderstandings on my part. 7DC18EC9-02FC-49A1-9F37-4AD810C97704 73526EDD-8E2C-4308-B014-2DD1B4DAABC1 3F085826-CFEF-4F45-8350-BB30320779C7 6573D347-D1FC-4956-814F-203C5711C49F B16FAFBF-7BAA-4DEB-A386-3AA8EC5116D6 817F4B4A-E662-4FEB-A56F-323A72015328

apexad commented 4 years ago

Are you using HOOBS?

cargueta001 commented 4 years ago

Are you using HOOBS?

Not using HOOBS. My setup is with Docker Homebridge by Oznu.

asednev commented 4 years ago

Errors definitely suggest there is something with dependencies for noble. Basically some of the dependencies were not built for the architecture you're using.

Even if you get past all of the errors, you will need to figure out how to expose your bluetooth module to docker container. That may require non-trivial manipulations with Docker.

Unfortunately I don't have a system running on arm to help you with that. Maybe after new Mac comes out for arm architecture.

apexad commented 4 years ago

I agree with @asednev that using Docker here presents a different situation. I am not familiar with Docker in a way that I could help. I would suggest going to the homebridge discord to ask for general help on getting noble/Bluetooth working in Docker.