Skip to main content

Home AssistantでのreTerminal E Series ePaperディスプレイの高度なESPHome使用法


この記事では、reTerminal E Series ePaperディスプレイデバイスの高度なESPHome設定について探求し、基本的なESPHome使用ガイドで説明した基礎概念を基に構築します。ESPHomeやreTerminal E Seriesが初めての方は、これらの高度なアプリケーションに取り組む前に、基本ガイドから始めることをお勧めします。

ハードウェア機能

reTerminal E Series ePaperディスプレイには、ESPHomeを通じてHome Assistantで活用できるいくつかのハードウェアコンポーネントが含まれています:

  • 3つのプログラマブルボタン(GPIO3、GPIO4、GPIO5)

  • ブザー(GPIO45)

  • バッテリーレベル監視(電圧用GPIO1)

  • オンボードLED(GPIO6)

  • 温度・湿度センサー(I²Cインターフェース)

これらの各コンポーネントを実用的なアプリケーションで使用する方法を探ってみましょう。

reTerminal E Series ePaperディスプレイハードウェアコンポーネント制御

Home AssistantでreTerminal E Series ePaperディスプレイの各ハードウェアコンポーネントを使用する方法を探ってみましょう。

ボタンとLED

この例では、reTerminal E Series ePaperディスプレイの3つのボタンを使用して機能を制御し、オンボードLEDで視覚的フィードバックを提供する方法を示します。

以下のコードをコピーして、YamlファイルのCaptive_portalコード行の後に貼り付けることで、この例を使用できます。

# Button configuration
binary_sensor:
- platform: gpio
pin:
number: GPIO3 # Green button
mode: INPUT_PULLUP
inverted: true
id: button_1
name: "Button 1"
on_press:
then:
- light.turn_on: onboard_led
- delay: 500ms
- light.turn_off: onboard_led

- platform: gpio
pin:
number: GPIO4 # Right white button
mode: INPUT_PULLUP
inverted: true
id: button_2
name: "Button 2"
on_press:
then:
- light.turn_on: onboard_led
- delay: 200ms
- light.turn_off: onboard_led
- delay: 200ms
- light.turn_on: onboard_led
- delay: 200ms
- light.turn_off: onboard_led

- platform: gpio
pin:
number: GPIO5 # Left white button
mode: INPUT_PULLUP
inverted: true
id: button_3
name: "Button 3"
on_press:
then:
- light.toggle: onboard_led

# LED configuration
output:
- platform: gpio
pin: GPIO6
id: led_output
inverted: true

light:
- platform: binary
name: "Onboard LED"
output: led_output
id: onboard_led

この設定では:

  • プルアップ抵抗付きの入力として3つのボタンすべてを設定
  • ボタン1をLEDを短時間点滅させるように設定
  • ボタン2をLEDをダブル点滅パターンで点滅させるように設定
  • ボタン3をLEDのオン/オフを切り替えるように設定
  • LEDをHome Assistantで制御可能なライトエンティティとして利用可能にする

ブザー制御

reTerminal E Series ePaperディスプレイには、音声フィードバックを提供するために使用できるGPIO45のブザーが含まれています。設定方法は以下の通りです:

以下のコードをコピーして、YamlファイルのCaptive_portalコード行の後に貼り付けることで、この例を使用できます。

# This component creates a raw PWM (Pulse Width Modulation) output signal.
# For ESP32, the correct platform is 'ledc', which uses the dedicated LED Control hardware peripheral.
output:
- platform: ledc # CORRECTED: 'ledc' is the correct platform for ESP32 PWM.
pin: GPIO45
id: buzzer_pwm
# The frequency determines the pitch of the buzzer's sound. 1000Hz is a mid-range tone.
frequency: 1000Hz

# Create a light entity to provide a user-friendly way to control the buzzer.
# The 'brightness' of the light will control the PWM duty cycle, which effectively changes the buzzer's volume.
light:
- platform: monochromatic
output: buzzer_pwm
name: "Buzzer"
id: buzzer
# Setting transition length to 0s makes the buzzer turn on and off instantly.
default_transition_length: 0s

