AdyRock / com.switchbot

GNU General Public License v3.0
11 stars 6 forks source link

Meter Pro met CO2 #149

Open H159320 opened 6 days ago

H159320 commented 6 days ago

I am not receiving any data from the Meter Pro with CO2. I have sent you the log files. I don’t understand how this can happen. In the Switchbot app, I can see everything, but not in Homey. I get various error messages such as ‘invalid token’ or an authorization error. Is there anything that can be done about this? I bought this meter to start flows.

AdyRock commented 6 days ago

SwitchBot has been having server issues, so the token issues could be due to that.

The updates are pushed via a webhook when the data changes, but I have noticed that it doesn't push every change. However, mine has been working and updates regularly.

Everything looks OK in the logs, but they are quite short. Could you set the level to Webhook and then clear the log. Wait for about 10 minutes, and then check again to see if anything has been received.

H159320 commented 6 days ago

How do I do this?

Is it obligated to have a hub for this to work? Or can homey read the BLE directly?

AdyRock commented 6 days ago

It only works with a hub as the BLE information has not been provided and I haven't had time to try and reverse engineer it.

AdyRock commented 6 days ago

Use the same procedure to send the logs as before, but just change the drop list to show Webhook

H159320 commented 6 days ago

Will it eventually work without a hub? :)

H159320 commented 6 days ago

I just sended you the webhook log

AdyRock commented 6 days ago

If the BLE protocol is published or if I get time to reverse engineer the data, then I will add it, but I have no idea when that will be.

How long was the log active before you sent it?

H159320 commented 6 days ago

A couple of minutes. I deleted all the logs and restarted the app. Then I opened the log again and sent it.

But I thought SwitchBot was an official partner? Can’t this be arranged in consultation with them? This should save you time and ensure that we can use the application.

AdyRock commented 6 days ago

Can you let it run for about 10 minutes or more and then send the logs.

I have a contact at SwitchBot, but that's only for the API. The BLE protocols are very unofficial, so I don't have support for that.

Basically, I created the app and then transferred it to a SwitchBot account when Athom wanted it to be official. However, I continue to maintain the app in my spare time, but with support from a dedicated contact higher up in the SwitchBot organisation.

H159320 commented 6 days ago

Oh really. Sounds cool. Thanks for your hard work. I and, of course, the other users appreciate your work a lot. I will send the new log in 10 minutes.

Is there a chance that you will reverse engineer the BLE? This is because Switchbot is the only supplier of a good NDIR sensor at a fair price. Very interesting for hobbyists who want to improve their living environment at home.

AdyRock commented 6 days ago

I will probably have a crack at decoding the BLE data at some point.

So it seems no Webhook data is being received. I presume your Homey has a reliable Internet connection? It could just be that the values aren't changing, so they are not being sent. Screenshot_20241126_121935_Homey.jpg

As you can see, mine are infrequent.

You could also try running the repair option to see if that fixes the other errors as it shouldn't have those.

H159320 commented 6 days ago

I have tried all of this. But do you use the hub? I notice that the CO2 meter only updates to the app when you press the button on the device for 2 seconds. Is it different for you

AdyRock commented 6 days ago

Yes, I use a hub. I seem to remember a setting in the SwitchBot mobile app for notification time, but as I am not at home, I can't get into the settings.

H159320 commented 6 days ago

Hmm, can you please let me now if you find such a thing.

Everything is now a gain for me, because now I can’t do anything with it in terms of managing flows

kiselio commented 3 days ago

Hello @AdyRock

I've parsed the data for the SwitchBot Meter Pro and SwitchBot Meter Pro (CO2) and identified the correct bytes and conversion logic that you would need to add these devices to Homey WITHOUT a hub (BLE advertisements only).

1. Temperature (Bytes 8–9) Interpretation: Byte 8: Lower 4 bits (0x0F) = Decimal part of temperature. Byte 9: Upper 7 bits (0x7F) = Whole number of temperature. Negative Flag: High bit (0x80) in Byte 9. If set, temperature is negative. FORMULA EXAMPLE: Temperature = (Byte 9 & 0x7F) + (Byte 8 & 0x0F) * 0.1 If Byte 9 & 0x80, Temperature = -Temperature

