From c14af378a18c5e5f13c12e7cae44a1506bee2641 Mon Sep 17 00:00:00 2001 From: DK <16869713+poldim@users.noreply.github.com> Date: Thu, 21 Jan 2021 14:28:15 -0800 Subject: [PATCH] Add directions for handling text strings (#955) --- components/display/index.rst | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/components/display/index.rst b/components/display/index.rst index 551b5a566..098a59fca 100644 --- a/components/display/index.rst +++ b/components/display/index.rst @@ -277,7 +277,16 @@ arguments after the format string in the right order. // %% - literal % sign it.printf(0, 0, id(my_font), "Temperature: %.1f°C, Humidity: %.1f%%", id(temperature).state, id(humidity).state); +To display a text string from a ``text_sensor``, append ``.c_str()`` to the end of your variable. +.. code-block:: yaml + + display: + - platform: ... + # ... + lambda: |- + it.printf(0, 0, id(my_font), "Text to follow: %s", id(template_text).state.c_str()); + The last printf tip for use in displays I will discuss here is how to display binary sensor values. You *could* of course just check the state with an ``if`` statement as the first few lines in the example below, but if you want to be efficient you can use an *inline if* too. With the ``%s`` print specifier you can tell it to