# This section defines the physical button that will trigger the buzzer.
binary_sensor:
- platform: gpio
pin:
number: GPIO3 # The GPIO pin connected to the green button.
mode: INPUT_PULLUP # Use the internal pull-up resistor.
inverted: true # The signal is low when pressed.
id: button_1
# 'on_press' defines the sequence of actions to execute when the button is pressed.
on_press:
then:
# First beep: turn on at 50% volume (brightness) for 200 milliseconds.
- light.turn_on:
id: buzzer
brightness: 50%
- delay: 200ms
- light.turn_off: buzzer
# Pause for 100 milliseconds between beeps.
- delay: 100ms
# Second beep: turn on at 70% volume for 200 milliseconds.
- light.turn_on:
id: buzzer
brightness: 70%
- delay: 200ms
- light.turn_off: buzzer

この設定では:

  • ブザーをPWM出力として設定
  • ブザーを制御するライトエンティティを作成
  • ボタン1を押したときに短いビープパターンを再生するように設定
tip

frequencyパラメータを調整してブザーの音程を変更できます。値が高いほど高音になります。

バッテリー監視

reTerminal E Series ePaperディスプレイは、GPIO1のアナログ入力を通じてバッテリーレベルを監視できます。設定方法は以下の通りです:

esphome:
name: reterminal-e10xx
friendly_name: reTerminal_E10xx
on_boot:
priority: 600
then:
- output.turn_on: bsp_battery_enable

esp32:
board: esp32-s3-devkitc-1
framework:
type: arduino

# Enable logging
logger:

# Enable Home Assistant API
api:
encryption:
key: "m+rOiVDwjdvePoiG1zritvcD0Kl/a2zmsnuG+4IfWlw="

ota:
- platform: esphome
password: "710fecea969062a5775b287a54f3c0f5"

wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password

# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "Reterminal-E10Xx"
password: "tRc2fXaYE54Q"

captive_portal:

output:
- platform: gpio
pin: GPIO21
id: bsp_battery_enable

sensor:
- platform: adc
pin: GPIO1
name: "Battery Voltage"
id: battery_voltage
update_interval: 60s
attenuation: 12db
filters:
- multiply: 2.0 # Voltage divider compensation

- platform: template
name: "Battery Level"
id: battery_level
unit_of_measurement: "%"
icon: "mdi:battery"
device_class: battery
state_class: measurement
lambda: 'return id(battery_voltage).state;'
update_interval: 10s
filters:
- calibrate_linear:
- 4.15 -> 100.0
- 3.96 -> 90.0
- 3.91 -> 80.0
- 3.85 -> 70.0
- 3.80 -> 60.0
- 3.75 -> 50.0
- 3.68 -> 40.0
- 3.58 -> 30.0
- 3.49 -> 20.0
- 3.41 -> 10.0
- 3.30 -> 5.0
- 3.27 -> 0.0
- clamp:
min_value: 0
max_value: 100

この設定では:

  • ADCを通じてバッテリー電圧を読み取り
  • 校正曲線を使用して電圧をバッテリーパーセンテージに変換
  • 生の電圧とパーセンテージの両方をHome Assistantで利用可能にする
caution

バッテリーレベルを測定するには、GPIO21ピンを有効にする必要があります。そうしないと、GPIO1からバッテリー電圧値を読み取ることができません。

デモ2. Home Assistantダッシュボードをスクリーンショットとして撮影

この例では、Home Assistantダッシュボードのスクリーンショットを撮影し、reTerminal E Seriesに表示する方法を示します。

Puppetアドオンのインストール

ステップ1. まず、Puppetアドオンをインストールする必要があります。以下のボタンをクリックすると、Home Assistantインスタンスのアドオンインストールページに直接移動します:

ステップ2. アドオンページで「INSTALL」ボタンをクリックし、インストールが完了するまで待ちます。

アクセストークンの作成

ステップ3. インストール後、Puppetアドオンの設定ページに移動します。ご覧のように、ここでトークンを入力する必要があります。このアドオン用のアクセストークンを作成する必要があります。

ステップ4. 左下のユーザー名をクリックしてHome Assistantのプロフィールに移動し、ページ下部の「長期アクセストークン」を選択します。

