openHASP icon indicating copy to clipboard operation
openHASP copied to clipboard

Updating label text does not work when string is empty

Open he-so opened this issue 1 year ago • 11 comments

Perform all steps below and tick them with [x]

  • [ x] Check the related part of the Documentation
  • [ x] Update openHASP to the latest version
  • [ x] Reproduce the issue and describe all steps

Describe the bug

When using Label object to display text, updates via openHASP - Custom Component for Home Assistant to the text are ignored when the new value is just space or empty string. This makes it impossible to "hide" labels by setting the text to empty.

To Reproduce

pages.jsonl

{"page":1,"id":25,"obj":"label","x":9,"y":250,"w":400,"h":50,"parentid":20,"text":"start","align":1}

configuration.jaml

openhasp:
  plate:
    objects:
    - obj: "p1b25"
        properties:
          "text": '{{"" if not has_value("sensor.evcc_einfahrt_plan_projected_start") else "start"}}'

What you observe now: Even though has_value("sensor.evcc_einfahrt_plan_projected_start") changes to false, the label object does not change from "start" to "". When changing the last line to setting some other single character not equal to space, like:

    "text": '{{"." if not has_value("sensor.evcc_einfahrt_plan_projected_start") else "start"}}'

surprisingly, the update does work. But the dot is visible, so that is not the solution here. Setting it to " " does not work either, but still keeps the label showing "start".

Expected behavior

Assign the empty string "" when condition is met and hide the label.

Screenshots or video

he-so avatar Nov 16 '25 13:11 he-so

Please post the exact MQTT topic and payload that is sent to the plate, using MQTT Explorer or another tool. And check the serial/telnet log on the device when the message is received to see what actually happens...

To determine if this is an issue in the firmware or in the custom component, more details are needed. On the other hand, why not just hide the label outright using the hidden property?

fvanroie avatar Nov 16 '25 16:11 fvanroie

Thank you for recommending MQTT Explorer. I just figured out that, apearantly, the mqtt message with the empty string is not sent out to the plate. It seems to be an issue with the custom component. If you have further advice, how to track this down, let me know. I'm still in the middle of the migration to homeassistant and need to figure out how to manage things here. Regarding the hidden property, yes, that would partially solve my problem. I was not aware of its existence. But when using it, it probably would bloat my yaml code, since the lable text itself has to be changed anyway. So I prefer to set empty text, if possible.

edit:

Did some tests, still not sure if the plate shows correct behaviour. The topic connected to the label object literally disapears also in MQTT Explorer when the value is the empty string/space. See the two videos I recorded. One, with the above mentioned single space/empty string in the yaml template, the other one with the dot.

https://github.com/user-attachments/assets/04e7b050-7d31-4574-b1f0-9f6f43f2920c Space https://github.com/user-attachments/assets/a0e27432-3101-4aae-9c91-fdc36edd9ac5 Dot

he-so avatar Nov 18 '25 18:11 he-so

You can use U+00A0 (non-breaking space) too if spaces are ignored by the custom component.

    "text": '{{"\u00A0" if not has_value("sensor.evcc_einfahrt_plan_projected_start") else "start" |e}}'

Note: The |e at the end is needed for HA to recognize the unicode encodings.

fvanroie avatar Nov 18 '25 22:11 fvanroie

You can use U+00A0 (non-breaking space) too if spaces are ignored by the custom component.

This character didn't work for me. The last displayed text remained visible when I used the non-breaking space \u00A0.

For me, the zero-width space \u200B works without any problems for this task. However, it's important to note that text_font must not be defined, otherwise ZWSP will be displayed as an unknown character. I've solved this in my configuration.

"jsonl": >
  {% if is_state('media_player.kuechenradio', 'buffering') %}
  {"text":"\u200B","text_font":""}
  {%-else %}
  {"text_font":26}
  {% endif %}

schabau avatar Nov 19 '25 16:11 schabau

\u200B

Yes, this works. Surprisingly, without | e.

But I still have the opinion, that openHASP should clear the label text as MQTT Explorer does by hiding the topic in case of empty or trimable strings.

he-so avatar Nov 20 '25 16:11 he-so

And check the serial/telnet log on the device when the message is received to see what actually happens...

fvanroie avatar Nov 20 '25 16:11 fvanroie

Prompt > [18:38:27.617][102388/114664 10][54620/54988  1] MQTT RCV: p1b22.val = 1
Prompt > [18:38:27.808][102388/114616 10][54520/54908  1] MQTT RCV: p1b25.text = Ladestart: 04:00
Prompt > [18:38:47.491][102388/114664 10][54264/54988  2] MQTT RCV: p1b22.val = 0
Prompt > [18:38:47.555][102388/114664 10][54540/54908  1] MQTT RCV: p1b25.text =
Prompt > [18:38:47.566][102388/112808  9][54540/54908  1] MQTT PUB: p1b25 => {"text":"Ladestart: 04:00"}

After this, p1b25 still shows "Ladestart: 04:00"

he-so avatar Nov 20 '25 18:11 he-so

OK, so the MQTT message is received and the topic is hasp/plate01/command/p1b25.text with empty payload. The default documented behavior of openHASP on empty payload is to respond with the current value: https://openhasp.com/0.7.0/commands/mqtt/#issuing-commands

That's why you see 'MQTT PUB: p1b25 => {"text":"Ladestart: 04:00"}' in response.

Docs:

hasp/[nodename]/command/[keyword] topic with payload [parameter(s)] Leave the payload empty to get the current state without changing it.

If you really want to set the text to empty using MQTT, you can use:

hasp/[nodename]/command topic with payload p1b25.text= or hasp/[nodename]/command/p1b25.jsonl topic with payload {"text"=""}

fvanroie avatar Nov 20 '25 19:11 fvanroie

If you really want to set the text to empty using MQTT, you can use:

hasp/[nodename]/command topic with payload p1b25.text=

Unfortunately, not. It's the same behaviour:

Prompt > [21:09:15.504][102388/114416 10][54216/54980 2] MQTT RCV: = p1b25.text Prompt > [21:09:15.514][102388/114416 10][54216/54980 2] MSGR: p1b25.text Prompt > [21:09:15.524][102388/112568 9][54216/54980 2] MQTT PUB: p1b25 => {"text":"Ladestart: 04:00"}

or hasp/[nodename]/command/p1b25.jsonl topic with payload {"text"=""}

Ok, this does the trick, when using a json style colon like {"text":""}

Prompt > [21:15:09.651][102388/114416 10][54216/54980 2] MQTT RCV: p1b25.jsonl = {"text":""}

I am still wondering how sending this corner case mqtt message can be integrated into a homeassistant yaml config. In case there are real use cases for this empty message behaviour in openHASP, should not the custom component in homeassistant handle this?

he-so avatar Nov 20 '25 21:11 he-so

The command payload needs the equal sign too p1b25.text= . It's exactly that equal sign that treats it as a set command, while without that equal sign (or blank payload) it is interpreted as a get command.

fvanroie avatar Nov 20 '25 22:11 fvanroie

\u200B

Yes, this works. Surprisingly, without | e.

I've almost completely switched to "hidden":true in my code, saving myself a lot of hassle. This also saves me several lines of code.

schabau avatar Nov 26 '25 15:11 schabau