merdok / homebridge-miot

Homebridge plugin for devices supporting the Xiaomi miot protocol
MIT License
364 stars 62 forks source link

Question: Segment clean: bug or what am I doing wrong? #548

Closed CooperCGN closed 7 months ago

CooperCGN commented 7 months ago

Hi,

when I issue the following from the command line the robot starts as expected

miot send x.x.x.x -t 12345678901234567890123456789012 app_segment_clean '[{"segments": [16],"repeat": 3}]'

Now I am trying to set up a method button for this:

method: app_segment_clean
name: Küche saugen
params: '[{"segments": [16],"repeat": 3}]'

I get the following error: =MB= data for segment is not a number!

What am I doing wrong with the parameters?

merdok commented 7 months ago

Can you post a debug log where we can see the raw request? That would be helpful to identify where the issue might lay.

merdok commented 7 months ago

Btw, params should be an array not a string as in your case. Try to remove the ' chars around your entry.

CooperCGN commented 7 months ago

First, I came up with the ' chars because without them the direct call from the CLI didn't work. I removed them now but the error persists.

Here is the debug log:

[22/11/2023, 15:22:01] [homebridge-miot] [Roborock Unten] Executing method! Method: app_segment_clean Params: ["[{\"segments\": [16],\"repeat\": 3}]"]
[22/11/2023, 15:22:01] [homebridge-miot] [Roborock Unten] (Protocol) Call 10.0.1.16: app_segment_clean - ["[{\"segments\": [16],\"repeat\": 3}]"] - {}
[22/11/2023, 15:22:01] [homebridge-miot] [Roborock Unten] (Protocol) Start handshake 10.0.1.16
[22/11/2023, 15:22:01] [homebridge-miot] [Roborock Unten] (Protocol) 10.0.1.16 <- (2) {"method":"app_segment_clean","params":["[{\"segments\": [16],\"repeat\": 3}]"],"id":5}
[22/11/2023, 15:22:01] [homebridge-miot] [Roborock Unten] (Protocol) 10.0.1.16 <- !1�)KPS����l��z$��QN�K
[22/11/2023, 15:22:01] [homebridge-miot] [Roborock Unten] (Protocol) 10.0.1.16 -> Data: {"id":5,"error":{"code":-10005,"message":"data for segment is not a number"},"exe_time":11}
[22/11/2023, 15:22:01] [homebridge-miot] [Roborock Unten] (Protocol) 10.0.1.16 -> Message: {"id":5,"error":{"code":-10005,"message":"data for segment is not a number"},"exe_time":11}
[22/11/2023, 15:22:01] [homebridge-miot] [Roborock Unten] (Protocol) 10.0.1.16 <- Error during send! (-10005) data for segment is not a number | Request: {"method":"app_segment_clean","params":["[{\"segments\": [16],\"repeat\": 3}]"],"id":5}
[22/11/2023, 15:22:01] [homebridge-miot] [Roborock Unten] =MB= data for segment is not a number!
merdok commented 7 months ago

The params look incorrect to me. Can you post the whole config.json entry? If you are using the ui to add that, i would strongly recommend doing that in the config.json directly as the ui will probably not recognize that the params needs to be an array.

CooperCGN commented 7 months ago

Here is the config.json entry:

"methodButtons": [
                {
                    "method": "app_segment_clean",
                    "name": "Küche Test",
                    "params": [
                        "[{\"segments\": [16],\"repeat\": 3}]"
                    ]
                }
            ]
merdok commented 7 months ago

Yeah, this is incorrect. It should be simply:

"methodButtons": [
                {
                    "method": "app_segment_clean",
                    "name": "Küche Test",
                    "params": [
                        {"segments": [16],"repeat": 3}
                    ]
                }
            ]
CooperCGN commented 7 months ago

Thank you, it is working now. Only thing I realized is that I can't use the UI of the Plugin anymore, as it overwrites the params fields and leaves them empty. After saving it removed the params section completely.

merdok commented 7 months ago

Yeah, well this is quite tricky. The best solution would be to remove it from the ui completely as it can get anyway rather complex. You could also try and play a little bit with the config.schema.json which is in the plugin install directory and remove the type from the params property

            "methodButtons": {
              "title": "Method buttons",
              "type": "array",
              "items": {
                "type": "object",
                "properties": {
                  "method": {
                    "title": "method",
                    "type": "string",
                    "required": true
                  },
                  "name": {
                    "title": "name",
                    "type": "string",
                    "required": false
                  },
                  "params": {
                    "title": "params",
                    "type": "array",
                    "items": {
                      "type": "string"
                    },
                    "required": false
                  }
                }
              },
              "required": false
            },

The thing is the items type could be json any type, but i guess then if you remove it then it cannot be rendered in the ui anymore.

CooperCGN commented 7 months ago

Sorry for the late reply but I was fiddling around with the plugin the last few days creating some enhanced automations in combination with other Homebridge stuff to automate almost everything in the house.

Two questions left: the only thing which I don't get is, and this actually might belong in a seperate thread, is when I start something like zone or room cleaning (not the full thing) the switch in Robots HomeKit-Switch stays off the whole time. Is this how it is supposed to be?

What parameters is the plugin actually using to determine the dock status? Also the dock shows charging when it is at 100%.

If it is of any importance, we have a S8 and a S8 Pro Max

merdok commented 7 months ago

Both questions are bound to the device which you are using. In general to properly map statuses of devices (as each device can have different) a device class needs to be created. The plugin tries to determine automatically what status could be useful but this is just an estimation so it might be wrong. You would need to check if your devices have classes under -> lib/modules/robotcleaner/devices If not, then ones need to be created to properly map the status.

CooperCGN commented 7 months ago

I just checked but the devices model numbers are not listed. They are "roborock.vacuum.a51" for the S8 and roborock.vacuum.a70" for the S8 Pro Ultra.

As far as I get it as a non coder I now could make a copy of one of the files but what would I need to change inside?

merdok commented 7 months ago

You can use the ui to generate the device classes ("Generate device class") by specifying the models. Afterwards just copy over the files to the devices directory and then you have to map the statuses under the "Values overrides" section as in the other classes. The correct status values for your devices you can find here -> https://www.merdok.org/miotspec/?model=roborock.vacuum.a70

CooperCGN commented 7 months ago

Ok, so that was easier than I thought :)

At least both robots now show up as active no matter what program is running. The only thing that's still not working and is rather cosmectic is the 100% battery showing as charging thing.

CooperCGN commented 7 months ago

One thing, what does that "active" represent as marked in the picture because it never changes.

IMG_0233

merdok commented 7 months ago

It more or less shows that there is a connection to the device. It should should jump to inactive when for example the plugin cannot to the device or the device is offline.

As for the battery, as long as the device is in the dock it will show as "charging" as technically even if the battery is already 100% it is still connected to a power source hence it keeps the battery being charged.

merdok commented 7 months ago

I added classes for your 2 vacuum devices in the recent update so hopefully the status now works ok.

CooperCGN commented 7 months ago

Thank you.

merdok commented 7 months ago

Is there anything else or can we close this issue?

CooperCGN commented 7 months ago

For now that’s it.