ステップ5. 「Puppet Screenshot」のような説明的な名前で新しいトークンを作成し、生成されたトークンをコピーします。

ステップ 6. Puppet アドオンの設定に戻り、「Long-Lived Access Token」フィールドにトークンを貼り付けます。

ステップ 7. 設定を保存し、Puppet アドオンを再起動します。

スクリーンショット API の理解

Puppet アドオンは、Home Assistant の任意のページのスクリーンショットを生成するサーバーをポート 10000 で起動します。使用方法は以下の通りです:

基本的なスクリーンショット URL 形式

http://homeassistant.local:10000/lovelace/0?viewport=800x480

この URL は、デフォルトダッシュボードを 800x480 解像度(reTerminal E シリーズに最適)でスクリーンショットを撮影します。

E-Paper 最適化

E-Paper ディスプレイの場合、eink パラメータを追加してカラーパレットを削減します:

http://homeassistant.local:10000/lovelace/0?viewport=800x480&eink=2

2 は 2 色(白黒)パレットを表します。

色の反転

invert パラメータを追加して白黒を反転します:

http://homeassistant.local:10000/lovelace/0?viewport=800x480&eink=2&invert

異なるページのキャプチャ

URL パスを変更することで、Home Assistant の任意のページをキャプチャできます:

http://homeassistant.local:10000/todo?viewport=800x480&eink=2&invert

ステップ 10. Web ブラウザにスクリーンショット URL を入力してテストします。選択した Home Assistant ページのスクリーンショットが表示されるはずです。

ESPHome 設定

ステップ 11. captive_portal セクションの後に、以下のコードを ESPHome 設定に追加します:

http_request:
verify_ssl: false
timeout: 10s
watchdog_timeout: 15s

online_image:
- id: dashboard_image
format: PNG
type: BINARY
buffer_size: 30000
url: http://homeassistant.local:10000/lovelace/0?viewport=800x480&eink=2&invert # Replace with your Home Assistant address
update_interval: 30s
on_download_finished:
- delay: 0ms
- component.update: main_display

spi:
clk_pin: GPIO7
mosi_pin: GPIO9

display:
- platform: waveshare_epaper
id: epaper_display
model: 7.50inv2
cs_pin: GPIO10
dc_pin: GPIO11
reset_pin:
number: GPIO12
inverted: false
busy_pin:
number: GPIO13
inverted: true
update_interval: never
lambda: |-
it.image(0, 0, id(dashboard_image));
caution

ネットワークでローカル DNS 解決が機能しない場合は、homeassistant.local を Home Assistant の実際の IP アドレスに置き換えてください。

設定が正常にアップロードされ実行されると、reTerminal E シリーズ ePaper ディスプレイに Home Assistant ダッシュボードのスクリーンショットが表示されます:

デモ 3: ディープスリープモード

tip

ディープスリーププログラムの使用を開始する場合は、右側の白いボタンと組み合わせて使用し、右側の白いボタンをスリープウェイクボタンとして設定することをお勧めします。これにより、プログラムを更新したい場合に、デバイスがスリープ状態でシリアルポート経由でプログラムをアップロードできないという困った状況を避けることができます。

この例では、ディープスリープモードを使用して消費電力を大幅に削減し、reTerminal E シリーズ ePaper ディスプレイをバッテリー駆動アプリケーションに適したものにする方法を示します。

以下のコードをコピーして、Yaml ファイルの captive_portal コード行の後に貼り付けることで、この例を使用できます。

globals:
- id: sleep_counter
type: int
restore_value: yes # Use RTC storage to maintain counter during sleep
initial_value: '0'

# Deep sleep configuration
deep_sleep:
id: deep_sleep_1
run_duration: 30s # Device remains awake for 30 seconds
sleep_duration: 5min # Then sleeps for 5 minutes
# Optional: Use a button to wake from sleep
wakeup_pin: GPIO4
wakeup_pin_mode: INVERT_WAKEUP

interval:
- interval: 29s # Schedule sleep just before run_duration ends
then:
- logger.log: "Entering deep sleep now..."

