Installing ESPhome on GEEKMAGIC Smart Weather Clock (smalltv/pro)


I have been trying to follow this thread but have lost my way. My SmartTV-Pro arrived today from AliExpress with a ESP32 (GM32-N16 ?)
Am i correct in thinking I can just compile a esphome file like from @jpaha and upload it as a .bin file into firmware page and it will work ? I am concerned there has been updates mentioned but i have not seen a file more recently. All help gratefully received.

Just give it a try.

I also just tried, in the youtube video I saw, the person recommended to first upload a minimal version, especially without display component. Then the file is a bit smaller and - according to them - that’s more stable or so. Once the minimal version is uploaded you can uncomment the complex stuff and upload via OTA. My min version was line 1 to 50 and the on_boot was commented out too (see below).

@PsyGanja Below my yaml. The display is kept rather stupid. It can process a mqtt message from an automation to fill it as received. The prio is only defining the coloring. Then my display looks like this and a flex-table-card is used to show the same info on my dashboard.

So the trick lies then in rendering this mqtt message and I compose this from the alert2 integration (and give them prio 4,3,2), the home maintenance (and give them prio 1) and then I add stuff, so the display is not empty (prio 0)

My next step: Alert 2 allows to acknowledge alerts, so I want to add the on_tap action to the flex-table, so I can make message disappear easily =)

sample payload template
{% set ns = namespace(payload= [
{'name':'TEST DATA','msg':'DATA TEST','prio':4},
{'name':'Wasserleck Spüle','msg':'','prio':4},
{'name':'Boiler kalt','msg':'40°C','prio':3},
{'name':'Waschmaschine fertig','msg':'','prio':2},
{'name':'Reinige Flusensieb','msg':'','prio':1},
{'name':'Reinige Katzenklo draußen','msg':'','prio':1},
{'name':'Solarleistung','msg':'50W','prio':0},
{'name':'Batterie SNZB01-02','msg':'10%','prio':3},
]) %}
{% set ns.payload = ns.payload|sort(attribute='prio',reverse=True) %}
{{ ns.payload|tojson }}
ultra-smart-01.yaml
substitutions:
  device_name: "ultra-smart-01" 
  friendly_name: "Geek Yellow"
  font_size: "21"  
  font_size_small: "18"
  line_separation: "4"
  mqtt_display_topic: "homestatus/display/rawdata"
api:
  encryption:
    key: !secret ultra_smart_01_api_encryption_key
ota:
  - platform: esphome
    password: !secret ultra_smart_01_ota_password

### SAME SAME from here, for potential other displays

esphome:
  name: ${device_name}
  friendly_name: ${friendly_name}
# Is this really needed? 
#  platformio_options: 
#    board_build.f_cpu: 160000000L
  on_boot:
    priority: 500 
    then:
      - lambda: |-
            // Simulate a payload, so there is a propper boot message and
            // all variables are defined. 
            String boot_value = "[{'prio': 0,'name': 'Waiting for message','msg': ''}]";
            id(automation_display_text).publish_state(boot_value.c_str());

esp8266:
  board: esp12e

logger:
  level: ERROR

# Enable Home Assistant API

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
   ssid: "${device_name} Fallback"
   password: !secret wifi_captive_password
   channel: !secret wifi_captive_channel
captive_portal:

################

time:
  - platform: sntp
    id: sntp_time 
    timezone: Europe/Berlin

mqtt:
  broker: !secret mqtt_broker
  discovery: false # so entities don't show up twice in Home Assistant
  reboot_timeout: 0s # not sure, if needed. 
  username: !secret mqtt_username
  password: !secret mqtt_password
  on_message:
    - topic: ${mqtt_display_topic}
      then:
        - lambda: |-
            id(automation_display_text).publish_state(x);
            id(automation_display_text_last_received).publish_state((id(sntp_time).now().strftime("%Y-%m-%dT%H:%M:%S%z")).c_str());
        - delay: 200ms    
        - component.update: my_display
        - delay: 500ms # I had the feeling, the first redering sometimes does not complete correctly. 
        - component.update: my_display

color:
  - id: color_error
    hex: eb1c24  
  - id: color_red
    hex: eb1c24
  - id: color_yellow
    hex: fcb712
  - id: color_blue
    red: 0
    green: 0
    blue: 100%
  - id: black_color
    red: 0
    green: 0
    blue: 0    
  - id: color_green
    red: 0
    green: 100%
    blue: 0
  - id: color_white
    red: 100%
    green: 100%
    blue: 100%


text_sensor:
  - platform: template
    name: "Display Text Automation"
    id: automation_display_text
  - platform: template
    id: automation_display_text_last_received
    name: "Last MQTT Message on"
    device_class: "timestamp"
    entity_category: diagnostic


sensor:
  - platform: uptime
    name: "Uptime"
  - platform: wifi_signal
    name: "WiFi Signalstärke"
    update_interval: 60s
  - platform: template
    name: "${friendly_name} Freier Speicher (RAM)"
    id: free_ram_sensor
    entity_category: diagnostic
    unit_of_measurement: "B"
    update_interval: 60s
    lambda: |-
      return ESP.getFreeHeap();

button:
  - platform: restart
    name: "Neustart"
  - platform: safe_mode
    name: "Neustart (Safe Mode)"    

output:
  - platform: esp8266_pwm
    pin: GPIO5 # Bestätigter korrekter Pin
    frequency: 1000 Hz
    id: pwm_backlight
    inverted: true 

light:
  - platform: monochromatic
    output: pwm_backlight
    name: "Geek Display Backlight"
    id: backlight
    restore_mode: ALWAYS_ON 

spi:
  clk_pin: GPIO14
  mosi_pin: GPIO13
  id: spihwd
  interface: hardware

font:
  - file: "gfonts://Roboto"
    id: font_default
    size: ${font_size}
    glyphs:
      - "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
      - "!@#$%^&*()_+-=,./?[]{}<>\"':;|~` "
      - "äÄöÖüÜ߀°"

  - file: "gfonts://Roboto"
    id: font_small
    size: ${font_size_small}
    glyphs:
      - "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
      - "!@#$%^&*()_+-=,./?[]{}<>\"':;|~` "
      - "äÄöÖüÜ߀°"

  - file: "fonts/materialdesignicons-webfont.ttf"
    id: icon_font
    size: 25
    glyphs: [
      '', # mdi-thermometer
      '', # mdi-water-percent
      "", # mdi-alert-outline
      ]


# TODO: Use this instead of the switch statement later?
#    std::map<std::string, std::string> weather_state { 
 #       { "clear-day", "" },             // mdi:weather-sunny
#
 #       { "partly-cloudy-day", "" },     // mdi:weather-partly-cloudy
  #      { "partly-cloudy-night", "n" }    // mdi:weather-night-partly-cloudy
   # };




display:
  - id: my_display
    platform: mipi_spi # Interner, stabiler Treiber
    model: ST7789V      
    spi_id: spihwd
    dimensions:
      height: 240
      width: 240
      offset_height: 0 
      offset_width: 0

    dc_pin: GPIO00
    reset_pin: GPIO02
    
    buffer_size: 12.5%
    invert_colors: true
    color_depth: 16
    color_order: BGR # Korrektur der Farbreihenfolge
    spi_mode: mode3
    data_rate: 40000000
    
    rotation: 0° # Startet mit 0° (horizontal)
    auto_clear_enabled: False
    update_interval: 60s 
    
    lambda: |-
      static int margin_bottom=4; // the display bottom is coverd byx the housing =(
      static int separator_line_width=4; // thickness of the separation lines. 
      
      JsonDocument doc; // TODO: Find out how to define globals, so this can be filled when a message comes. 
      deserializeJson(doc, id(automation_display_text).state);

      int y=0;
      auto color = Color();
      int last_prio = 99;

      it.fill(id(black_color)); 
      delay(10); 

      for (JsonObject elem : doc.as<JsonArray>()) {
          String str = elem["name"].as<String>();
          String msg = elem["msg"].as<String>();
          int    p   = elem["prio"].as<int>();
          
          switch (p) {
            case 0: color = Color(id(color_green));   break; // Info
            case 1: color = Color(id(color_white));   break; // Tasks             
            case 2: color = Color(id(color_blue));    break; // Alert2 Low
            case 3: color = Color(id(color_yellow));  break; // Alert2 Medium
            case 4: color = Color(id(color_red));     break; // Alert2 High
          }
          
          if(p < last_prio){// only draw a line, if the previous prio was higher. 
            y += separator_line_width-${line_separation};
            it.filled_rectangle(0,y,it.get_width()-1,separator_line_width,color);
            y += separator_line_width;
            last_prio=p;
          }
          // left text
          it.printf(0,y,id(font_default), color, "%s", str.c_str());
          // right text
          it.printf(it.get_width()-1,y,id(font_default), color, TextAlign::TOP_RIGHT,"%s", msg.c_str());
          y += ${font_size} + ${line_separation};
      }       

      // IP Adresse
      // it.print(0, it.get_height()-1-margin_bottom, id(font_small), TextAlign::BOTTOM_LEFT, (String("IP: ") + WiFi.localIP().toString()).c_str());
      // Uhrzeit
      it.strftime(it.get_width()-1, it.get_height()-1-margin_bottom, id(font_small), TextAlign::BOTTOM_RIGHT,"%H:%M", id(sntp_time).now());

You can always attach GPIO0 from the header, to a switch, drilled on top or side of the cage … just don’t press it during boot and should work

I wasn’t sure because of that boot thing yeah… I’ll dig a bit on that side.

I know the topic is mainly about firmware, but I wanted to share an alternative approach I’m using to integrate the device with Home Assistant, in case anyone finds it useful.

The idea is pretty straightforward: generate a 240x240px image from an HTML template, then upload it to the device using its API. I ended up writing a small service that renders the image, and upload it through Home Assistant using the Shell Commnand integration:

configuration.yaml