2. Humidity (Byte 10) Interpretation: Lower 7 bits (0x7F) = Humidity percentage. FORMULA EXAMPLE: Humidity = Byte 10 & 0x7F

3. Battery (Byte 2, from service_data) Interpretation: Lower 7 bits (0x7F) = Battery percentage. FORMULA EXAMPLE Battery = Byte 2 & 0x7F

4. CO2 (Bytes 13–14) Interpretation: 16-bit big-endian integer = CO2 ppm value. FORMULA EXAMPLE CO2 = (Byte 13 << 8) | Byte 14

The bytes are identical for both versions, simply the base version doesn't advertise CO2 at bytes 13-14. Please use this to add support for both devices in the Homey App.

Let me know if you need anything else.

AdyRock commented 2 days ago

@kiselio If you have the Meter Pro without the CO2, could you let me know what the first byte of the service data is? For the MP with CO2 it is 35 and is the intensifier for the device type, so I'm wondering if the MP without the CO2 is different?

kiselio commented 2 days ago

Yes, I have both variants. The first byte of the service data for the Meter Pro without CO2 is 0x34 (decimal: 52), while for the Meter Pro with CO2, it is 0x35 (decimal: 53). switchbot-meter-pro-co2-review-side-to-side-right-side-view

AdyRock commented 15 hours ago

I have published a new test version that has BLE support for the Meter Pro and Meter Pro CO2.

kiselio commented 14 hours ago

I managed to pair the Meter Pro (CO2) with some difficulty. Pressing the button several times to force a payload to be sent resulted in the device being discovered in BLE mode by the Homey Pro after several tries. As is, it won't get discovered in the short scanning window the app gives you.

HOWEVER, I cannot pair the Meter Pro (Without CO2) no matter what I do. Change distance, swap new batteries, force a payload, set in pairing mode. Nothing works.

I confirmed the following:

  1. Byte data I gave you is 100% correct.
  2. Byte data handling logic is 100% correct.
  3. Both devices advertise on regular intervals. Verified with an ESP32 board in ESPHome.

Here's a screenshot of the CO2 working in BLE mode:

Screenshot_20241202_080858_Homey copy Screenshot_20241202_082119_Homey copy

H159320 commented 12 hours ago

I don’t understand how you can take these screenshots if you can’t connect the meter?

kiselio commented 12 hours ago

This is the Meter Pro (CO2) which connect fine. I cannot connect the Meter Pro (WITHOUT CO2).

You misread what I wrote.

H159320 commented 12 hours ago

With or without the hub?

kiselio commented 12 hours ago

No hub, direct BLE connection

H159320 commented 11 hours ago

My CO2 meter still doesn't provide any data. Only when I press the physical button does the Switchbot app synchronize. Homey doesn't receive anything. Any idea what else I could do?

kiselio commented 11 hours ago

Install the Test version of the app, re-pair the device and it will push data without issues. Make sure you press the button on the device every 1 second or so during pairing so it gets discovered.

H159320 commented 11 hours ago

Where do I get the test version?

AdyRock commented 4 hours ago

https://homey.app/en-gb/app/com.switchbot/SwitchBot/test/

Make sure you install the new Meter Pro with CO2 (BLE) device.

AdyRock commented 4 hours ago

I have noticed these meters only broadcast BLE data when value changes. Homey, has a bug that makes it ignore any results passed back during the pairing if it takes more than 10 seconds, so that is the longest the app can scan for devices, Using my ESP32 bridge helps as it caches the last data from each device, so the reply during the pairing is immediately available.

H159320 commented 4 hours ago

What is the refresh rate of the CO2 meter on BLE? Mine is not refreshing. And when I try to read the status, is says: Error: No OAuth2 Client Found

AdyRock commented 1 hour ago

Reading the status is for the cloud devices (connected to a hub), so you see that error because you haven't logged in to the cloud.

The app polls the BLE every 15 seconds on an HP2023 and 30 seconds on an HP2019. However, the Meter Pro appears only to publish data when a value changes. I'm not sure if that means Homey can miss updates as I don't know the internal workings of Homey.

My ESP32 hub constantly monitors the BLE broadcast and caches them, plus it pushes the updates to Homey via WiFi.