font:
- file: "gfonts://Inter@700"
id: font1
size: 24

spi:
clk_pin: GPIO7
mosi_pin: GPIO9

display:
- platform: waveshare_epaper
id: epaper_display
model: 7.50inv2
cs_pin: GPIO10
dc_pin: GPIO11
reset_pin:
number: GPIO12
inverted: false
busy_pin:
number: GPIO13
inverted: true
update_interval: 5min
lambda: |-
id(sleep_counter) += 1;
ESP_LOGD("main", "Wakeup count: %d", id(sleep_counter));
it.printf(100, 100, id(font1), "Wakeup count: %d", id(sleep_counter));

この設定は:

  • スリープサイクル間で持続するカウンターを作成します
  • デバイスを 30 秒間起動し、その後 3 分間スリープするように設定します
  • 現在の起動回数でディスプレイを更新します
  • オプションでデバイスを起動するボタンを設定します

実行すると、デバイスがスリープから起動するたびにカウンターが増加するのが確認できます:

デモ 4: 包括的な例

tip

理解を深めるために、この包括的な例を試す前に、上記の基本的な例を最初に実行することを強くお勧めします。

この高度な例では、複数の機能を組み合わせて reTerminal E シリーズの完全なダッシュボードソリューションを作成します。以下を実演します:

  1. 天気と室内気候の表示
  2. アイコン付きバッテリー監視
  3. 時刻と日付の表示
  4. ボタンを使用したページ切り替え
  5. バッテリー監視
完全なコードを表示するにはここをクリック
esphome:
name: reterminal_e1001
friendly_name: reTerminal_E1001
on_boot:
priority: 600
then:
- output.turn_on: bsp_sd_enable
- output.turn_on: bsp_battery_enable
- delay: 200ms
- component.update: battery_voltage
- component.update: battery_level


esp32:
board: esp32-s3-devkitc-1
framework:
type: arduino

# Enable logging
logger:

# Enable Home Assistant API
api:
encryption:
key: "g93yP72UIyVsz9WfffaDMK+JeIQYROIFRK+VIQjkM+g="

ota:
- platform: esphome
password: "1ff187393ee444aa2e892779dc78e488"

wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password

# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "reTerminal-E1001"
password: "yoUkaGlJaDpC"

captive_portal:

# Deep-sleep, wake by GPIO4
deep_sleep:
id: deep_sleep_1
run_duration: 1min
sleep_duration: 60min
wakeup_pin: GPIO4 # Right white button
wakeup_pin_mode: INVERT_WAKEUP

# SPI / I²C
spi:
clk_pin: GPIO7
mosi_pin: GPIO9
i2c:
scl: GPIO20
sda: GPIO19

# Fonts
font:
- file: "gfonts://Inter@700"
id: small_font
size: 24
- file: "gfonts://Inter@700"
id: mid_font
size: 36
- file: "gfonts://Inter@700"
id: big_font
size: 180
- file: "gfonts://Inter@700"
id: time_font
size: 96 # for the big time display
- file: 'fonts/materialdesignicons-webfont.ttf'
id: font_mdi_large
size: 70
glyphs:
- "\U000F050F" # thermometer
- "\U000F058E" # humidity
- file: 'fonts/materialdesignicons-webfont.ttf'
id: font_bat_icon
size: 24
glyphs:
- "\U000F007A" # mdi-battery-10
- "\U000F007B" # mdi-battery-20
- "\U000F007C" # mdi-battery-30
- "\U000F007D" # mdi-battery-40
- "\U000F007E" # mdi-battery-50
- "\U000F007F" # mdi-battery-60
- "\U000F0080" # mdi-battery-70
- "\U000F0081" # mdi-battery-80
- "\U000F0082" # mdi-battery-90
- "\U000F0079" # mdi-battery

globals:
- id: page_index
type: int
restore_value: true
initial_value: '0'
- id: battery_glyph
type: std::string
restore_value: no
initial_value: "\"\\U000F0079\"" # default full battery

