The binary sensor does not update the display

i have an Aquara sensor on a window which shows me whether the window is open or closed.

now i would also like to show the status on a display at the front door.

that does not work.
the other indicators such as temperature and power consumption all work and update automatically.

  - platform: homeassistant
    id: schlafzimmerfenster
    entity_id: binary_sensor.fenster_schlafzimmer_offnet
if (id(schlafzimmerfenster)) {
        it.printf(160,120, id(roboto30),TextAlign::CENTER, "offen");
else {
        it.printf(160,120, id(roboto30),TextAlign::CENTER, "zu");
it.printf(160,120, id(roboto30),TextAlign::CENTER, "Window is %s", id(schlafzimmerfenster) ? "Open" : "Closed");

it makes no difference whether i write “id(schlafzimmerfenster)” or “id(schlafzimmerfenster).state”.

the change arrives in ESPhome.

[D][homeassistant.binary_sensor:026]: 'binary_sensor.fenster_schlafzimmer_offnet': Got state ON
[D][binary_sensor:036]: 'schlafzimmerfenster': Sending state ON
[D][homeassistant.binary_sensor:026]: 'binary_sensor.fenster_schlafzimmer_offnet': Got state OFF
[D][binary_sensor:036]: 'schlafzimmerfenster': Sending state OFF

unfortunately i have little knowledge of programming.

what am i overlooking here?

I can’t see anything obvious. I’d be debugging with the .state in place rather than absent.

You could try adding in some logger messages to try to catch where it is going wrong (i.e at the if or the printf level).

if (id(schlafzimmerfenster).state) {
        ESP_LOGD("custom", "Test 1");
        it.printf(160, 120, id(roboto30),TextAlign::CENTER, "offen");
else {
        ESP_LOGD("custom", "Test 2");
        it.printf(160, 120, id(roboto30),TextAlign::CENTER, "zu");
1 Like

If you don’t use .state - you are referring to the whole sensor object, rather than it’s value.

In other words - you need to add .state to the sensor id.


but with “.state” it does not work either.

What does it actually print? Anything? Maybe post the rest of the yaml so we can see that code in the context of the whole display code?

Also give as an example of the expected out versus what you see on the display?

The logs showing the binary sensor updating and your custom log output would be good too.

1 Like

with “it.print” instead of “it.printf” it works

maybe because i had not specified any formatting for printf?

1 Like

Yep - that would be it. Don’t worry I think many have been caught doing that - including me.

1 Like

this works :slight_smile:

      static bool show = false;
      if (id(schlafzimmerfenster).state) {
        it.print(160,120,id(roboto40),id(my_red), TextAlign::CENTER_RIGHT,"Fenster:");
        if (show) {
            it.print(318, 120, id(roboto40), id(my_red), TextAlign::CENTER_RIGHT, "offen");
        show = !show;

the text only appears when the window is open and “Offen” (OPEN) additionally blinks

“show” is only for blinking

The tip from @Mahko_Mahko with ESP_LOGD helped a lot.

1 Like