lscp01.yaml 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. # https://github.com/FlorianSoler/OpenBeken-Action-lsc-smartplug-with-monitoring-guide/tree/main?tab=readme-ov-file
  2. substitutions:
  3. devicename: lscp01
  4. low_devicename: lscp01
  5. friendly_devicename: LSC Plug 01
  6. update_interval_seconds: "15s"
  7. esphome:
  8. name: $devicename
  9. friendly_name: $friendly_devicename
  10. bk72xx:
  11. board: generic-bk7231t-qfn32-tuya
  12. #framework:
  13. # version: dev
  14. # Enable logging
  15. logger:
  16. web_server:
  17. port: 80
  18. # Enable Home Assistant API
  19. api:
  20. encryption:
  21. key: "ejeMnlF5M60w/yuYwAWn/kIBz701xLwVkUGf9iN8uLA="
  22. ota:
  23. password: "2c27af3ab81f992e23745c20ab5dfc02"
  24. wifi:
  25. ssid: !secret iot_ssid
  26. password: !secret iot_password
  27. domain: .int.mmax.cloud
  28. sensor:
  29. - platform: wifi_signal
  30. name: "WiFi Signal Sensor"
  31. update_interval: 60s
  32. - platform: uptime
  33. name: Uptime Sensor
  34. id: uptime_sensor
  35. update_interval: 60s
  36. on_raw_value:
  37. then:
  38. - text_sensor.template.publish:
  39. id: uptime_human
  40. state: !lambda |-
  41. int seconds = round(id(uptime_sensor).raw_state);
  42. int days = seconds / (24 * 3600);
  43. seconds = seconds % (24 * 3600);
  44. int hours = seconds / 3600;
  45. seconds = seconds % 3600;
  46. int minutes = seconds / 60;
  47. seconds = seconds % 60;
  48. return (
  49. (days ? to_string(days) + "d " : "") +
  50. (hours ? to_string(hours) + "h " : "") +
  51. (minutes ? to_string(minutes) + "m " : "") +
  52. (to_string(seconds) + "s")
  53. ).c_str();
  54. #
  55. # power monitoring
  56. #
  57. # PC191HA includes a BL0937 chip for measuring power consumption
  58. # and BL0937 is a variation of hlw8012, but using inverted SEL pin functionality
  59. - platform: hlw8012
  60. model: BL0937 # note that the model must be specified to use special calculation parameters
  61. sel_pin: # I believe that cf_pin reports either Voltage or Current depending on this select pin
  62. inverted: true # determine whether true reports Voltage
  63. number: P11
  64. cf_pin: # current or voltage (ele_pin: 7)
  65. # inverted: true # the logic of BL0937 is opposite from HLW8012
  66. number: P24
  67. cf1_pin: # Power (vi_pin: 8)
  68. # inverted: true # the logic of BL0937 is opposite from HLW8012
  69. number: P26
  70. update_interval: $update_interval_seconds
  71. # PC191HA measures and returns Voltage OR Current according to the value of sel_pin,
  72. # but it can change the value of sel_pin periodically
  73. initial_mode: "VOLTAGE"
  74. change_mode_every: "5"
  75. # Adjust according to the actual resistor values on board to calibrate the specific unit
  76. voltage_divider: "895" # LOWER VALUE GIVES LOWER VOLTAGE
  77. current_resistor: "0.0006" # HIGHER VALUE GIVES LOWER WATTAGE
  78. # how the power monitoring values are returned to ESPHome
  79. voltage:
  80. name: $friendly_devicename Voltage
  81. id: ${low_devicename}_voltage
  82. unit_of_measurement: V
  83. accuracy_decimals: 1
  84. filters:
  85. - skip_initial: 2
  86. power:
  87. name: $friendly_devicename Power
  88. id: ${low_devicename}_power
  89. unit_of_measurement: W
  90. accuracy_decimals: 2
  91. filters:
  92. - skip_initial: 2
  93. current:
  94. name: $friendly_devicename Current
  95. id: ${low_devicename}_current
  96. unit_of_measurement: A
  97. accuracy_decimals: 2
  98. filters:
  99. - multiply: 0.18
  100. - skip_initial: 2
  101. # power is simply current x voltage -- except that the pc191ha doesn't follow that formula.
  102. # Setting current_resistor to give an accurate Amperage does NOT also give the correct Wattage
  103. # my work-around is to calculate current from power / voltage
  104. # - platform: template
  105. # name: $friendly_devicename Current
  106. # id: ${low_devicename}_current
  107. # unit_of_measurement: A
  108. # accuracy_decimals: 2
  109. # update_interval: $update_interval_seconds
  110. # lambda: |-
  111. # return (id(${low_devicename}_power).state / id(${low_devicename}_voltage).state);
  112. # filters:
  113. # - skip_initial: 5 # give time for data to settle to avoid NaN
  114. text_sensor:
  115. - platform: template
  116. name: Uptime Human Readable
  117. id: uptime_human
  118. icon: mdi:clock-start
  119. - platform: wifi_info
  120. ip_address:
  121. name: IP Address
  122. entity_category: diagnostic
  123. light:
  124. - platform: status_led
  125. name: "led"
  126. internal: true
  127. id: led
  128. pin:
  129. number: P8
  130. inverted: true
  131. - platform: status_led
  132. name: "netled"
  133. internal: true
  134. id: netled
  135. pin:
  136. number: P10
  137. inverted: true
  138. binary_sensor:
  139. - platform: status
  140. name: Status
  141. entity_category: diagnostic
  142. - platform: gpio
  143. pin:
  144. number: P7
  145. mode:
  146. input: true
  147. pullup: true
  148. inverted: true
  149. id: button1
  150. filters:
  151. - delayed_on: 50ms
  152. - delayed_off: 50ms
  153. on_click:
  154. - switch.toggle: outlet
  155. - platform: status
  156. name: ${friendly_devicename} status
  157. switch:
  158. - platform: gpio
  159. name: ${friendly_devicename} Outlet
  160. id: outlet
  161. pin: P6
  162. icon: mdi:power-socket-eu
  163. on_turn_on:
  164. - light.turn_on: led
  165. on_turn_off:
  166. - light.turn_off: led
  167. # Switch to restart the plug
  168. - platform: restart
  169. name: ${friendly_devicename} Restart Switch