...
shell_command:
  geek_magic_set_brt: ./geekmagic.sh set_brt "{{ value }}"
  geek_magic_set_img: ./geekmagic.sh set_img "{{ filename }}"
  geek_magic_get_theme: ./geekmagic.sh get_theme
  geek_magic_set_theme: ./geekmagic.sh set_theme "{{ theme }}"
  geek_magic_set_text: ./geekmagic.sh set_text "{{ subject }}" "{{ text }}"
  geek_magic_set_html: ./geekmagic.sh set_html "{{ html }}"
...

The geekmagic.sh script simply performs a few curl calls to both the rendering service and the device’s API.

Everything else is just scripts and automations inside Home Assistant.


Nice work. Give more code please.

Here you’ll find everything needed for the Home Assistant configuration, including a few script examples.
The HTML rendering service is self-written and available here. If you don’t want to build it yourself, you can use the prebuilt Docker image at docker.io/aydarik/text2image - just expose port 8000.

I could also share my personal running instance of the renderer if you don’t have much experience with Python/Docker. In that case, please DM me, don’t want to share it publicly.

I have a smalltv-pro. Does anyone know if the pinout is the same? The board looks different and the square pin seems to be on the other side.

I used the same pinout as in the first post:

My board has the same version number and this worked well for me installing basic ESPHome. I have not installed a working yaml yet, the code in this thread seems to work only with ESP8266, not with ESP32.

OK, but on which side is GND?

BTW, there is also code on this thread for the ESP32 version, I think.

When you do the reset, does the display background light go off for a second?
Mine is soft-bricked and when I connect GND and RST for a second, I see no reaction and after 10 times, it is still not connected to my WiFi again.
I had it working on WiFi but adding some stuff in the display section soft-bricked it.

Right in my picture - blue wire. Top in you picture.

It the right yaml for ESP32 is in the thread I havent found it yet… :slight_smile:

Thanks a lot! Was finally able to re-flash it via USB.

I think this post is about the ESP32:

The one I linked above is working. I stripped it down to one widget and this works for my smalltv-pro:

esphome:
  name: smalltv-pro
  friendly_name: SmallTV-Pro

esp32:
  board: esp32dev
  framework:
    type: arduino

# WiFi with fallback AP
wifi:
  ssid: "xxx"
  password: "xxx"
  ap:
    ssid: "smalltvpro_fallback"
    password: "xxx"

# Logging
logger:

# OTA updates
ota:
  platform: esphome

# ESPHome API for openHAB
api:
  encryption:
    key: "xxx"

# Web server for browser access
web_server:
  port: 80

# Define a PWM output on the ESP32
output:
  - platform: ledc
    pin: GPIO25
    inverted: True
    id: backlight_pwm

# Define a monochromatic, dimmable light for the backlight
light:
  - platform: monochromatic
    output: backlight_pwm
    name: "Display Backlight"
    id: back_light
    restore_mode: ALWAYS_ON
    on_turn_on:
      - light.turn_on:
          id: back_light
          brightness: 1.0  # Set initial brightness to 100% on power up

spi:
  clk_pin: GPIO18
  mosi_pin: GPIO23
  interface: hardware
  id: spihwd

display:
  - platform: ili9xxx
    id: lcd_display
    model: st7789v
    spi_id: spihwd
    data_rate: 40MHz
    dc_pin: GPIO02
    reset_pin: GPIO04
    spi_mode: MODE3
    dimensions:
      width: 240
      height: 240
      offset_height: 0
      offset_width: 0
    invert_colors: true
    auto_clear_enabled: false
    update_interval: never

lvgl:
  log_level: INFO
  color_depth: 16
  bg_color: 0
  border_width: 0
  outline_width: 0
  #shadow_width: 0
  #text_font: unscii_16
  #align: center
  style_definitions:
    - id: font_style
      text_color: 0xFFFFFF
      bg_color: 0
      bg_opa: TRANSP
    - id: details_style
      text_font: MONTSERRAT_16
      text_color: 0xFFFFFF
      bg_color: 0
      bg_opa: TRANSP

  buffer_size: 25%
  widgets:
    - label:
        id: powerverschenkt_label
        text: "This is a test!"
        x: 35 
        y: 20
        #width: 100
        #text_align: CENTER
        styles: font_style
        text_font: MONTSERRAT_30 # override font size
        text_color: 0x00ff00

Now need to learn the UI syntax. :wink:

Can anyone please tell me why the display is flickering after boot for a while with this code above? Later it goes away.

Also, it does not boot ever time. Sometimes, it gets stuck with empty display and not connected to the WiFi.

GPIO0 is already DC Pin for the screen !..

Ends up soldering directly on the GPIO4 which was unused and worked like a charm :wink:

:milky_way: Cyberpunk vibes for your Home Assistant setup!

Check out this awesome GeekMagic Cyberpunk integration/manual – perfect for giving your dashboard that neon, futuristic edge inspired by Cyberpunk 2077.

Includes custom themes, configs, and more to make your smart home feel like Night City. :fire:

Repo: https://github.com/Thalantir/ha_geekmagic_cyberpunk/tree/main

#HomeAssistant #Cyberpunk2077 #SmartHome #HASS