Writing text to lcd

Hi There,

I hooked a esp8266 to a dual relay board and an 20x4 lcd using i2c - nothing special. The relays do want I want them to do and got “Hello World!” printed to the lcd (from the esphome website example) but I’m running into a wall when I want to display these things:

  • ip-address
  • wifi signal strengh
  • time relay last triggered by person.name
    and if that triggered and open of close of the door.

I found WiFi Info Text Sensor — ESPHome but there is no example how to embed that or use it. Since this is the first time I’m using esphome bit overwhelmed by yaml and the lambda notations.

I’m sure I’m not the only one that has asked this but what I found did not work and did not find indepth information about how to use WiFi Info Text Sensor.

Could use some help on it.

Regards,
Sjoerd

Start with simple setup.
Add a sensor of your interest like:

sensor:
  - platform: wifi_signal 
    name: "WiFi Signal dB"
    id: wifi_signal_db
    update_interval: 10s
    entity_category: "diagnostic"

and on your display component instead of printing “hello world” print the sensor value:

lambda: |-
  it.printf(0, 0, id(font1), "%.1f", id(wifi_signal_db).state);

ps. not tested

Hey Karosm,

I had to remove id(font) because the compiler has no idea what font1 is (neither do I tbf). Then it works. My yaml for the sensor and lcd are now:

display:
  - platform: lcd_pcf8574
    id: mydisplay
    dimensions: 20x4
    address: 0x27
    lambda: |-
      it.printf(0, 0, "%.1f", id(wifi_signal_db).state);
      it.printf(0, 1, "%.1f", id(wifi_signal_db_pct).state);

sensor:
  - platform: wifi_signal 
    name: "WiFi Signal dB"
    id: wifi_signal_db
    update_interval: 10s
    entity_category: "diagnostic"
  - platform: copy # Reports the WiFi signal strength in %
    source_id: wifi_signal_db
    id: wifi_signal_db_pct
    name: "WiFi Signal Percent"
    filters:
      - lambda: return min(max(2 * (x + 100.0), 0.0), 100.0);
    unit_of_measurement: "Signal %"
    entity_category: "diagnostic"
    device_class: ""

When the 8266 boots I got nan on lines 1 and 2, when the 8266 is connected I got on line 1 the dB and on line 2 the strength in percentages… Next step will be the capture the nan and show “connecting…” or something.

Regards,
Sjoerd

Just put if statement for the state of sensor:

if (idiwifi_signal_db).has_state()) {
  it.printf(0, 0, "%.1f", id(wifi_signal_db).state);
      }
else {
  it.printf(0, 0, "connecting");
}

has_state is indeed better - I got this working but has_state is indeed better. Made and adjustment because I dont care about the decimals.

if ( isnan( id(wifi_signal_db).state ) ) {
  it.printf(0, 0, "Connecting...");
} else {
   it.printf(18, 0, "%.0f", round( id(wifi_signal_db_pct).state ) );
}

Next is to display the ip and pref de ssid

Got it:

display:
  - platform: lcd_pcf8574
    id: mydisplay
    dimensions: 20x4
    address: 0x27
    lambda: |-
      if ( ! id(wifi_signal_db).has_state() ) {
        it.printf(0, 0, "Connecting...");
      } else {
        it.printf(18, 3, "%.0f", round( id(wifi_signal_db_pct).state ) );
        it.print(0, 3, id(ip_address).state );
      }

sensor:
  - platform: wifi_signal 
    name: "WiFi Signal dB"
    id: wifi_signal_db
    update_interval: 10s
    entity_category: "diagnostic"
  - platform: copy # Reports the WiFi signal strength in %
    source_id: wifi_signal_db
    id: wifi_signal_db_pct
    name: "WiFi Signal Percent"
    filters:
      - lambda: return min(max(2 * (x + 100.0), 0.0), 100.0);
    unit_of_measurement: "Signal %"
    entity_category: "diagnostic"
    device_class: ""

text_sensor:
  - platform: wifi_info
    ip_address:
      id: ip_address
      name: IP address

Date/Time on line op and last two triggers on lines 2 and 3 with date/time and person.name if my final goal.

You need to setup time component first, then display it
it.strftime(0, 0, “%H:%M”, id(esptime).now());

I didn’t understand the person thing at all…

Got time also working now…

About the person… Hassio has persons, I mean every member of my family has their own account in Hassio. Those are persons and if someone turns on the lights with their phone hassio log shows something like: light livingroom turned on my Sjoerd eg.
The switches I exposed from the esphome device show the same so i was wondering (and I’m positive it can be done) if I could get that information on the esp device

