PiotrMachowski / lovelace-xiaomi-vacuum-map-card

This card provides a user-friendly way to fully control map-based vacuums in Home Assistant. Supported brands include Xiaomi (Roborock/Viomi/Dreame/Roidmi/Valetudo/Valetudo RE), Neato, Wyze, Roomba, Ecovacs (and probably more).
MIT License
1.47k stars 252 forks source link

Hypfer/Valetudo and vacuum_clean_zone_predefined are completelly broken #662

Open erkexzcx opened 1 year ago

erkexzcx commented 1 year ago

Checklist

The problem

Basically this is what example says (source):

      - zones: [[ 27782, 27563, 29678, 29369 ]]
        label:
          text: "Kitchen"
          x: 28760
          y: 28403
          offset_y: 35
        icon:
          name: "mdi:pot-mix"
          x: 28760
          y: 28403

Here is what I am getting:

image

Okey, ID is missing, let's add it:

      - id: "helloworld"
        zones: [[ 27782, 27563, 29678, 29369 ]]
        label:
          text: "Kitchen"
          x: 28760
          y: 28403
          offset_y: 35
        icon:
          name: "mdi:pot-mix"
          x: 28760
          y: 28403

Now it looks OK. Let's run it - nothing happens. Let's look at MQTT logs in Valetudo:

MQTT: Error while handling valetudo/rockrobo/ZoneCleaningCapability/start/set {
  payload: '{"zones": [{ "points": {"pA": { "x": h, "y": e }, "pB": { "x": l, "y": e }, "pC": { "x": l, "y": l }, "pD": { "x": h, "y": l } }, "iterations": 1}]}',

hmmm, h... e.. these are not coordinates! Let's see if we can convert template to manual configuration:

map_modes:
  - name: Zones list
    icon: mdi:floor-plan
    run_immediately: false
    coordinates_rounding: true
    coordinates_to_meters_divider: 1000
    selection_type: ROOM
    max_selections: 999
    repeats_type: EXTERNAL
    max_repeats: 3
    service_call_schema:
      service: mqtt.publish
      evaluate_data_as_template: true
      service_data:
        topic: '[[topic]]/ZoneCleaningCapability/start/set'
        payload: >-
          {"zones": [{%for s in ('[[selection]]')|from_json %}{ "points": {"pA":
          { "x": {{s[0]}}, "y": {{s[1]}} }, "pB": { "x": {{s[2]}}, "y": {{s[1]}}
          }, "pC": { "x": {{s[2]}}, "y": {{s[3]}} }, "pD": { "x": {{s[0]}}, "y":
          {{s[3]}} } }, "iterations": [[repeats]]}{%if not
          loop.last%},{%endif%}{%endfor%}]}
    predefined_selections:
    ....
    ....
    ....

But wait! Let's look into {%for s in ('[[selection]]')|from_json %} part. It uses '[[selection]]' and generates coordinates accordingly. Let's simply update payload to this:

        payload: >-
          '[[selection]]'

Let's run again and this time it's quite interesting result in MQTT logs in Valetudo :smile:

MQTT: Error while handling valetudo/rockrobo/ZoneCleaningCapability/start/set {
  payload: `'["helloworld"]'`,

How is this even supposed to work? Looks like this card is iterating ID string rather than coordinates.

I am not certainly sure, but it worked a week ago or something. I did not update this card, no idea how it ended up working like this.

What version of a card has described problem?

v2.2.2

What was the last working version card?

No response

What vacuum model do you have problems with?

roborock.vacuum.s5

Which integration do you use to control your vacuum (link)?

hypferValetudo over MQTT (standard configuration)

What browser (browsers/apps) does have this problem?

Firefox

What version of Home Assistant do you use?

Home Assistant 2023.9.3; Frontend 20230911.0 - latest

What type of installation are you running?

Home Assistant Container

Card's configuration

type: custom:xiaomi-vacuum-map-card
map_source:
  camera: camera.rockrobo_rendered_map
calibration_source:
  entity: sensor.rockrobo_calibration_data
entity: vacuum.valetudo_rockrobo
vacuum_platform: Hypfer/Valetudo
internal_variables:
  topic: valetudo/rockrobo
map_modes:
  - template: vacuum_clean_zone_predefined
    predefined_selections:
      - id: Entrance
        outline: [[2185,2975],[2310,2975],[2310,3090],[2185,3090]]
        label:
          text: Entrance
          x: 2247.5
          y: 3032.5
          offset_y: 28
        icon:
          name: mdi:door
          x: 2247.5
          y: 3032.5
  - template: vacuum_goto
  - template: vacuum_clean_zone
map_locked: true
two_finger_pan: false

Javascript errors shown in the browser's console (if applicable)

No errors

Additional information

I've developed a new mapper application for Valetudo: https://github.com/erkexzcx/valetudopng

I am currently using it. Considering that Ping & Go works like a charm, I believe my application has no impact on this and issue lies somewhere else...

PiotrMachowski commented 1 year ago

Yup, you are correct. It seems that I have not fully finished this section of configuration.

Check if this config works:

type: custom:xiaomi-vacuum-map-card
map_source:
  camera: camera.rockrobo_rendered_map
calibration_source:
  entity: sensor.rockrobo_calibration_data
entity: vacuum.valetudo_rockrobo
vacuum_platform: Hypfer/Valetudo
internal_variables:
  topic: valetudo/rockrobo
map_modes:
  - template: vacuum_clean_zone_predefined
    selection_type: PREDEFINED_RECTANGLE
    coordinates_rounding: true
    coordinates_to_meters_divider: 100
    max_selections: 5
    predefined_selections:
      - zones: [[2185,2975,2310,3090]]
        label:
          text: Entrance
          x: 2247.5
          y: 3032.5
          offset_y: 28
        icon:
          name: mdi:door
          x: 2247.5
          y: 3032.5
  - template: vacuum_goto
  - template: vacuum_clean_zone
map_locked: true
two_finger_pan: false
erkexzcx commented 1 year ago

Yes, this one does work:

map_modes:
  - template: vacuum_clean_zone_predefined
    selection_type: PREDEFINED_RECTANGLE
    predefined_selections:
      - zones:
          - - 2185
            - 2975
            - 2310
            - 3090
        label:
          text: Entrance
          x: 2247.5
          'y': 3032.5
          offset_y: 28
        icon:
          name: mdi:door
          x: 2247.5
          'y': 3032.5

Thanks a lot!

PiotrMachowski commented 1 year ago

Great :+1: I'll adjust it

erkexzcx commented 1 year ago

Thanks! Also note this: https://community.home-assistant.io/t/ive-build-a-better-alternative-to-icantbelieveitsnotvaletudo-map-renderer/620185/7?u=erkexzcx

Basically my project archived (or superseded) https://github.com/Hypfer/Icantbelieveitsnotvaletudo and instructions should be updated accordingly: https://github.com/PiotrMachowski/lovelace-xiaomi-vacuum-map-card/blob/master/docs/templates/hypferValetudo.md

Currently there are 2 projects now that can render a map in HomeAssistant as of today:

PiotrMachowski commented 1 year ago

I've seen this thread, good job 👍 I'll adjust docs - Valetudo Map Camera has already been added there, I'll add your project as well and remove ICBINV.

By the way, you might consider creating HA addon as well