Sensor MQTT Text don't change value

Hi everyone,

I want add discovery device - sensor text, like a helper, but define with mqtt discovery.

I have a problem - I cannot set new value for text mqtt sensor. No matter what i do, I saw only “unknown” at value of text sensor

code function block “config”

msg.topic = "homeassistant/text/szczecin_text/config"
msg.payload = {
    "object_id": "szczecin_text",
    "unique_id": "szczecin_text",
    "name": "szczecin text",
    "icon": "mdi:ab-testing",
    "mode": "text",
    "command_topic": "miasta_tekstowe/szczecin/cmd",
    "state_topic": "miasta_tekstowe/szczcin/stan",
    "min": 2,
    "max": 20,
}
return msg;

code function block “send value”

msg.payload = {
    data: {
        "value": msg.payload
    }
}
return msg;

after click “config” path - I see new sensor text - but i cannot change them value.

I send them new value inject in node red to mqtt entity text (szczecin_text) … this not change a value

When i add this to dashboard, i had that same situation - First I wrote new text in sensor

and after reload … again unknown


again unknown. Have I should add extra parametrs? How i can allow sensor mqtt entity save values …

MQTT Text - Home Assistant i tried find any information about but without success…

okay now i understand - if i didn’t give device_class - change value is imposibble

For readers in the future
my function block with config now looks like this

msg.payload = {
    "device_class": "text",
    "object_id": "szczecin_text",
    "unique_id": "szczecin_text",
    "name": "szczecin text",
    "icon": "mdi:ab-testing",
    "mode": "text",
    "command_topic": "miasta_tekstowe/szczecin/cmd",
    "state_topic": "miasta_tekstowe/szczecin/stan",
    "min": 2,
    "max": 20,
}

and change not by call service, but new value sending to call mqtt with comand_topic