Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I would love seeing Valetudo support in a Future release #375

Closed
PalmTamino opened this issue Mar 27, 2022 · 77 comments
Closed

I would love seeing Valetudo support in a Future release #375

PalmTamino opened this issue Mar 27, 2022 · 77 comments
Assignees
Labels
enhancement New feature or request new platform

Comments

@PalmTamino
Copy link

Description

Valetudo is a standalone binary, which runs on rooted Vacuums of the Xiaomi ecosystem and aims to enable the user to operate the robot vacuum without any Cloud Connection whatsoever.

https://valetudo.cloud/

Solution

https://valetudo.cloud/

Alternatives

No response

Context

No response

@PalmTamino PalmTamino added the enhancement New feature or request label Mar 27, 2022
@PiotrMachowski
Copy link
Owner

Does it support to cleaning by coordinates? Can you provide attributes of vacuum entity?

@PalmTamino
Copy link
Author

grafik
Do you mean this?

@PiotrMachowski
Copy link
Owner

yup 👍

@PiotrMachowski
Copy link
Owner

PiotrMachowski commented Mar 28, 2022

Are these entities created by mqtt autodiscovery?

@PalmTamino
Copy link
Author

Are these entities created by mqtt autodiscovery?

Yeah, i think so

@davidrustingha
Copy link

I second this! I initially rooted my vacuum with Valetudo RE so it wont be able to reach china, but a couple of days ago I reset it so I can make use of this awesome card you created!

If you need some information, I have two Xiaomi V1 vacuum robots which I can easily root with Valetudo RE again.

@PiotrMachowski
Copy link
Owner

PiotrMachowski commented Apr 10, 2022

@davidrustingha it's already possible to use it with Valetudo RE by manual configuration: #342

Original Valetudo should be doable as well

@wwebers
Copy link

wwebers commented Jul 17, 2022

Well, direct support for the original Valetudo firmware would be great. Simply as Valetudo RE doesn't seem to get actively mainained.

@PiotrMachowski
Copy link
Owner

@wwebers it would really help me if you could send me examples of service calls for Valetudo ;)

@wwebers
Copy link

wwebers commented Jul 17, 2022

@PiotrMachowski I'll look into it. For some reason the communication with the "camera" topic doesn't work, which works perfectly fine with the orginal Valetudo card.

@PiotrMachowski
Copy link
Owner

@wwebers any progress here? I would like to release v2.10.0 soon

@wwebers
Copy link

wwebers commented Aug 3, 2022

@PiotrMachowski
Sorry for late response. I updated HA today and my issue is that it complains about the "camera" source. I already installed "Lovelace Valetudo Map Card" via HACS. Still, it complains with a "Invalid calibration" error message. Am using the Valetudo RE platform.
Have not checked if the MQTT servcie API is different for "Valetudo" and "Valetudo RE". But I can however send commands.

@PiotrMachowski
Copy link
Owner

Camera source provided by Valetudo is practically useless for this card as it is not a real camera, but just a facade that is designed to work with "Lovelace Valetudo Map Card" - image is just a placeholder and map is rendered by the card from raw data. You have to install I can't believe it's not Valetudo to make it work with my card (calibration part will still be missing though).

Have not checked if the MQTT servcie API is different for "Valetudo" and "Valetudo RE". But I can however send commands.

Which commands?

@wwebers
Copy link

wwebers commented Aug 3, 2022

@PiotrMachowski
Ah! That explains things! My mistake. Thank you.
I mean those MQTT publish commands used by the "Valetudo RE" template:
https://github.com/PiotrMachowski/lovelace-xiaomi-vacuum-map-card/blob/master/src/model/generators/platform_templates/rand256_valetudo_re.json

@PiotrMachowski
Copy link
Owner

Have you tried them from my card or directly?

Can you try if version from the latest dev build works for you? To install it you have to manually copy js file downloaded from the artifact.

@wwebers
Copy link

wwebers commented Aug 3, 2022

Am looking directly into the source code of "Valetudo":
https://github.com/Hypfer/Valetudo/tree/master/backend/lib/mqtt

Doesn't look like the original "Valetudo" has support for the "custom_command" used by the "Valetude RE" template:

rand256_valetudo_re.json

@wwebers
Copy link

wwebers commented Aug 3, 2022

@PiotrMachowski
What I meant was that the API is different in the original "Valetudo". "Valetudo RE" uses a specific "custom_command", while the original doesn't. The functionality as such exists. So, what's needed is a different template with support for the original "Valetudo" API. Will see if I find some time to create one and send you a PR.

@PiotrMachowski
Copy link
Owner

PiotrMachowski commented Aug 3, 2022

You don't have to create a whole template, just example service calls would be enough

@wwebers
Copy link

wwebers commented Aug 3, 2022

👌

@PiotrMachowski
Copy link
Owner

Just one more question: do you have the same entities as @PalmTamino here, created by MQTT autodiscovery?

@wwebers
Copy link

wwebers commented Aug 3, 2022

Pretty much. Have some more as I'm using a Roborock S5 max with a watertank. So, some different capabilities...

@PiotrMachowski
Copy link
Owner

@wwebers One more thing that would massively help me in development.
Could you provide me data about entities created by Valetudo? Steps to follow:

  1. Open your main dashboard
  2. Open browser's dev tools (with F12 button)
  3. Open console
  4. Paste following code in the console:
    getDeviceData = async (entity) => {
        const hass = document.querySelector("home-assistant").hass;
        const vacuumDeviceId = (
            await hass.callWS({
                type: "config/entity_registry/get",
                entity_id: entity,
            })
        )["device_id"];
        const vacuumSensors = (
            await hass.callWS({
                type: "config/entity_registry/list",
            })
        ).filter(e => e.device_id === vacuumDeviceId);
        Promise.all(
            vacuumSensors.map(vs =>
                hass.callWS({
                    type: "config/entity_registry/get",
                    entity_id: vs.entity_id,
                }),
            ),
        ).then(v => console.log(v));
    }
  5. Retrieve entities related to the vacuum entity using following comand:
    getDeviceData("vacuum.example_valetudo_vacuum");
  6. Two entries should be printed, please copy content of the second one (click with right mouse button on it and choose "Copy object" option)
  7. Send me copied values to piotr.machowski.dev [at] gmail.com

@PiotrMachowski
Copy link
Owner

@wwebers Can you check if version from this build works with your vacuum?

@wwebers
Copy link

wwebers commented Aug 10, 2022

@PiotrMachowski I tried, but I cannot configure "Hypfer/Valetudo" as the new vacuum platform. Get an "Invalid vacuum platform" error.

@wwebers
Copy link

wwebers commented Sep 14, 2022

@Hypfer No offense. Even though Valetudo is not part of the manufacturer's firmware. It's still part of the software we flash onto the robots controller board. From the consumers perspektiv this would make it a part of the firmware.

To the outside world Valetudo abstracts from the OEM specific parts, which is cool. However, I would love better support in HA for it as well. I'm using the official card and miss several features there. Maybe one should spent some effort in that instead?

@Hypfer
Copy link

Hypfer commented Sep 14, 2022

I'm using the official card and miss several features there.

Yeah it's not feature-complete yet that is true and I'm aware of that.

@PiotrMachowski
Copy link
Owner

PiotrMachowski commented Sep 14, 2022

@Hypfer I don't want to argue, but actually I don't see any reason why my card would not be compatible with Valetudo (leaving aside retrieving map image), as it just utilizes a part of exposed MQTT API. Isn't this the whole point of having an API?

@Hypfer
Copy link

Hypfer commented Sep 14, 2022

Isn't map data retrieval the main issue here?
If it was working with it like any regular vacuum entity, then there wouldn't be this whole thread in the first place

@Hypfer
Copy link

Hypfer commented Sep 14, 2022

Anway, if you want to support Valetudo, you'll need to take the map data image, extract the ValetudoMap JSON, render that to an image and then use that image. In that case, you also won't need any calibration points as the ValetudoMap JSON already contains all the information you need.

See for example this test case JSON
https://github.com/Hypfer/Valetudo/blob/master/backend/test/lib/robots/dreame/res/map/1c_1096_areacleanup.json

Just take the map pixel coordinates and multiply it with the pixelSize found in that JSON.
This will give you the coordinates of that pixel in cm format, which - as far as I understand it - is what you're looking for.

To uncompress that compressedPixels format, take a look at this
https://github.com/Hypfer/lovelace-valetudo-map-card/blob/c9fe9659d78500dc7f44c00c68abf97b8fe1e0ad/valetudo-map-card.js#L801-L818

Also, consider looking at this comment describing the data format
https://github.com/Hypfer/Valetudo/blob/974ac6da5c0df0a430867c0c46e8a9b56a978086/backend/lib/entities/map/MapLayer.js#L3-L18

and this code extracting the data
https://github.com/Hypfer/lovelace-valetudo-map-card/blob/c9fe9659d78500dc7f44c00c68abf97b8fe1e0ad/valetudo-map-card.js#L779-L793

@PiotrMachowski
Copy link
Owner

It works with it like with any vacuum entity, the problem is that camera is not a regular camera - it doesn't contain an actual image.

My card (unlike Valetudo card) doesn't render map from data, but it displays an already rendered image. Because of that it needs calibration points to translate coordinates on the image to vacuum coordinates system.

The rest of communication and presentation uses standard HA entities and service calls (mqtt.publish to be precise).

I didn't want to incorporate rendering the map from ValetudoMap JSON, because it would be a completely different approach to displaying the map - that's why I wanted to use ICBINV (and add calibration points there).

@Hypfer
Copy link

Hypfer commented Sep 14, 2022

The reason why it is like that with Valetudo is that it allows us to

  • utilize the MQTT Autodiscovery feature to get the map data into HA
  • not kill the recorder component with huge amounts of useless old maps because it's an image and not a sensor entity and as such doesn't get recorded
  • don't use valuable cpu resources on the robot as we don't have those
  • not require deployment of any additional services that do the rendering
  • selectively render only parts of the map data
  • do scaling on the data level instead of the image level
  • do any processing really

It is indeed a completely different approach to how the cloud-based robots operate. That is why I was saying that this card and Valetudo like won't be very much compatible with each other, as they operate in very different niches even though they both have something to do with vacuum robots.
It is simply completely different. Working around that and forcing it to be similar will only cause mediocre results as one loses the benefits that each of those approaches would have on its own.

What I'm saying is that you can't support Valetudo without actually supporting Valetudo.
Valetudo is very much unlike the other vendor implementations and that's on purpose as it offers a range of benefits.

@wwebers
Copy link

wwebers commented Sep 14, 2022

It works with it like with any vacuum entity, the problem is that camera is not a regular camera - it doesn't contain an actual image.

And that's something I do not really get. How does the camera come into the game? Sure, there are vacuum cleaners out there with real cameras. But not all of them have. But all of them store a map. But a map is not a camera 🤔
So, why isn't the image of your card built around a map. Instead it's assuming the existence of a HA camera entity?

@Hypfer
Copy link

Hypfer commented Sep 14, 2022

@wwebers

So, why isn't the image of your card built around a map. Instead it's assuming the existence of a HA camera entity?

Okay so you see, the map data provided by the robots firmware actually isn't an image (like a png) but something else entirely.
It is a completely custom binary data structure.
Valetudo takes this custom binary data structure and maps it to a standard-ish ValetudoMap JSON structure.

To have an actual image (like a png), you then have to take that JSON and render it to an image.
As resources are limited on the robot, rendering cannot be done there as it would be too taxing for the cpu.
Thus, it is done in the browser by the lovelace card.

The fact that you're not seeing the ValetudoMap JSON but that camera entity with the picture telling you to install the map card is a clever hack around the following problem:

MQTT autodiscovery also means that any entity configured that way will also be recorded by the HA recorder component.
If the ValetudoJSON map data was a sensor entity, then this would mean that during cleanups, the HA recorder would store a few megabytes of JSON every few seconds.
That utterly shreds performance and fills up the disk of the HA machine with unnecessary data.

The trick here is that camera entities aren't stored by the recorder component. They have no history in HA.
We utilize this by embedding the ValetudoMap JSON into that image that you're seeing.
This makes it available in Home Assistant via the MQTT autodiscovery without any risk of the recorder exploding due to it.

So it's actually just a JSON string however for UX purposes, this string is wrapped into a png image file.

Also, context:
http://www.libpng.org/pub/png/spec/1.2/PNG-Chunks.html#C.zTXt

PNGs can contain arbitrary strings. See zTxT
What we're doing is not non-standard but 100% according to spec which makes it even cleverer.

@PiotrMachowski
Copy link
Owner

@Hypfer

don't use valuable cpu resources on the robot as we don't have those

I completely understand this, I don't expect Valetudo to render the image - I just wanted to use ICBINV istead.

It is simply completely different. Working around that and forcing it to be similar will only cause mediocre results as one loses the benefits that each of those approaches would have on its own.

It is just map rendering, I don't think that it would have such big impact on functionalities.

What I'm saying is that you can't support Valetudo without actually supporting Valetudo.
Valetudo is very much unlike the other vendor implementations and that's on purpose as it offers a range of benefits.

Like I mentioned above, my card since v2.x.x is not actually tied to any specific vendor. It provides a set of universal features to work with vacuums that operate using a map. It can be adjusted from supporting Roomba vacuums to Neato with just yaml a configuration change.


@wwebers

And that's something I do not really get. How does the camera come into the game? Sure, there are vacuum cleaners out there with real cameras. But not all of them have. But all of them store a map. But a map is not a camera 🤔
So, why isn't the image of your card built around a map. Instead it's assuming the existence of a HA camera entity?

Camera in HA doesn't have to be an actual real-world camera - it is just an entity with an image. In my case the image is a vacuum map.

@wwebers
Copy link

wwebers commented Sep 14, 2022

@Hypfer
Thanks for your explanation 😌 That makes things much clearer. However, the main culprit is than the design decision made by HA the force recording of sensor data. Instead they could offer to switch of such recording.
Anyway, will probably never happen and we'll have to live with the camera entity.
@Hypfer , @PiotrMachowski Isn't it possible to join both efforts into one project (card)?

@Hypfer
Copy link

Hypfer commented Sep 14, 2022

Like I mentioned above, my card since v2.x.x is not actually tied to any specific vendor.

Yes but it is tied to how all these vendors operate.
They all provide some kind of png image file of the map, enabling you to directly display it but also requiring you to use calibration points to figure out actual coordinates in cm.

Valetudo on the other hand doesn't provide an image as png and also does not need calibration points as the cm coordinates can be directly deduced from the JSON.

I know it would be easier to treat Valetudo like any other supported vendor, but it simply is different.
You can't do that without resorting to ugly hacks such as approximating data that is already there and having to set up another service that does some rendering.

To support Valetudo, you need to support Valetudo.
It is much more work than supporting other vendors at it is significantly different. There is no way around that.

@Hypfer
Copy link

Hypfer commented Sep 14, 2022

@wwebers

Isn't it possible to join both efforts into one project (card)?

No, because Valetudo is entirely different as it has a completely different access level to the map data than all other vendors.
It wouldn't make any sense to treat it like those, as you'd lose all the benefits that this raw map data access brings with it.

@wwebers
Copy link

wwebers commented Sep 14, 2022

@wwebers

Isn't it possible to join both efforts into one project (card)?

No, because Valetudo is entirely different as it has a completely different access level to the map data than all other vendors.
It wouldn't make any sense to treat it like those, as you'd lose all the benefits that this raw map data access brings with it.

Ok. Get that. That will only leave the option that @PiotrMachowski will code something more Valetudo specific into its card component.

@Hypfer
Copy link

Hypfer commented Sep 14, 2022

That will only leave the option that PiotrMachowski will code something more Valetudo specific into its card component.

Exactly, however I suspect that that wouldn't make all too much sense as it would be very different for just one Vendor.
I personally wouldn't want to bloat the architecture of a project with logic that only exclusively applies to one Vendor alone.
Especially considering that said vendor likely will only be used by idk.. 3%? of all users of the project

@PiotrMachowski
Copy link
Owner

Valetudo on the other hand doesn't provide an image as png and also does not need calibration points as the cm coordinates can be directly deduced from the JSON.

Actually e.g. Xiaomi doesn't provide map as an image as well - I have created Map Extractor that downloads binary map data from Xiaomi Cloud (rrmap) and creates an image. Thanks to that approach calibration points provided by Map Extractor are not an estimation, but are just as accurate as map generated by Valetudo. Generally speaking when using ME I have pretty similar access to map data compared to Valetudo.

No, because Valetudo is entirely different as it has a completely different access level to the map data than all other vendors.
It wouldn't make any sense to treat it like those, as you'd lose all the benefits that this raw map data access brings with it.

The only benefit of a binary map vs image map + calibration points is that you can treat binary map as a vector image, so e.g. zooming won't affect image quality. Is there something different that I'm missing?

That will only leave the option that PiotrMachowski will code something more Valetudo specific into its card component.

Exactly, however I suspect that that wouldn't make all too much sense as it would be very different for just one Vendor. I personally wouldn't want to bloat the architecture of a project with logic that only exclusively applies to one Vendor alone. Especially considering that said vendor likely will only be idk.. 3%? of all users

Yeah, adding Valetudo map parsing to the card doesn't really make sense. I think that I might create a custom integration (similar to Map Extractor) that will read ValetudoMAP JSON and create another camera with actual map displayed as an image, but this will definitely take some time for me to implement. It will bring other benefits to users that use HA and Valetudo, e.g. possibility to send map image with notification.

@Hypfer
Copy link

Hypfer commented Sep 14, 2022

Generally speaking when using ME I have pretty similar access to map data compared to Valetudo.

Oh okay. I've never looked into that due to the whole cloud thing but in that case

Is there something different that I'm missing?

You can selectively filter out entities or layers that you don't want. Maybe you just want to see the walls and the robot or maybe the path should not be part of the image or maybe it should be half-transparent or twice as wide.
This possibility is taken away as soon as the binary data becomes a simple image.

I think that I might create a custom integration (similar to Map Extractor) that will read ValetudoMAP JSON and create another camera with actual map displayed as an image, but this will definitely take some time for me to implement.

That would be awesome!
As mentioned in the ICBINV issue, it would be great if the user could just install a custom integration that does that and quickly configure it via the Home Assistant Config Flow.
As an idea: Maybe allow for having multiple instances of that for the same raw map data?
That would allow the user to have e.g. one image with only the walls and one with everything

@PiotrMachowski
Copy link
Owner

PiotrMachowski commented Sep 14, 2022

You can selectively filter out entities or layers that you don't want. Maybe you just want to see the walls and the robot or maybe the path should not be part of the image or maybe it should be half-transparent or twice as wide.
This possibility is taken away as soon as the binary data becomes a simple image.

Right, I have forgot about this. This would be nice - e.g. when drawing a free-hand zone to clean, but I think I can live without it.

As mentioned in the ICBINV issue, it would be great if the user could just install a custom integration that does that and quickly configure it via the Home Assistant Config Flow.

The downside of this solution compared to ICBINV is that it won't be available for people that doesn't use HA.

Using Config Flow is perfectly doable, but in this case configurability would probably need to be limited. Full functionality (incl. changing colors and visibility of elements) is much easier to achieve in yaml.

