Advertisement
dckiller

Xiaomi Desk Lamp 1S ESPHome

Feb 8th, 2021
700
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.67 KB | None | 0 0
  1. esphome:
  2. name: mi_desk_lamp_1s
  3. platform: ESP32
  4. board: esp32doit-devkit-v1
  5. platformio_options:
  6. platform: espressif32@1.11.0
  7. platform_packages: |-4
  8. framework-arduinoespressif32 @ https://github.com/pauln/arduino-esp32.git#solo-no-mac-crc/1.0.4
  9.  
  10. wifi:
  11. ssid: !secret ssid
  12. password: !secret wpa2
  13.  
  14. captive_portal:
  15.  
  16. logger:
  17.  
  18. api:
  19.  
  20. ota:
  21.  
  22. sensor:
  23. - platform: rotary_encoder
  24. id: rotation
  25. pin_a: GPIO27
  26. pin_b: GPIO26
  27. resolution: 2
  28. on_value:
  29. then:
  30. - if:
  31. condition:
  32. # Check if Button is pressed while rotating
  33. lambda: 'return id(button).state;'
  34. then:
  35. # If Button is pressed, change CW/WW
  36. - lambda: |-
  37. auto min_temp = id(light1).get_traits().get_min_mireds();
  38. auto max_temp = id(light1).get_traits().get_max_mireds();
  39. auto cur_temp = id(light1).current_values.get_color_temperature();
  40. auto new_temp = max(min_temp, min(max_temp, cur_temp + (x*20)));
  41. auto call = id(light1).turn_on();
  42. call.set_color_temperature(new_temp);
  43. call.perform();
  44. else:
  45. # If Button is not pressed, change brightness
  46. - light.dim_relative:
  47. id: light1
  48. relative_brightness: !lambda |-
  49. return x / 10.0;
  50. # Reset Rotation to 0
  51. - sensor.rotary_encoder.set_value:
  52. id: rotation
  53. value: 0
  54.  
  55. binary_sensor:
  56. - platform: gpio
  57. id: button
  58. pin:
  59. number: GPIO33
  60. inverted: True
  61. mode: INPUT_PULLDOWN
  62. on_click:
  63. then:
  64. # use if-condition instead of toggle to set full brightness on turn_on
  65. - if:
  66. condition:
  67. light.is_on: light1
  68. then:
  69. - light.turn_off:
  70. id: light1
  71. else:
  72. - light.turn_on:
  73. id: light1
  74. brightness: 100%
  75. color_temperature: 2700 K
  76.  
  77. output:
  78. - platform: ledc
  79. pin: GPIO2
  80. id: output_cw
  81. min_power: 0.03
  82. power_supply: power
  83. - platform: ledc
  84. pin: GPIO4
  85. id: output_ww
  86. min_power: 0.03
  87. power_supply: power
  88.  
  89. power_supply:
  90. - id: power
  91. pin: GPIO12
  92. enable_time: 0s
  93. keep_on_time: 0s
  94.  
  95. light:
  96. - platform: cwww
  97. id: light1
  98. default_transition_length: 0s
  99. constant_brightness: true
  100. name: "Lights"
  101. cold_white: output_cw
  102. warm_white: output_ww
  103. cold_white_color_temperature: 5000 K
  104. warm_white_color_temperature: 2600 K
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement