Please help create mqtt vacuum

Hi everybody,

I have a Gardena Sileno City lawnmower which I tried to integrate via the available HACS integration. Unfortunately, this integration seems to be broken atm: it will update the status once, namely when (re)starting Home Assistant - if any values change after this, they will not be represented correctly (nor update) within Home Assistant.

So I installed the gardena2mqtt bridge instead. This will present me with the output below (this exact pattern, I only changed user-specific details) (topic gardena2mqtt/My Garden/Sheena)

{
  "datetime": "2022-03-26 11:33:13",
  "id": "yes",
  "type": "MOWER",
  "battery_level": 100,
  "battery_state": "OK",
  "name": "Sheena",
  "rf_link_level": 100,
  "rf_link_state": "ONLINE",
  "serial": "exactly",
  "model_type": "GARDENA smart Mower",
  "activity": "PARKED_AUTOTIMER",
  "operating_hours": 403,
  "state": "OK",
  "last_error_code": "N/A",
  "mower_id": "tis but a scratch"
}

At this time, I am only trying to receive the states reported by this bridge, not to control the “vacuum” (or, in fact, lawn mower) this way. So I created the entity below

vacuum:
  - platform: mqtt
    name: "Sheena"
    availability_topic: "gardena2mqtt/My Garden/Sheena"
    payload_available: "OK"
    availability_value_template: "{{ value_json.state }}"
    battery_level_topic: "gardena2mqtt/My Garden/Sheena"
    battery_level_template: "{{ value_json.battery_level }}"
    error_topic: "gardena2mqtt/My Garden/Sheena"
    error_value_template: >
      {% if value_json.last_error_code != 'N/A' %}
        {{ value_json.last_error_code }}
      {% else %}
        OK
    cleaning_topic: "gardena2mqtt/My Garden/Sheena"
    cleaning_value_template: "{{ value_json.activity }}"

This will only create this entity (_2 because vacuum.sheena was already created by the HACS integration I mentioned in the beginning)

Can you please tell me what’s wrong with my template, and ideally how I can fix it? I restarted the gardena2mqtt bridge after restarting Home Assistant to make sure that the payloads will have been received by Home Assistant, and checked on them by manually subscribing to that topic via mqtt_sub in the terminal, which displayed everything as expected - however, no change within Home Assistant.

Thank you in advance for your help :slight_smile:

I changed the approach: instead of creating a vacuum entity, I first created multiple mqtt sensors (one for each attribute I wanted to display), then created a template sensor combining all those values into one sensor.

Seems like this is way too hacky and unnecessary, but it was the only way I could get things to work. Would anybody have done it differently, and if so, how?

sensor:
  - platform: mqtt
    unique_id: sheenamqttstate
    name: "Sheena State"
    icon: "mdi:robot-mower"
    state_topic: "gardena2mqtt/My Garden/Sheena"
    value_template: "{{ value_json.state }}"
  - platform: mqtt
    unique_id: sheenamqttbattery
    name: "Sheena Battery"
    icon: "mdi:robot-mower"
    state_topic: "gardena2mqtt/My Garden/Sheena"
    value_template: "{{ value_json.battery_level }}"
  - platform: mqtt
    unique_id: sheenamqttactivity
    name: "Sheena Activity"
    icon: "mdi:robot-mower"
    state_topic: "gardena2mqtt/My Garden/Sheena"
    value_template: "{{ value_json.activity }}"
  - platform: mqtt
    unique_id: sheenamqtthours
    name: "Sheena Operating Hours"
    icon: "mdi:robot-mower"
    state_topic: "gardena2mqtt/My Garden/Sheena"
    value_template: "{{ value_json.operating_hours }}"
  - platform: mqtt
    unique_id: sheenamqttlasterror
    name: "Sheena Last Error Code"
    icon: "mdi:robot-mower"
    state_topic: "gardena2mqtt/My Garden/Sheena"
    value_template: "{{ value_json.last_error_code }}"
  - platform: template
    sensors:
      sheena:
        friendly_name: "Sheena"
        value_template: "{{ states('sensor.sheena_activity') }}"
        icon_template: >
          {% if (states("sensor.sheena_activity") == "PARKED_AUTOTIMER") %}
            mdi:robot-mower-outline
          {% else %}
            mdi:robot-mower
          {% endif %}
        attribute_templates:
          state: "{{ states('sensor.sheena_state') }}"
          operating_hours: "{{ states('sensor.sheena_operating_hours') }}"
          battery_level: "{{ states('sensor.sheena_battery') }}"

Interesting, I’m currently working on an integration that would interface the MQTT vacuums.
Can you please point me to the docs of your vacuum?
Would gladly try to add it to the list of the supported ones.
This is a garden model correct?