sensor:
- platform: sht4x
temperature:
name: "Temperature"
id: temp_sensor
humidity:
name: "Relative Humidity"
id: hum_sensor
- platform: adc
pin: GPIO1
name: "Battery Voltage"
id: battery_voltage
update_interval: 60s
attenuation: 12db
filters:
- multiply: 2.0
- platform: template
name: "Battery Level"
id: battery_level
unit_of_measurement: "%"
icon: "mdi:battery"
device_class: battery
state_class: measurement
lambda: 'return id(battery_voltage).state;'
update_interval: 60s
on_value:
then:
- lambda: |-
int pct = int(x);
if (pct <= 10) id(battery_glyph) = "\U000F007A";
else if (pct <= 20) id(battery_glyph) = "\U000F007B";
else if (pct <= 30) id(battery_glyph) = "\U000F007C";
else if (pct <= 40) id(battery_glyph) = "\U000F007D";
else if (pct <= 50) id(battery_glyph) = "\U000F007E";
else if (pct <= 60) id(battery_glyph) = "\U000F007F";
else if (pct <= 70) id(battery_glyph) = "\U000F0080";
else if (pct <= 80) id(battery_glyph) = "\U000F0081";
else if (pct <= 90) id(battery_glyph) = "\U000F0082";
else id(battery_glyph) = "\U000F0079";
filters:
- calibrate_linear:
- 4.15 -> 100.0
- 3.96 -> 90.0
- 3.91 -> 80.0
- 3.85 -> 70.0
- 3.80 -> 60.0
- 3.75 -> 50.0
- 3.68 -> 40.0
- 3.58 -> 30.0
- 3.49 -> 20.0
- 3.41 -> 10.0
- 3.30 -> 5.0
- 3.27 -> 0.0
- clamp:
min_value: 0
max_value: 100

output:
- platform: gpio
pin: GPIO6
id: bsp_led
inverted: true
- platform: gpio
pin: GPIO16
id: bsp_sd_enable
- platform: gpio
pin: GPIO21
id: bsp_battery_enable

# Onboard LED
light:
- platform: binary
name: "Onboard LED"
output: bsp_led
id: onboard_led

binary_sensor:
- platform: gpio # Next page
pin:
number: GPIO3
mode: INPUT_PULLUP
inverted: true
id: key1
name: "Key1"
on_press:
then:
- lambda: |-
id(page_index) = (id(page_index) + 1) % 2;
id(epaper_display).update();

- platform: gpio # Prev page
pin:
number: GPIO5
mode: INPUT_PULLUP
inverted: true
id: key2
name: "Key2"
on_press:
then:
- lambda: |-
id(page_index) = (id(page_index) - 1 + 2) % 2;
id(epaper_display).update();

# - platform: gpio
# pin:
# number: GPIO4
# mode: INPUT_PULLUP
# inverted: true
# id: key2
# name: "Key2"
# on_press:
# then:
# - lambda: |-
# id(page_index) = (id(page_index) - 1 + 3) % 3;
# id(epaper_display).update();

# Home Assistant time
time:
- platform: homeassistant
id: ha_time

