theengs / decoder

Efficient, portable and lightweight library for Internet of Things payload decoding.
https://decoder.theengs.io
GNU General Public License v3.0
119 stars 38 forks source link

Include decoding support for SwitchBot Curtain 3 #469

Closed mxndtaylor closed 8 months ago

mxndtaylor commented 8 months ago

Is your feature request related to a problem? Please describe. Sort of? I'm trying to use TheengsGateway to read/write data to a SwitchBot Curtain 3, and the data is not coming back decoded.

Describe the solution you'd like Given I am running the gateway with decoding on, and there is a SwitchBot Curtain 3 in detectable range When I look at the MQTT output for the SwitchBot device's topic Then I should see decoded information

Describe alternatives you've considered I have not considered very many alternatives, but I did try to get this python script to work, which it didn't. Even if it had, it would have been a development effort and a half to get working with MQTT as I am not very experienced with it.

Additional context I ran this to get some sample undecoded data packets from 2 SwitchBot Curtain 3 devices:

python -m TheengsGateway -H localhost -padv 1

And using MQTT-Explorer, I found these events:

{
  "manufacturerdata": "6909e77d785a859e1803641204014f", 
  "id": "<MACADDR>", 
  "rssi": -60, 
  "servicedatauuid": "fd3d",
  "servicedata": "7bc04f641204", 
  "mfr": "Woan Technology (Shenzhen) Co., Ltd."
}
{
  "manufacturerdata": "6909f8552ba34b38ee016311040157", 
  "id": "<MACADDR>", 
  "rssi": -69, 
  "servicedatauuid": "fd3d", 
  "servicedata": "7b4057631104", 
  "mfr": "Woan Technology (Shenzhen) Co., Ltd."
}

For context, I'm coming from this openhab forum thread, where it was suggest to me to provide the sample undecoded data json. You can see my original reply just above the linked one, which has further details on set up and process for what I was trying to do.

If this is a good first issue and anyone would be willing to help guide me a little, I'd love to contribute to the solution, or at least understand how to make similar changes from sample data.

DigiH commented 8 months ago

Hi @mxndtaylor

Same guy here who answered you in the OpenHAB forum, so all clear :)

Thanks for the Curtain3 advertising data.

It seems to be only a small change again for the Curtain 3, and adjusting the existing Curtain decoder I am getting

{ "manufacturerdata": "6909e77d785a859e1803641204014f", "id": "", "rssi": -60, "servicedatauuid": "fd3d", "servicedata": "7bc04f641204", "mfr": "Woan Technology (Shenzhen) Co., Ltd." }