Updated yaml:
Remaining issue: I can update the display when triggered by as soon as if falls back to normal state (relay is only active for 750ms) the message disappears from the display and I have no idea how to control that to be fair…

switch:
  - platform: gpio
    name: Gargedoor on ESP8266
    icon: "mdi:garage"
    id: relay
    pin: 14
    inverted: true
    on_turn_on:
      - delay: 750ms
      - switch.turn_off: relay
      - logger.log: "ESP8266 Garagedoor Switch Turned On!"
    on_turn_off:
      - logger.log: "ESP8266 Garagedoor Switch Turned On!"
  - platform: gpio
    name: Garage lights
    pin: 12
    inverted: true

i2c:
  sda: 4
  scl: 5

display:
  - platform: lcd_pcf8574
    id: mydisplay
    dimensions: 20x4
    address: 0x27
    lambda: |-
      if ( ! id(wifi_signal_db).has_state() ) {
        it.printf(0, 0, "Connecting...");
      } else {
        it.strftime(0, 0, "%d/%m/%Y %H:%M", id(homeassistant_time).now() );
        it.printf(18, 3, "%.0f", round( id(wifi_signal_db_pct).state ) );
        it.print(0, 3, id(ip_address).state );
      }
      if ( id(relay).state ) {
        it.strftime(0, 1, "%H:%M", id(homeassistant_time).now());
        it.print(6, 1, "triggered");
      }

sensor:
  - platform: wifi_signal 
    name: "WiFi Signal dB"
    id: wifi_signal_db
    update_interval: 10s
    entity_category: "diagnostic"
  - platform: copy # Reports the WiFi signal strength in %
    source_id: wifi_signal_db
    id: wifi_signal_db_pct
    name: "WiFi Signal Percent"
    filters:
      - lambda: return min(max(2 * (x + 100.0), 0.0), 100.0);
    unit_of_measurement: "Signal %"
    entity_category: "diagnostic"
    device_class: ""

text_sensor:
  - platform: wifi_info
    ip_address:
      id: ip_address
      name: IP address

time:
  - platform: homeassistant
    id: homeassistant_time

explain little better the circuit. Some latching relay?

Just some coil relays - nothing special really. The esp momentarily activates the relay for just under a second and then releases it. I want to keep in the display when it last happened but as soon as the relay falls back to “off” the message got removed. I think is has to do with id(relay).state but I have no idea how to prevent is from updating. If it was just c++ i had to tinker with I would have stored it and put it on the display when ! id(relay).state or something but I don’t dig this yaml stuff at all yet.

That doesn’t answer my question. What happens during the 750ms if it’s not a latching circuit?
I could read between the lines that you have a garage door with open/close contact toggled with a relay… But I prefer you describe the circuit.

when everything works i will connect the relay to the garagedoor remote - is short: it replaces the physical button press (which shorts two points to trigger the remote)

So you don’t have any feedback and you don’t know if the signal was received or if some other remote was used. One not received button press and your state is out of synch. Can you live with that?

I fact I do since i got a binary read sensor on the door at end and start - i know when door is fully open, fully closed or somewhere in between - cant see if is moving tho - that would be a whole other thing.

But I do not know how to read/get those values into the esp… This is just my first “serious” project using esphome - did more with esp but all using visual code.

I’m off for the time being - dinner - appreciate the input!

I’m pumping here…
Where are those values? Where is the “binary read sensor” connected to ?

the binary sensors are just magnetic read contact and are entities in home assistant. But I use those just to turn on/off the lights in my garage using some fancy node-red flow, but that is entirely beside my question :slight_smile:

Why? I thought you wanted to have a indicator if garage door is open or closed.
Did I miss something?

Yes :slight_smile:

I want to show the last too time the remote got trigigered
something like

12:34 - sjoerd
17:22 - sacha

The display would show this then:

05/01/2025 13:00
12:34 - sjoerd
17:22 - sacha
192.168.1.58    71%

See here home assistant log: I want that (time + person) to show in the display
image

edit: I posted the turn off - but thats fine… hassio shows turned on - and a second later turned off - that exactly the behaviour of the relay

That’s correct behavior, relay stays on only 750ms.
That’s why I wrote you should get the door state from your sensors, not from your “switch”.

For the names you need to find some entity ID to get it on Esphome (or some other way to send it ).