SSD1306 as display in automation possible?

Hello,

is it possible to use a SSD1306 oled in an automation, meaning can i send a text message, written in automations, to this screen when a event happens? Or can you not set it up this way?

I know it works with mqqt, but just wondering if homeassistant would see it as a screen too.

thank you

Yes, create a service Native API Component — ESPHome

Thank you for your reply,

I think i asked the wrong question, with automation i mean the one you set up in Homeassistant, not on the espnode itself. My desired result is to have a Espnode with a oled attached to it, that can receive text messages send by Homeassistant. So i need to set up the oled on the espnode as a “receiver”.

Maybe im not understading it correctly, but will this still work with the native api?

Hi
I tried this some time ago. I did like this:

Use text sensor in esphome to get the text from home assistant.

And in home assistant I used/created a input_text helper.

In which I the changed the text on input_text from an automation in home-assistant.

Then the text sensor in esphome received the text.

The text sensor:

text_sensor:
  - platform: homeassistant
    name: "EspText"
    id: esp_text
    entity_id: input_text.esptext

And in the display part of the code I referenced it.

it.printf(0, 10,id(small_font), "%s", id(esp_text).state.c_str());

I only have some part of this commented out in my test stuff. So I cannot give you a full yaml.

I only rely on display normal redraw cycle. So it took to the next redraw before the text show.

Is this what you are looking for?
/Mattias

1 Like

Very interesting, im now trying to see if i can get it to work with your explanation. I will give you an update when im done!

It works! Thank you very much for your help as this is exactly what i needed.
Is there a way to refresh the screen/make it remove the text after a certain time period?

I will post the code here for others to use:

esphome:
  name: text-message-receiver
  platform: ESP8266
  board:  d1_mini_pro

# Enable logging
logger:

# Enable Home Assistant API
api:

ota:
  password: "af3220770299376c651b77847654b5f5"

wifi:
  ssid: "Your-Wifi-Name"
  password: "Your-Wifi-Password"

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Text-Message-Receiver"
    password: "KufCODrrSJuQ"

captive_portal:

i2c:
  sda: D2
  scl: D1
  scan: False

font:
  - file: 'arial.ttf'
    id: font1
    size: 14 
    
text_sensor:
  - platform: homeassistant
    name: "EspText"
    id: esp_text
    entity_id: input_text.esptext
    
display:
  - platform: ssd1306_i2c
    model: "SSD1306 128x64"
    reset_pin: D0
    address: 0x3C
    lambda: |-
     it.printf(0, 10,id(font1), "%s", id(esp_text).state.c_str());

Hi

Great that you got it to work.
I haven’t found any direct way to trigger redraw of an display.
But there are something called display pages.

So you could pre configure several pages the by trigger change in between them.
So in your case one page with an “empty” and one with the information.

Then switch in between them to toggle between them. To switch the pages are exposed as an signal for automations in esphome.

I haven’t tried it by myself.

Maybe a way to explore.
/Mattias

1 Like

Yes I got it round the wrong way, I was meaning this Native API Component — ESPHome

Redraw is in the instructions here Display Component — ESPHome

1 Like

i got them to rotate but that is not really what i am looking for.
In the automation part I tried to send a 2e empty message after a 5 second delay, but the value can not be empty so it will keep displaying the first message.

Hi

Can you not send one space or a number of spaces.
Instead of the normal text when you want to clear it.

/Mattias

1 Like

You need to send a blank screen. :slight_smile:

Something along the line

it.fill(COLOR_OFF);

EDIT:
Why not share a full example? :wink:

display:
  - platform: ssd1306_i2c
    model: "SSD1306 128x64"
    reset_pin: D0
    address: 0x3C
    lambda: |-
      if (id(timer_on).state == true)
      {
        it.print(0, 8, id(kontrapunkt), "Only");
        it.printf(0, 32, id(kontrapunkt), "%s seconds", id(timer_text).state.c_str());
      }
      else
      {
        it.fill(COLOR_OFF);
      }

Kontrapunkt is the font I’m using.

1 Like

Thank you , although that would mean some tweaking of my code.

That did the trick, a simple spacebar press cleared the screen. So obvious but not :stuck_out_tongue:

1 Like

So the redraw didn’t work?

i couldnt figure that part out unfortunatly

Note

To trigger a redraw right after the page show use a component.update action:

For example cycle through pages on a timer interval: - interval: 5s then: - display.page.show_next: my_display - component.update: my_display

1 Like