zigbee2mqtt icon indicating copy to clipboard operation
zigbee2mqtt copied to clipboard

[Bug] SWV-ZFE Water Valve: irrigation_schedule_status sensor state is truncated JSON

Open vchatela opened this issue 6 months ago • 8 comments

Description

The irrigation_schedule_status sensor exposed by Zigbee2MQTT for the SWV-ZFE Water Valve device returns a truncated JSON string as its state in Home Assistant.

Steps to reproduce

  1. Pair a Water Valve device (e.g. Tuya TS0601 _TZE204_r0jdjrvi)
  2. Trigger an irrigation schedule
  3. Read the state of the irrigation_schedule_status sensor in Home Assistant

Expected result

A complete, valid JSON string such as:

{
  "actual_end_time": "2026-05-26T13:57:42+02:00",
  "actual_irrigation_amount": 1,
  "expected_end_time": "2026-05-26T14:19:37+02:00",
  "expected_irrigation_amount": 30,
  "irrigation_amount_unit": "liter",
  "irrigation_mode": "duration",
  "schedule_index": 0
}

Actual result

The sensor state is cut off mid-JSON string. Example of what is received:

{'actual_end_time': '2026-05-26T13:57:42+02:00', 'actual_irrigation_amount': 1, 'expected_end_time': '2026-05-26T14:19:37+02:00', 'expected_irrigation_amount': 30, 'irrigation_amount_unit': 'liter', 'irrigation_mode': 'duration', 'schedule_index': 0, 'sc

The string is abruptly truncated at 'sc — the rest of the payload is missing.

Impact

  • The expected_end_time field (useful for dashboard timers and automations) is present in the truncated portion, but the sensor state cannot be reliably parsed via from_json because the JSON is invalid/incomplete.
  • Any automation or template relying on this sensor state will fail to parse the JSON.

Possible cause

The MQTT payload for this attribute may exceed the maximum state length allowed by Home Assistant (255 characters), causing it to be truncated. This could be addressed by splitting the value across multiple attributes or exposing individual fields (e.g. irrigation_schedule_expected_end_time) as separate sensor attributes.

Environment

  • Zigbee2MQTT version: latest
  • Home Assistant: current
  • Device: Water Valve (Tuya TS0601, manufacturer _TZE204_r0jdjrvi or similar)

vchatela avatar May 26 '26 12:05 vchatela

I got the exact same problem. so that it messes up in home assistant. Using a Sonoff SWV-ZFE Valve using 2.11.0. Just updated the valve to 1.0.8.

drschnalli avatar Jun 03 '26 10:06 drschnalli

This is because HA does not support showing long strings

Koenkk avatar Jun 03 '26 18:06 Koenkk

is it possible to expose these as individual sensors? The actual irrigation amount is tied up in this and it would be great to run automations based on the actual water flow.

Pel1can111 avatar Jun 11 '26 09:06 Pel1can111

Worst case could be to use MQTT broker like emqx to manipulate the json to create additional sensors (but also when receiving update on a value from HA then reconstitute the overall json).

But would really prefer having Z2M fiting HA specs.

vchatela avatar Jun 11 '26 11:06 vchatela

@vchatela You can create a custom MQTT sensor for this entity.

Here is an example YAML config:

mqtt:
  sensor:
    - name: "Sonoff Irrigation Schedule Status"
      state_topic: "zigbee2mqtt/{FRIENDLY_NAME}"
      unique_id: sonoff_irrigation_schedule_status
      force_update: true
      value_template: >-
        {{ value_json["irrigation_schedule_status"] | default('',True) | string | truncate(254, True, '', 0) }}
      json_attributes_topic: "zigbee2mqtt/{FRIENDLY_NAME}"
      json_attributes_template: >-
        {{ value_json["irrigation_schedule_status"] | tojson }}

Change {FRIENDLY_NAME} to your Device Name in Zigbee2Mqtt.

I will create a Pull-Request to add this to the Auto-Configuration for this special Sensors

Rappelkiste98 avatar Jun 29 '26 23:06 Rappelkiste98

@vchatela You can create a custom MQTT sensor for this entity.

Here is an example YAML config:

mqtt:
  sensor:
    - name: "Sonoff Irrigation Schedule Status"
      state_topic: "zigbee2mqtt/{FRIENDLY_NAME}"
      unique_id: sonoff_irrigation_schedule_status
      force_update: true
      value_template: >-
        {{ value_json["irrigation_schedule_status"] | default('',True) | string | truncate(254, True, '', 0) }}
      json_attributes_topic: "zigbee2mqtt/{FRIENDLY_NAME}"
      json_attributes_template: >-
        {{ value_json["irrigation_schedule_status"] | tojson }}

Change {FRIENDLY_NAME} to your Device Name in Zigbee2Mqtt.

I will create a Pull-Request to add this to the Auto-Configuration for this special Sensors

The value_template is still a malformed string (because of the 255 char limit), thus json_attributes_topic and json_attributes_template don't work. What I did is to extract the 'schedule_status' form the payload, for example:

mqtt:
  sensor:
    - name: "Irrigation Status"
      state_topic: "zigbee2mqtt/{FRIENDLY_NAME}"
      device: 
        hw_version: 0
        identifiers:
          - {IDENTIFIER} # check with your payload data
        manufacturer: SONOFF
        model: Zigbee smart water valve
        model_id: SWV-ZFE
        name: water irrigation
      unique_id: irrigation_status
      force_update: true
      value_template: >-
        {{ value_json["irrigation_schedule_status"]["schedule_status"] | default('unknown',True) }}
      json_attributes_topic: "zigbee2mqtt/{FRIENDLY_NAME}"
      json_attributes_template: >-
        {{ value_json["irrigation_schedule_status"] | tojson }}

Then, you can use a helper in HA to extract all other state_attr

mwong009 avatar Jul 16 '26 13:07 mwong009

Confirming the issue & temporary workaround

Home Assistant has a hard limit of 255 characters for entity states. When Zigbee2MQTT pushes a long JSON string like irrigation_schedule_status as a standard sensor state, Home Assistant truncates it, breaking valid JSON formatting.

Regarding the exposed sensors:

  • x_real_time_irrigation_volume is misleadingly named. It actually behaves like a daily total consumption (it updates every 5 minutes and resets at midnight), rather than showing real-time volume per irrigation cycle;
  • actual_irrigation_amount inside irrigation_schedule_status is the actual real-time water consumption that resets to zero at each new irrigation cycle.

It would be ideal if Zigbee2MQTT exposed actual_irrigation_amount as a standalone sensor.

In the meantime, if anyone needs to extract the real-time value from the truncated state (e.g., using custom:template-entity-row or a template sensor), you can use this extraction logic:

{% set value = states('sensor.irrigazione_giardino_irrigation_schedule_status') %}
{% if 'actual_irrigation_amount' in value %}
  {{ value.split("'actual_irrigation_amount': ")[1].split(',')[0] | trim }} L
{% else %}
  N/D
{% endif %}

simonevisciano avatar Jul 29 '26 07:07 simonevisciano

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 7 days

github-actions[bot] avatar Sep 28 '26 00:09 github-actions[bot]