onfoot / homebridge-valetudo-xiaomi-vacuum

A Homebridge plugin for Xiaomi/Roborock vacuum cleaners running Valetudo
MIT License
31 stars 9 forks source link

[suggestion] cleaning mode #4

Open leonardpitzu opened 5 years ago

leonardpitzu commented 5 years ago

one thing to add is a way to control the cleaning mode: vacuum/mop and the power level associated with it. My first idea would be to add a fan mode which can be controlled but this is tricky as the user needs to remember which percent of the fan corresponds to which cleaning mode. Another idea would be to have switches for cleaning and mopping. Still you somehow need to control the power levels for vacuuming... Mopping is tricky as it is missing from valetudo. It's an additional mode during which the vacuum moves slower. I modified valetudo as follows:

var fanspeeds = { 38: "Quiet", 60: "Balanced", 75: "Turbo", 100: "Max", 105: "Mop" };

`function handleFanspeedButton() { window.clearTimeout(currentRefreshTimer);

                ons.openActionSheet({
                    title: 'Select power mode',
                    cancelable: true,
                    buttons: [
                        'Quiet',
                        'Balanced',
                        'Turbo',
                        'Max',
                        'Mop',
                        {
                            label: 'Cancel',
                            icon: 'md-close'
                        }
                    ]
                }).then(function (index) {
                    var level;

                    switch (index) {
                        case 0:
                            level = 38;
                            break;
                        case 1:
                            level = 60;
                            break;
                        case 2:
                            level = 75;
                            break;
                        case 3:
                            level = 100;
                            break;
                        case 4:
                            level = 105;
                            break;
                    }

                    if (level) {
                        loadingBarHome.setAttribute("indeterminate", "indeterminate");
                        fanspeedButton.setAttribute("disabled", "disabled");
                        fn.requestWithPayload("api/fanspeed", JSON.stringify({ speed: level }), "PUT", function (err, res) {
                            if (err) {
                                fanspeedButton.removeAttribute("disabled");
                                loadingBarHome.removeAttribute("indeterminate");
                                ons.notification.toast(err, { buttonLabel: 'Dismiss', timeout: 1500 })
                            } else {
                                window.clearTimeout(currentRefreshTimer);
                                window.setTimeout(function () {
                                    updateHomePage();
                                }, 150);
                            }
                        })
                    } else {
                        window.setTimeout(function () {
                            updateHomePage();
                        }, 3000);
                    }
                });
            }`
leonardpitzu commented 5 years ago

battery status would also be nice

onfoot commented 5 years ago

Yeah, I've been thinking how to approach the cleaning modes, especially the power, and thought that the solution using a fan accessory for both mop and non-mopping modes is not a very fortunate one.

A separate switch for mopping mode, and a fan accessory for non-mopping modes rescaled to 0-100 should do at least. But we would have to be able to detect whether the vacuum the plugin is controlling is a mopping-capable robot.

OR, maybe besides the normal/mop mode switch, provide a config setting for any two modes the user prefers, so they'd get a switch for Quiet/Max, or Balanced/Turbo, etc. Currently I'm using only one mode anyway, as when I'm not at home I don't care how quickly the vacuum will do its job.

The battery status is there in every accessory already - whether it's charging, battery level and low level state. Or maybe you're thinking of a "status accessory" for something battery-related?

leonardpitzu commented 5 years ago

i was thinking of a mixture... a switch for on off a switch (with a config flag to enable it for gen.2) for mop on/off a fan (a multi-level switch would be nicer) for vacuum power a sensor for displaying battery level

onfoot commented 5 years ago

Which sensor for battery level would you have in mind? Nothing existing really fits, and I don't know whether a custom accessory would show up as a sensor showing a numeric value, for example. The ones that do are I think light level (in lux), temperature (celsius or fahrenheit), and humidity (percentage). That's it, I think.

The rest are devices you can control, like doors, window coverings, fans, bulbs.

leonardpitzu commented 5 years ago

I think of the humidity sensor as it’s percentage and fits the battery level reported by Valetudo.

onfoot commented 5 years ago

By the way, have you tried to send a pull request for Valetudo with the speed modes? They use their own values in the client for the different speeds, but their own fake backend actually does define the presets available in the official robot's interface (i.e. Quiet, Balanced, Turbo, Max, Mop). I implemented those, but when they are set, the default Valetudo interface shows undefined. :D

leonardpitzu commented 5 years ago

pushed ;)

onfoot commented 5 years ago

In case you didn't notice, 0.1.2 is live with cleaning modes. I'm still contemplating the humidity sensor as battery indicator idea.

Is it really useful to see the battery level in the Home app directly? Would you do anything about it if it crossed a specific threshold? Do you want to set up automations with it (e.g. red lights turn on in the living room if the battery is low ;) )?

Not saying it's a terrible idea and would never implement it. It's just that it is an additional code I have to maintain afterwards, for a functionality I'm not completely sold on. It's not a lot of code, honestly, but still.

I'm much more eager to implement buttons for cleaning saved zones or spots, or adding MQTT support so the plugin receives vacuum's status by listening to notifications, rather than having to poll every few seconds. My simple HTTP notifier PR for Valetudo got rejected, so I'm about to set up a standalone MQTT broker at home to test this ecosystem. I've never been a huge fan of MQTT, but I guess it has its uses, for a slight cost of additional infrastructure.

leonardpitzu commented 5 years ago

Guess you can drop the humidity/battery sensor. In terms of automation you could set up some form of notification and action(e.g. on battery < 30% notify the user and regardless of the task go to the dock). Still this sound more like a useless feature even as I type it. Scrap it. Regarding MQTT... I am for simple things, few lines of code, etc. thus I would not use it. Still it might be of interest to a lot of people so I guess it is a good idea to do it. Maybe a flag would be nice so one can chose between http and MQTT.

onfoot commented 5 years ago

The vacuum does stop and go back to base when low on juice - there are even suitable error messages for that. I would know because I recently sent a PR to dustcloud with updated Polish translations. ;)

I'm all for simpler solutions and the HTTP notifications I proposed in the PR would solve some of my issues, but MQTT prevails as THE IoT protocol, apparently.

No worries, though - this plugin will be both HTTP- and MQTT-capable. Once MQTT is configured, I'd like to offer the same exact features, but use a different means of communication.

Here's an idea - maybe I could implement some kind of a status forwarder in the plugin, that, once configured, would post human-readable messages to a predefined URL, to enable push notifications, for example. We could define which status changes should be forwarded, too - I know it spams a lot of these status updates when working, because it does that even for area covered or battery level changes.

Seems like a bit beyond what a Homebridge plugin should do, but then again, one wouldn't have to set up any other ways of getting such notifications.

leonardpitzu commented 5 years ago

I did something different - scripting based telegram notifications. I have now updated to the latest version - for me it’s mostly ok so I would leave it like this. As of now i am contemplating in baking telegram notification support directly in Valetudo so the vacuum would be self sufficient...

leonardpitzu commented 5 years ago

Just a question as i have not looked into homebridge (yet). Are there any switch types which support more than 2 states? I am thinking of a multi-level switch - simple press toggles between on/off while long press allows for setting the desired level (e.g. low, medium, high). It would combine the power modes of the vacuum and the ability to turn that particular mode on or off.

onfoot commented 5 years ago

There is a programmable switch, for example, but its purpose is to have an "intelligent" HomeKit-compatible physical button that can be programmed to perform different actions on a click, double-click and a long-press, so you can't really use it like that in HomeKit, just program the actions performed.

There are other sort of multi-level switches, but very specific ones, like the one for alarm systems - this one has Stay, Away, Night, Disarm, Triggered, so this doesn't make any sense for our purpose. :(

imbaimbaimba commented 4 years ago

Did you start using MQTT? I would also love to have controls of zones in HomeKit, I just haven't been able to program it myself :(

onfoot commented 4 years ago

I have had zero time available recently, but I've been thinking about the zone cleanups, and it's doable provided that the plugin can indeed associate current action with cleaning the chosen zone when checking for vacuum's status.

As for MQTT, I'd love to implement it for sure.