# e-paper
display:
- platform: waveshare_epaper
id: epaper_display
model: 7.50inv2
cs_pin: GPIO10
dc_pin: GPIO11
reset_pin:
number: GPIO12
inverted: false
busy_pin:
number: GPIO13
inverted: true
update_interval: never
lambda: |-
// ---------- PAGE 0 ----------
if (id(page_index) == 0) {
const int scr_w = 800;
const int scr_h = 480;

// Battery in upper-right corner
it.printf(670, 13, id(font_bat_icon), "%s", id(battery_glyph).c_str());
it.printf(700, 10, id(small_font), "%.0f%%", id(battery_level).state);

//line
it.filled_rectangle(400, 100, 2, 280);

// Convert °C to °F
float temp_f = id(temp_sensor).state * 9.0 / 5.0 + 32.0;

// ---------------------------------------------------------
// Horizontal split: two 400 px columns
const int col_w = scr_w / 2;

const int icon_y = 100; // Icon baseline
const int value_y = 220; // Number baseline
const int unit_y = 300; // Unit baseline
const int label_y = 380; // Text label baseline

const int icon_size = 70; // icon font size
const int val_size = 120; // number font size
const int unit_size = 44; // unit font size
const int label_size= 36; // label font size

// --- Left column : Temperature -----------------------------
const int left_mid = col_w / 2 - 30; // 200 px

// Icon
it.printf(left_mid, icon_y, id(font_mdi_large), TextAlign::CENTER, "\U000F050F");
// Value
it.printf(left_mid, value_y, id(big_font), TextAlign::CENTER, "%.0f", temp_f);
// Unit
it.printf(left_mid + 150, unit_y, id(mid_font), TextAlign::CENTER, "°F");
// Label
it.printf(left_mid, label_y, id(mid_font), TextAlign::CENTER, "Temperature");

// --- Right column : Humidity -------------------------------
const int right_mid = col_w + col_w / 2; // 600 px

// Icon
it.printf(right_mid, icon_y, id(font_mdi_large), TextAlign::CENTER, "\U000F058E");
// Value
it.printf(right_mid, value_y, id(big_font), TextAlign::CENTER, "%.0f", id(hum_sensor).state);
// Unit
it.printf(right_mid + 150, unit_y, id(mid_font), TextAlign::CENTER, "%%");
// Label
it.printf(right_mid, label_y, id(mid_font), TextAlign::CENTER, "Humidity");
}
// ---------- PAGE 1 ----------
else{
// Battery top-right
it.printf(670, 13, id(font_bat_icon), "%s", id(battery_glyph).c_str());
it.printf(700, 10, id(small_font), "%.0f%%", id(battery_level).state);

auto now = id(ha_time).now();
struct tm timeinfo = now.to_c_tm();

// centering time HH:MM
char timeStr[6];
strftime(timeStr, sizeof(timeStr), "%H:%M", &timeinfo);
it.printf(400, 180, id(time_font), TextAlign::CENTER, timeStr);

// Date: Day of week
const char *weekday[] = {"Sun","Mon","Tue","Wed","Thu","Fri","Sat"};
const char *wday = weekday[timeinfo.tm_wday];

// Date: month - day
char dateStr[12];
strftime(dateStr, sizeof(dateStr), "%b %d", &timeinfo); // e.g. Jun 15

// Day of the week + date below the time
it.printf(400, 280, id(mid_font), TextAlign::CENTER, "%s, %s", wday, dateStr);
}

設定が正常にアップロードされて実行されると、reTerminal E Series ePaper ディスプレイには環境データ、時刻、バッテリー状態を含む包括的なダッシュボードが表示されます:

包括的な例の理解

この例では以下を実装しています:

  1. 複数ページ: ディスプレイは2つのページ(気候ダッシュボードと時刻/日付表示)を切り替えます
  2. ボタンナビゲーション: GPIO3とGPIO5のボタンを使用してページ間を移動します
  3. バッテリー監視: バッテリーレベルが充電レベルに応じて変化する適切なアイコンで表示されます
  4. ハードウェア初期化: 起動時にSDカードとバッテリー監視回路が有効になります
  5. 温度と湿度の表示: I²C経由でオンボードSHT4xセンサーを使用します
  6. 動的アイコン: Material Design Iconsがセンサー値に基づいて変化します

FAQ

Q1: データが表示されないのはなぜですか?

この場合、設定 -> デバイスとサービス -> 統合に移動して、デバイスを再設定する必要があります。ePaper パネルが見つからない場合は、Home Assistant を再起動してみてください。

Q2: Home Assistant でこれらのデータを取得できないのはなぜですか?

この場合、設定 -> デバイスとサービス -> 統合に移動して、デバイスを Home Assistant に追加する必要があります。

Q3: Wi-Fi プログラムアップロードが失敗しますか?

この場合、デバイスがオフラインまたはディープスリープモードになっています。アップロードを試行する前に、ネットワークに接続されていることを確認するか、スリープモードから復帰させてください。

技術サポート & 製品ディスカッション

弊社製品をお選びいただき、ありがとうございます!弊社製品での体験が可能な限りスムーズになるよう、さまざまなサポートを提供しています。さまざまな好みやニーズに対応するため、複数のコミュニケーションチャンネルを提供しています。

Loading Comments...