Solved: Esphomeyaml Wifi Info publish

Is there a way to use something like a text sensor to post IP address and MAC address of nodes? I tried various forms of the code below but compiling gives an error.

esphomeyaml code:

text_sensor:
  - platform: template
    name: "IP Address"
    lambda: 'return WiFi.localIP().toString().c_str();'

compiler error message:

src/main.cpp: In lambda function:
src/main.cpp:40:38: error: could not convert 'IPAddress::toString() const()' from 'String' to 'esphomelib::optional<std::basic_string<char> >'
return WiFi.localIP().toString();
^

Thanks!

-Josh

1 Like

Very close, see the docs for why this doesn’t work: https://esphomelib.com/esphomeyaml/components/text_sensor/template.html

lambda: 'return {WiFi.localIP().toString().c_str()};'

1 Like

It was even in Bold. Apologies for missing that. Thanks!

PS. I’m currently working to get setup to contribute to documentation but I’m new to pretty much everything on that side of things (doxygen, sphinx, doing anything with Git other than pull, etc.) Love the project. Keep up the great work and I look forward to helping any way that I can.

-Josh

You the expert…how can I get using lambda… .the MQTT status? like connected…connecting…etc

If you enable logging at the DEBUG level, it publishes that info in log form to the topic:

{node_name}/debug

I know…but I want it locally to write it on a display unit.

I know that this is late to this post, but I came here to get a MAC address sensor. When I did not find one in the forum, I had to make one. This works for the esp8266 devices. Here it is:

esphome code:

text_sensor:
  - platform: template
    name: "MAC Address"
    lambda: |-
      byte mac[6];
      WiFi.macAddress(mac);
      char buffer[18];
      sprintf(buffer, "%X:%X:%X:%X:%X:%X", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
      return {buffer};
    icon: mdi:fingerprint
    update_interval: 1d

Enjoy. [This is my first post]

1 Like

LOL And now for my second post.
I did a bit more research into C++ and learned that this also works.

esphome code:

text_sensor:
  - platform: template
    name: "MAC Address"
    lambda: 'return {WiFi.macAddress().c_str()};'
    icon: mdi:fingerprint
    update_interval: 1d

5 Likes

@GarSys - this was great and very helpful !
Do you know (or know where to look for) how to get MAC address of the AP to which module is connected ?
In the log it comes as: BSSID in the esplog

[09:55:22][C][wifi:443]: WiFi:
[09:55:22][C][wifi:303]:   SSID: 'IOT'
[09:55:22][C][wifi:304]:   IP Address: 192.168.1.13
[09:55:22][C][wifi:306]:   BSSID: 49:AC:AC:AA:00:15

I would like to have this BSSID in the text sensor as well.

This is now all built-in functionality: WiFi Info Text Sensor — ESPHome

1 Like