Get opening/closing state from JSON - String does not match the pattern of "DEPRECATED^"

Hi guys, trying to figure out to use the opening/closing/stopped state from my covers, which are ESP8266 wifi relays with Tasmota (Sonoff 4CH Pro). It gives it state like this:
{"Shutter1":{"Position":100,"Direction":0,"Target":100},"Shutter2":{"Position":95,"Direction":1,"Target":100}}

I want to use direction to set state_opening, state_closing like this:

cover:
  - platform: mqtt
    name: "Rolgordijn zolder noord"
    availability_topic: "tele/TasCH4zolder/LWT"
    state_topic: "stat/TasCH4zolder/RESULT"
    value_template: >
      {% if value_json.Shutter1.Direction == 1 %}
        opening
      {% elif value_json.Shutter1.Direction == -1 %}
        closing
      {% elif value_json.Shutter1.Direction == 0 %}
        stopped
      {% endif %}
    state_closing: "closing"
    state_opening: "opening"
    state_stopped: "stopped"
    payload_available: "Online"
    payload_not_available: "Offline"
    position_topic: "stat/TasCH4zolder/SHUTTER1"
    position_open: 100
    position_closed: 0
    set_position_topic: "cmnd/TasCH4zolder/ShutterPosition1"
    command_topic: "cmnd/TasCH4zolder/Backlog"
    payload_open: "ShutterOpen1"
    payload_close: "ShutterClose1"
    payload_stop: "ShutterStop1"
    retain: false
    optimistic: false
    qos: 1
    tilt_opened_value: 100

This however gives me the error String does not match the pattern of “DEPRECATED^”:


Anyone who can tell me what I do wrong?

Unfortunately my code also does not work, although HASS indeed does not give warnings or errors on the configuration.yaml. Is there something wrong with the template code?

It looks OK here. What do you get if you paste the template into Developer Tools / Template? Are there any errors in the logs?

1 Like

I’ve put the following in the dev tools:

{% set value_json=
{"Shutter1":{"Position":100,"Direction":-1,"Target":100},"Shutter2":{"Position":95,"Direction":1,"Target":100}}
 %}

    value_template: >
      {% if value_json.Shutter1.Direction == 1 %}
        opening
      {% elif value_json.Shutter1.Direction == -1 %}
        closing
      {% elif value_json.Shutter1.Direction == 0 %}
        stopped
      {% endif %}

This works perfectly if I change direction values.

Figured out what I did wrong: was listening to the wrong topic. I now get the correct down and up arrow when they are moving, great!

So the code now works perfectly, but I cannot find how to fix the DEPRECATED message. I found the link you posted before as well when diving into this issue. But it does not seem to help in my case If I remove the template from the configuration (i.e. leave value_template empty) the message is gone. But what is wrong with:

    value_template: >
      {% if value_json.Shutter1.Direction == 1 %}
        opening
      {% elif value_json.Shutter1.Direction == -1 %}
        closing
      {% elif value_json.Shutter1.Direction == 0 %}
        stopped
      {% endif %}

that it gives this error?

1 Like

If it works and passes Check Configuration, don’t be concerned with what some plugin for VS Code says. It’s a plugin separate from Home Assistant. The final arbiter of what’s right/wrong is Home Assistant.

2 Likes

It’s a bug apparently, see already that frenck picked it up, amazing!
MQTT cover deprecation of value_template breaking functionality · Issue #51089 · home-assistant/core (github.com)