Can I use this code also for the ESP8266? By just changing ESP32 to ESP8266?
Or will that not work?
Also can I provide mqtt username and password?
Because I do have that on my mqtt server.
Can I use this code also for the ESP8266? By just changing ESP32 to ESP8266?
Or will that not work?
Also can I provide mqtt username and password?
Because I do have that on my mqtt server.
Not exactly, but you can flash a ESP8266, many of us have done it, see my post here of the code I’m using:
Yes this is actually for Esp32 and will work only there. I have made a version for my other esp8266 based SmallTV as well, will post it later. It comes with a few quirks though and could use some optimisation in terms of display refresh.
Setting the user/pw should work like this:
# Example configuration entry
mqtt:
broker: <broker>
username: <user>
password: !secret mqtt_password
see MQTT Client Component - ESPHome - Smart Home Made Simple
(post deleted by author)
st7789v driver has been deprecated for a while in favor of mipi_spi. This has been mentioned several times over the thread, but unfortunately it is too long to read and find the relevant post…
Just update your display section as follows, while keeping your pages/lambda code. You can also remove all external_components. Key there is the buffer_size, which is a new feature that no longe requires the whole picture to reside on ESP8266 RAM.
- id: my_display
platform: mipi_spi
model: ST7789V
spi_id: spihwd
dimensions:
height: 240
width: 240
offset_height: 0
offset_width: 0
buffer_size: 12.5%
invert_colors: true
dc_pin: GPIO00
reset_pin: GPIO02
color_depth: 16
update_interval: never
spi_mode: mode3
data_rate: 40000000
auto_clear_enabled: False
That did it, thanks!
This is the updated version of the yaml for the ESP8266 using the most adequate driver (Thanks to @lhartmann)
esphome:
name: smalltv
friendly_name: SmallTV
esp8266:
board: esp12e
# Enable logging
# logger:
# level: DEBUG
# WiFi configuration
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
ap:
ssid: "SmallTV Fallback"
password: "secretPW"
captive_portal:
# OTA updates
ota:
- platform: esphome
password: !secret ota_password
# MQTT broker configuration (no user/password)
mqtt:
broker: <broker hostname>
port: 1883
on_json_message:
- topic: <topic>
then:
- lambda: |-
if (!x["items"].is<JsonArrayConst>()) return;
JsonArrayConst items = x["items"].as<JsonArrayConst>();
int count = items.size();
if (count > 10) count = 10;
id(item_count) = count;
for (int i = 0; i < count; i++) {
JsonObjectConst item = items[i].as<JsonObjectConst>();
std::string label = item["label"].as<std::string>();
std::string value = item["value"].as<std::string>();
std::string rgb = item["value_rgb"].as<std::string>();
id(item_labels)[i] = label;
id(item_values)[i] = value;
id(item_colors)[i] = rgb;
}
for (int i = count; i < 10; i++) {
id(item_labels)[i] = "";
id(item_values)[i] = "";
id(item_colors)[i] = "FFFFFF";
}
- component.update: my_display
# Global variables to store parsed data
globals:
- id: item_count
type: int
restore_value: no
initial_value: "0"
- id: item_labels
type: std::string[10]
restore_value: no
- id: item_values
type: std::string[10]
restore_value: no
- id: item_colors
type: std::string[10]
restore_value: no
# Fonts
font:
- file: "gfonts://Roboto"
id: font_header
size: 16
- file: "gfonts://Roboto"
id: font_label
size: 14
- file: "gfonts://Roboto"
id: font_value
size: 16
color:
- id: color_bg
hex: "0A0A1A"
- id: color_header_bg
hex: "1A1A2E"
- id: color_header_text
hex: "00BFFF"
- id: color_row_bg
hex: "16213E"
- id: color_row_border
hex: "0F3460"
- id: color_label_text
hex: "A0A0C0"
- id: color_default_value
hex: "00FF88"
output:
- platform: esp8266_pwm
pin: GPIO05
frequency: 20 Hz
id: pwm_output
light:
- platform: monochromatic
output: pwm_output
name: "Backlight"
spi:
clk_pin: GPIO14
mosi_pin: GPIO13
interface: hardware
id: spihwd
display:
- id: my_display
platform: mipi_spi
model: ST7789V
spi_id: spihwd
dimensions:
height: 240
width: 240
offset_height: 0
offset_width: 0
buffer_size: 12.5%
invert_colors: true
dc_pin: GPIO00
reset_pin: GPIO02
color_depth: 16
update_interval: never
spi_mode: mode3
data_rate: 40000000
auto_clear_enabled: False
lambda: |-
// it.filled_rectangle(0, 0, 240, 240, Color(255, 0, 0));
// it.printf(120, 120, id(font_label), Color(255, 255, 255), TextAlign::CENTER, "HELLO");
auto hex_to_color = [](const std::string &hex) -> Color {
uint32_t rgb = 0x00FF88;
if (hex.length() == 6) {
rgb = strtoul(hex.c_str(), nullptr, 16);
}
uint8_t r = (rgb >> 16) & 0xFF;
uint8_t g = (rgb >> 8) & 0xFF;
uint8_t b = rgb & 0xFF;
return Color(r, g, b);
};
int w = 240;
int y = 0;
int header_h = 25;
int row_h = 34;
// Background
it.filled_rectangle(0, 0, w, 240, id(color_bg));
// Header bar
it.filled_rectangle(0, 0, w, header_h, id(color_header_bg));
it.printf(w / 2, header_h / 2, id(font_header), id(color_header_text), TextAlign::CENTER, "AS20");
y = header_h;
int count = id(item_count);
if (count > 6) count = 6;
if (count == 0) {
it.printf(w / 2, y + 20, id(font_label), id(color_label_text), TextAlign::CENTER, "Waiting for data...");
}
for (int i = 0; i < count; i++) {
int row_y = y + i * row_h;
// Row background
it.filled_rectangle(0, row_y, w, row_h, id(color_row_bg));
// Bottom border
it.horizontal_line(0, row_y + row_h - 1, w, id(color_row_border));
// Label on left
it.printf(6, row_y + row_h / 2, id(font_label), id(color_label_text), TextAlign::CENTER_LEFT, "%s", id(item_labels)[i].c_str());
// Value on right with dynamic color
Color val_color = hex_to_color(id(item_colors)[i]);
it.printf(w - 5, row_y + row_h / 2, id(font_value), val_color, TextAlign::CENTER_RIGHT, "%s", id(item_values)[i].c_str());
}