hencou / esphome_components

Collection of own ESPhome components
25 stars 15 forks source link

New install transitioning from Sidoh/miligjthub #18

Closed turbidWaters closed 9 months ago

turbidWaters commented 1 year ago

I am currently using many milight bulbs for over 5 years. Initially I was using them with milight WiFi bridges integrating them into homebridge (and ultimately HomeKit) using the plugin - https://github.com/dotsam/homebridge-milight.

I later made custom milight hubs using https://github.com/sidoh/esp8266_milight_hub integrating them into homebridge using https://github.com/cflurin/homebridge-mqtt

I saw the implementation in esphome in this repo (I haven't ever used esphome till date but I have flashed tasmota ans used lots of devices) and found it interesting. I find the instructions to be elaborate but since I am not using home assistant (and I haven't used esphome too) I am at a loss to be able to implement this.

I am not sure if this is the right place to reach out for help with such fundamentals. But since I don't know of any other platform to reach out for this, I am trying here. If someone can help me implement this kindly let me know. As I am not a "techie" as such, I would be grateful to assign the project out on a freelance basis or anything else that works.

damiencorpataux commented 11 months ago

This ESPHome component works like a charm !

Here is what you can do:

pip install esphome
mkdir esphome
cd esphome
nano milight.yaml

Copy/paste this https://github.com/hencou/esphome_components/blob/main/example_milight.yaml and replace the device_id with the id of your hub (or remote controller)

Here is my milight.yaml file:

# See tutorials:
#
# - using Sidoh esp8266_milight_hub
#   https://jacksonraila.wordpress.com/2021/01/17/diy-milight-hub-for-home-assistant-using-sidoh-nodemcu-esp8266/
#
# - using ESPHome fork
#   https://github.com/hencou/esphome_components
#   https://github.com/sidoh/esp8266_milight_hub/issues/642#issuecomment-1336466795

substitutions:
  device_name: milight
  friendly_name: Lights

esphome:
  name: $device_name
  # platformio_options:                     #optional, to set additional build flags
  #   build_flags:                          #optional, to set additional build flags
  #     - "-D USE_ESP32_ALTERNATE_SPI"      #optional, to use the alternate HSPI SPI bus instead of the default VSPI on an ESP32 board
  #     - "-D ALT_SPI_MISO_PIN=15"          #optional, if HSPI bus is used, alternate pins can also be defined
  #     - "-D ALT_SPI_MOSI_PIN=14"
  #     - "-D ALT_SPI_SCLK_PIN=12"
  #     - "-D ALT_SPI_SS_PIN=4"

  libraries:
    - milight=https://github.com/hencou/esphome-milight

external_components:
  - source: github://hencou/esphome_components
    components: mi

esp8266:
  board: nodemcuv2

# Enable logging
logger:
  level: DEBUG

# Enable Home Assistant API
api:
  password: "xxx"

ota:
  password: "xxx"

wifi:
  ssid: "xxx"
  password: "xxx"

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Fallback Hotspot"
    password: "xxx"

mi:
  ce_pin: D2 #required, default: 4
  csn_pin: D8 #required, default: 15
  reset_pin: 0 #optional, default: 0, only needed with LT8900 radio
  radio_interface_type: nrf24 #optional, default: nrf24, possible values: nrf24,lt8900
  packet_repeats: 50 #optional, default: 50, total of sended packets per command
  listen_repeats: 20 #optional, default: 20, amount of received packets needed for a incoming command from other remote
  state_flush_interval: 5000 #optional, default: 10000, time in miliseconds to send the latest state report to HomeAssistant
  packet_repeat_throttle_threshold: 200 #optional, default: 200, threshold to limit the amount of packets in a second
  packet_repeat_throttle_sensitivity: 0 #optional, default: 0
  packet_repeat_minimum: 3 #optional, default: 3
  enable_automatic_mode_switching: false #optional, default: false
  rf24_power_level: MAX #optional, default: MAX, possible values: MIN, LOW, HIGH, MAX
  rf24_listen_channel: LOW #optional, default: LOW, possible values: LOW, MID, HIGH
  packet_repeats_per_loop: 10 #optional, default: 10, repeat packets sended per loop
  resend_last_command: true #optional, default: true, repeats the latest command after a random time between 2 and 3 seconds again
  rf24_channels: #optional, 1-3 values required when used, default: LOW-MID-HIGH, possible values: LOW, MID, HIGH
    - LOW
    - MID
    - HIGH
  on_command_received: #optional, useful to send remote commands to HA and process them further there in automations
    - homeassistant.event:
        event: esphome.mi_command_received
        data:
          device_id: !lambda "return format_hex(data.device_id);"
          group_id: !lambda "return data.group_id;"
          remote_type: !lambda "return data.remote_type.c_str();"
          command: !lambda "return data.command.c_str();"

light:
  - platform: mi
    id: group1
    name: "Group 1 test"
    device_id: 0x30c5
    group_id: 1
    remote_type: rgb_cct
    default_transition_length: 0s

  - platform: mi
    id: group2
    name: "Group 2 test"
    device_id: 0x30c5
    group_id: 2
    remote_type: rgb_cct
    default_transition_length: 0s

  - platform: mi
    id: group3
    name: "Group 3 test"
    device_id: 0x30c5
    group_id: 3
    remote_type: rgb_cct
    default_transition_length: 0s

  - platform: mi
    id: group4
    name: "Group 4 test"
    device_id: 0x30c5
    group_id: 4
    remote_type: rgb_cct
    default_transition_length: 0s

  - platform: mi
    id: group_all
    name: "Group all test"
    device_id: 0x30c5
    group_id: 0
    remote_type: rgb_cct
    default_transition_length: 0s