As an idea: Maybe allow for having multiple instances of that for the same raw map data?
That would allow the user to have e.g. one image with only the walls and one with everything

Sure, this isn't a problem at all. One thing that has to be taken to account though is that image rendering might use some resources.

@wwebers
Copy link

wwebers commented Sep 14, 2022

As mentioned in the ICBINV issue, it would be great if the user could just install a custom integration that does that and quickly configure it via the Home Assistant Config Flow.

The downside of this solution compared to ICBINV is that it won't be available for people that doesn't use HA.

Is it really? I mean those using Valetudo but not HA would probably use Valetudo directly, wouldn't they?🤔

Have no clue though how the Valetudo integration looks like for others like OpenHAB.

@wwebers
Copy link

wwebers commented Oct 11, 2022 via email

@PiotrMachowski
Copy link
Owner

@wwebers All of these are supported right now ;)

@lindsaymarkward
Copy link

Hi folks. I'm trying to follow this thread and use this card with Valetudo, but I don't have a "camera" entity other than camera.valetudo_roborock_map_data which simply shows the message that it's not actually a camera.
I might be missing it, but I can't see in the instructions how to use this card with Valetudo without specifying a camera - or with specifying a usable camera.
Can you help me (and others) see how this is supported please?
Thanks!

@PiotrMachowski
Copy link
Owner

@lindsaymarkward
Copy link

Thanks for the reply. I see this link says to use "ICBINV", which is perhaps still working but deprecated. I was hoping for an up-to-date supported solution. I may give it a go, as I only really need to get the coordinates once anyway.

@wwebers
Copy link

wwebers commented Feb 5, 2023

Not only you hope for that. The map image of the map has to be rendered somewhere, but not by the CPU of the vacuum cleaning robot. Resources are too limited @Hypfer said once. Anyway, Valetudo has the capability to render such a map. Sounds somewhat contradictory.

@PiotrMachowski
Copy link
Owner

Unfortunately that's all I have at this moment, but I plan to make some improvements

@lindsaymarkward
Copy link

lindsaymarkward commented Feb 6, 2023

Thanks for the responses!
Can I ask a different question to get to the same end result? All I really want is the coordinates of parts of my map.
I can successfully go to location in Valetudo interface, but I'm watching the MQTT topics and don't see the coordinates there. It would be super if there was a way to get these coordinates from this working command. Is there?

I've tried lots of "go to location" commands with various points and the robot goes for a trip and says it can't get there. I can't figure it out. It will go to the North East part of my house for say, 150, 300... then I try to move it a tiny bit, like 120, 300 and it will go to a totally different spot on the West side. I understand it might not be able to get to actual locations that aren't inside the house, but I've yet to figure it out.
I'm working with the stated understanding that 0, 0 is the top-left of the map and the measurements are in cm.
Valetudo's zone interface shows dimensions of zones, so I'm using that to make informed guesses, but no luck. Perhaps I don't understand where 0, 0 actually is.
I'll post an example...

@lindsaymarkward
Copy link

In this map image you can see I've drawn a zone 800 x 755 from what might be the top-left of the map if I include all the parts that are drawn. I sent the MQTT command to go to 800, 755 and off it went into the top-middle orange room, did a lap, some reversing, then went way back to the left green room you see it's in now and said "cannot reach the target".
Any ideas of what my actual coordinates would be here would be much appreciated :)
Valetudo-Map

@PiotrMachowski
Copy link
Owner

@lindsaymarkward well, I don't use Valetudo so I can't help you using my own experience, but I've managed to find this discussion that should help you in resolving your issues: Hypfer/Valetudo#1688

@lindsaymarkward
Copy link

Super, thanks! I spent way too much of my weekend looking for something like that, so thanks for finding it for me. That didn't come up in any of my searches...
Here's where 0, 0 (roughly) is... way off what I expected!
Valetudo-Map2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request new platform
Projects
None yet
Development

No branches or pull requests

8 participants