{\"brand\":\"SwitchBot\",\"model\":\"Curtain\",\"model_id\":\"W070160X\",\"type\":\"WCVR\",\"acts\":true,\"moving\":false,\"position\":100,\"calibrated\":true,\"lightlevel\":1,\"batt\":79}

{ "manufacturerdata": "6909f8552ba34b38ee016311040157", "id": "", "rssi": -69, "servicedatauuid": "fd3d", "servicedata": "7b4057631104", "mfr": "Woan Technology (Shenzhen) Co., Ltd." }

{\"brand\":\"SwitchBot\",\"model\":\"Curtain\",\"model_id\":\"W070160X\",\"type\":\"WCVR\",\"acts\":true,\"moving\":false,\"position\":99,\"calibrated\":true,\"lightlevel\":1,\"batt\":87}

Would these be correct?

Maybe we can try and verify a few more datasets, possibly with the curtains moving or at half open positions or higher light levels.

mxndtaylor commented 8 months ago

Hey @DigiH 👋😊

Yeah, these are 2 different devices, recorded at fully or nearly fully closed position.

They don't have any light sensor attached, as that's add-on I didn't opt for, so not sure if I'll be able to get you different data there.

I can maybe try during the day tomorrow, just to see if there's any change to it.

The rest seems fairly doable though, so should be able to get you that soon, if not tonight (US time).

DigiH commented 8 months ago

They don't have any light sensor attached, as that's add-on I didn't opt for, so not sure if I'll be able to get you different data there.

I didn't realise that the light level meter was a separate add-on for the Curtain models, but as the possible values are between 1-10 I assume the current 1 being the lowest level is fine if the meter is not attached ;)

mxndtaylor commented 8 months ago

I didn't realise that the light level meter was a separate add-on for the Curtain models

Well, I'm not actually 100% sure of this :)

I had thought they were advertising their solar panel add-on as both a charger and light sensor, but I'll see about getting some data in full daylight and we can see for sure haha.

I ran the curtains through a calibration cycle, so ideally these somewhat match:

  1. position ~ 100 (closed), moving = false, calibrated = false
  2. position ~ 50 (semi open), moving = true, calibrated = false
  3. position ~ 0 (fully open), moving = false, calibrated = false
  4. position ~ 50 (semi open), moving = true, calibrated = false
  5. position ~ 100 (closed), moving = false, calibrated = true

But I'm only really guessing just based on where the devices were around when I saw the data update, here's the events:

{"manufacturerdata": "6909f8552ba34b38f1080011040157", "id": "<MACADDR1>", "rssi": -78, "servicedatauuid": "fd3d", "servicedata": "7b0057001104", "mfr": "Woan Technology (Shenzhen) Co., Ltd."}
{"manufacturerdata": "6909f8552ba34b38f2008011040157", "id": "<MACADDR1>", "rssi": -63, "servicedatauuid": "fd3d", "servicedata": "7b0057801104", "mfr": "Woan Technology (Shenzhen) Co., Ltd."}
{"manufacturerdata": "6909f8552ba34b38f7016411060157", "id": "<MACADDR1>", "rssi": -75, "servicedatauuid": "fd3d", "servicedata": "7b4057e41106", "mfr": "Woan Technology (Shenzhen) Co., Ltd."}
{"manufacturerdata": "6909f8552ba34b38f7016411060157", "id": "<MACADDR1>", "rssi": -68, "servicedatauuid": "fd3d", "servicedata": "7b4057641106", "mfr": "Woan Technology (Shenzhen) Co., Ltd."}
{"manufacturerdata": "6909f8552ba34b38f4000011030157", "id": "<MACADDR1>", "rssi": -65, "servicedatauuid": "fd3d", "servicedata": "7b0057001103", "mfr": "Woan Technology (Shenzhen) Co., Ltd."}
{"manufacturerdata": "6909e77d785a859e1a02001204014f", "id": "<MACADDR2>", "rssi": -79, "servicedatauuid": "fd3d", "servicedata": "7b804f001204", "mfr": "Woan Technology (Shenzhen) Co., Ltd."}
{"manufacturerdata": "6909e77d785a859e1a02001204014f", "id": "<MACADDR2>", "rssi": -79, "servicedatauuid": "fd3d", "servicedata": "7b804f001204", "mfr": "Woan Technology (Shenzhen) Co., Ltd."}
{"manufacturerdata": "6909e77d785a859e1b02801204014f", "id": "<MACADDR2>", "rssi": -67, "servicedatauuid": "fd3d", "servicedata": "7b804f801204", "mfr": "Woan Technology (Shenzhen) Co., Ltd."}
{"manufacturerdata": "6909e77d785a859e1e02801203014f", "id": "<MACADDR2>", "rssi": -72, "servicedatauuid": "fd3d", "servicedata": "7b804f801203", "mfr": "Woan Technology (Shenzhen) Co., Ltd."}
{"manufacturerdata": "6909e77d785a859e2003641206014f", "id": "<MACADDR2>", "rssi": -60, "servicedatauuid": "fd3d", "servicedata": "7bc04f641206", "mfr": "Woan Technology (Shenzhen) Co., Ltd."}
{"manufacturerdata": "6909e77d785a859e2103631206014d", "id": "<MACADDR2>", "rssi": -78, "servicedatauuid": "fd3d", "servicedata": "7bc04d631206", "mfr": "Woan Technology (Shenzhen) Co., Ltd."
DigiH commented 8 months ago

Thanks for the updated data. Everything looks fine apart from the position (around 50) when moving.

As I'm not sure if the correct position is actually being continually braodcast while moving with any of the curtain models, would you be able just to add one more reading with the curtains around half open, but not moving?

Then all should be fine for the Curtain 3 decoder changes to be merged.

Thanks

mxndtaylor commented 8 months ago

Huh, I wouldn't have expected that. I think this one should be around 50:

{"manufacturerdata": "6909e77d785a859e0d03391204014f", "id": "<MACADDR>", "rssi": -72, "servicedatauuid": "fd3d", "servicedata": "7bc04f391204", "mfr": "Woan Technology (Shenzhen) Co., Ltd."}

Just in case the position wasn't being updated because of the calibration state, I added a couple more of it in motion now that it's calibrated.

{"manufacturerdata": "6909e77d785a859e1503971204014e", "id": "<MACADDR>", "rssi": -71, "servicedatauuid": "fd3d", "servicedata": "7bc04e971204", "mfr": "Woan Technology (Shenzhen) Co., Ltd."}
{"manufacturerdata": "6909e77d785a859e1803931204014e", "id": "<MACADDR>", "rssi": -74, "servicedatauuid": "fd3d", "servicedata": "7bc04e931204", "mfr": "Woan Technology (Shenzhen) Co., Ltd."}
{"manufacturerdata": "6909e77d785a859e1f03001204014e", "id": "<MACADDR>", "rssi": -77, "servicedatauuid": "fd3d", "servicedata": "7bc04e001204", "mfr": "Woan Technology (Shenzhen) Co., Ltd."}
{"manufacturerdata": "6909e77d785a859e2903271205014e", "id": "<MACADDR>", "rssi": -66, "servicedatauuid": "fd3d", "servicedata": "7bc04e271205", "mfr": "Woan Technology (Shenzhen) Co., Ltd."}

Not the end of the world if it doesn't update the position live.

Based on what you've said, I guess the device might be reporting the position as the "target" position while it's in motion? In the mobile app, for instance, when you click the "close" button it immediately updates the UI to show that the Curtain is already closed, so maybe that data is coming directly from the advertising data, rather than just a front-end piece of logic.

DigiH commented 8 months ago

Huh, I wouldn't have expected that. I think this one should be around 50:

{"manufacturerdata": "6909e77d785a859e0d03391204014f", "id": "<MACADDR>", "rssi": -72, "servicedatauuid": "fd3d", "servicedata": "7bc04f391204", "mfr": "Woan Technology (Shenzhen) Co., Ltd."}

This results in

{"brand":"SwitchBot","model":"Curtain (2/3)","model_id":"W070160X","type":"WCVR","acts":true,"moving":false,"position":57,"calibrated":true,"lightlevel":1,"batt":79}

so looking fine :)

Not the end of the world if it doesn't update the position live.

Based on what you've said, I guess the device might be reporting the position as the "target" position while it's in motion?

And thinking about it more, Gateway would have to constantly and repeatedly scan to be able to get any live updating positions while the curtain is moving, and even when a position would be reported by that time it would already have moved on. So it makes sense that there is no live updating position broadcasts.

Merging the Curtain 3 adjustments now.

Looks like you installed Gateway through pip, correct?

After the merge you could build and intall your own updated version of Theengs Decoder fromk the development srouce, by following

https://decoder.theengs.io/use/python.html#installing-a-development-version

or wait until we will release a new Theengs Decoder version by the weekend.

DigiH commented 8 months ago

Closing, as with Theengs Decoder release v1.6.7 this amended Curtain decoder is included.

mxndtaylor commented 8 months ago

thanks for the quick turnaround!

As a note, I'm trying to place this on the Raspberry Pi 4, and it comes pre-installed with pip major version 20. Neither the development build or the published version could be installed on that, I had to upgrade pip (to major version 23), after which the published pypi version started working.

Maybe there was something else was also contributing to the errors, but was just thinking that it might be good to add some notes about minimum versions of pip, setuptools etc. for installing the library.

If you think that'd be valuable at all, I can open an issue for it, maybe try to contribute to that sort of effort myself? Let me know :)

mxndtaylor commented 8 months ago

Otherwise, just confirming that it's now working for me after upgrading my version of decoder: image

DigiH commented 8 months ago

@koenvervloesem - what do you say about additional pip installation requirement/notes?

@mxndtaylor - you can also have a look at this thread, about controlling SwitchBot Curtsain, but only currently possible with OpenMQTTGateway, and keeping in mind that there is still an issue with concurrently sent commands.

https://github.com/1technophile/OpenMQTTGateway/issues/1412

koenvervloesem commented 8 months ago

Ok, if the package is not installable with pip 20, it's definitely helpful to add this as a note in the installation instructions. Just a pip install --upgrade pip should be enough.