Help with MQTT Sensor

Hi all, I want to create a mqtt sensor that report the status of a topic of my valetudo vacuum.
The topic is this:
valetudo/rockrobo/custom_command
inside this i have: {"command": "zoned_cleanup", "zone_ids": ["Zona Notte"]}

The status I want to see is inside zone_ids (Zona Notte).

I created this sensor:

  - platform: mqtt
    state_topic: "valetudo/rockrobo/custom_command/"
    name: Zone Cleaning
    value_template: "{{ value_json.zone_ids }}"

Status is always unknown. Any hint?

Try this:

    value_template: "{{ value_json.zone_ids[0] }}"

No change unfortunately.

New code:

- platform: mqtt
    state_topic: "valetudo/rockrobo/custom_command/"
    name: Zone Cleaning
    value_template: "{{ value_json.zone_ids[0] }}"

Same status : Unknown

Here’s the topic as shown in MQTT Explorer
image
{“command”: “zoned_cleanup”, “zone_ids”: [“Zona Giorno”]}

remove last /

By adding a trailing / to the topic you are defining a different topic from the one that your vacuum cleaner is publishing its payload to. That’s what is causing the problem and the template I suggested works perfectly.

Also, I don’t know if that’s a copy-paste error, but your last post contains an incorrectly indented configuration for the MQTT Sensor. It should be this:

- platform: mqtt
  state_topic: "valetudo/rockrobo/custom_command"
  name: Zone Cleaning
  value_template: "{{ value_json.zone_ids[0] }}"

Screenshot from 2021-04-29 13-55-37

Screenshot from 2021-04-29 13-55-27

Eureka! it works now.
BTW it was a copy paste error. In my yaml indentation was correct :slight_smile: .

Thank you both fot your support :slight_smile: