MJTD01YL 小米米家台灯

Flashing

卸下底座胶垫下的三颗螺丝即可拆开,按照 tasmota 文档给 ESP 模块焊上需要的引线:

pinout

Source

  1. 黑色:GND,PIN3、5、6、7、15、16、19、20 均可
  2. 白色:Vcc(+3.3V),PIN8
  3. 灰色:RxD,PIN17
  4. 紫色:TxD,PIN18

wiring

另外短接 PIN3(GND)和 PIN4(GPIO0);再用镊子短接 PIN9(RST)和 PIN7(GND)后释放,让 ESP 重置后进入 flashing 模式即可。

Software

ESPHome 配置示例:

Source: syssi/esphome-mi-desk-lamp

esphome:
  name: lamp
  comment: 'Living room Mijia Desk Lamp'

esp8266:
  board: esp8285  # 注意型号

logger:
  level: WARN
#   baud_rate: 9600

wifi:
  fast_connect: true
  networks:
    - ssid: !secret wifi_ssid
      bssid: !secret wifi_bssid
      password: !secret wifi_password

api:
ota:
  password: !secret ota_password

sensor:
  - platform: rotary_encoder
    id: rotation
    pin_a: 13
    pin_b: 12
    resolution: 2
    on_value:
      then:
        - if:
            condition:
              lambda: 'return id(button).state;'
            then:
              - lambda: |-
                  auto min_temp = id(light1).get_traits().get_min_mireds();
                  auto max_temp = id(light1).get_traits().get_max_mireds();
                  auto cur_temp = id(light1).current_values.get_color_temperature();
                  auto new_temp = max(min_temp, min(max_temp, cur_temp + (x * 10)));
                  auto call = id(light1).turn_on();
                  call.set_color_temperature(new_temp);
                  call.perform();
            else:
              - light.dim_relative:
                  id: light1
                  relative_brightness: !lambda |-
                    return x / 25.0;
        - sensor.rotary_encoder.set_value:
            id: rotation
            value: 0

binary_sensor:
  - platform: gpio
    id: button
    pin:
      number: 2
      inverted: true
    on_click:
      then:
        - light.toggle: light1

output:
  - platform: esp8266_pwm
    pin: 4
    id: output_cold
  - platform: esp8266_pwm
    pin: 5
    id: output_warm

light:
  - platform: cwww
    id: light1
    default_transition_length: 0s
    constant_brightness: true
    name: 'Lamp'
    cold_white: output_cold
    warm_white: output_warm
    cold_white_color_temperature: 6500K
    warm_white_color_temperature: 2700K
    gamma_correct: 0

HASS 接入

重置 ESP 模块后稍等,HASS 会通知已自动发现新 ESPHome 设备,直接选择接入即可。之后即可添加原生带亮度与色温调整的灯具卡片至 lovelace。

lovelace-card

关于扩展功能

之前根据 tasmota 文档最后说的

As the lamp has external power supply, and the LEDs are in the upper part of the lamp, the temperature of the base is the same as of the ambient, and by its nature the lamp is situated on your desk, so it's a perfect place for temp+humidity measurements.

在 GPIO0 接了一个 DHT22 温湿度传感器,但实际使用一段时间后发现效果并不好,台灯一点亮就会让温度马上升高 5 ℃ 左右。


0 Comments

发表评论

Avatar placeholder

您的电子邮箱地址不会被公开。