lscp03.yaml 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. # https://github.com/FlorianSoler/OpenBeken-Action-lsc-smartplug-with-monitoring-guide/tree/main?tab=readme-ov-file
  2. substitutions:
  3. devicename: lscp03
  4. low_devicename: lscp03
  5. friendly_devicename: LSC Plug 03
  6. update_interval_seconds: "15s"
  7. esphome:
  8. name: $devicename
  9. friendly_name: $friendly_devicename
  10. platformio_options:
  11. lib_ignore:
  12. - RPAsyncTCP
  13. bk72xx:
  14. board: generic-bk7231t-qfn32-tuya
  15. packages:
  16. # Enable Home Assistant API
  17. esphome: !include common/keys.yaml
  18. diag: !include common/diag.yaml
  19. logger:
  20. web_server:
  21. port: 80
  22. wifi:
  23. ssid: !secret iot_ssid
  24. password: !secret iot_password
  25. domain: .int.mmax.cloud
  26. sensor:
  27. #
  28. # power monitoring
  29. #
  30. # PC191HA includes a BL0937 chip for measuring power consumption
  31. # and BL0937 is a variation of hlw8012, but using inverted SEL pin functionality
  32. - platform: hlw8012
  33. model: BL0937 # note that the model must be specified to use special calculation parameters
  34. sel_pin: # I believe that cf_pin reports either Voltage or Current depending on this select pin
  35. inverted: true # determine whether true reports Voltage
  36. number: P11
  37. cf1_pin:
  38. inverted: true
  39. number: P24
  40. cf_pin:
  41. inverted: true
  42. number: P26
  43. update_interval: 5s
  44. change_mode_every: 4
  45. # update_interval: 5s
  46. # initial_mode: "VOLTAGE"
  47. # change_mode_every: 4294967295
  48. # Adjust according to the actual resistor values on board to calibrate the specific unit
  49. # voltage_divider: "895" # LOWER VALUE GIVES LOWER VOLTAE
  50. # current_resistor: "0.0006" # HIGHER VALUE GIVES LOWER WATTAGE
  51. voltage_divider: "814"
  52. current_resistor: "0.001"
  53. # how the power monitoring values are returned to ESPHome
  54. voltage:
  55. name: $friendly_devicename Voltage
  56. id: ${low_devicename}_voltage
  57. unit_of_measurement: V
  58. accuracy_decimals: 1
  59. filters:
  60. - skip_initial: 2
  61. - sliding_window_moving_average:
  62. window_size: 4
  63. send_every: 2
  64. on_value:
  65. component.update: ${low_devicename}_apparent_power
  66. power:
  67. name: $friendly_devicename Power
  68. id: ${low_devicename}_power
  69. unit_of_measurement: W
  70. accuracy_decimals: 0
  71. on_value:
  72. component.update: ${low_devicename}_power_factor
  73. filters:
  74. # - skip_initial: 15
  75. - skip_initial: 2
  76. - sliding_window_moving_average:
  77. window_size: 4
  78. send_every: 2
  79. current:
  80. name: $friendly_devicename Current
  81. id: ${low_devicename}_current
  82. unit_of_measurement: A
  83. accuracy_decimals: 3
  84. filters:
  85. # - multiply: 1
  86. - multiply: 0.450
  87. - skip_initial: 2
  88. - sliding_window_moving_average:
  89. window_size: 4
  90. send_every: 2
  91. # power is simply current x voltage -- except that the pc191ha doesn't follow that formula.
  92. # Setting current_resistor to give an accurate Amperage does NOT also give the correct Wattage
  93. # my work-around is to calculate current from power / voltage
  94. # - platform: template
  95. # name: $friendly_devicename Current
  96. # id: ${low_devicename}_current
  97. # unit_of_measurement: A
  98. # accuracy_decimals: 2
  99. # update_interval: $update_interval_seconds
  100. # lambda: |-
  101. # return (id(${low_devicename}_power).state / id(${low_devicename}_voltage).state);
  102. # filters:
  103. # - skip_initial: 5 # give time for data to settle to avoid NaN
  104. - platform: total_daily_energy
  105. name: $friendly_devicename daily consumption
  106. id: ${low_devicename}_total_daily_energy
  107. power_id: ${low_devicename}_apparent_power
  108. filters:
  109. - multiply: 0.001 # to kWh
  110. unit_of_measurement: kWh
  111. - platform: template
  112. name: "Apparent power"
  113. id: ${low_devicename}_apparent_power
  114. unit_of_measurement: VA
  115. device_class: apparent_power
  116. lambda: |-
  117. return id(${low_devicename}_voltage).state * id(${low_devicename}_current).state;
  118. update_interval: never
  119. on_value:
  120. component.update: ${low_devicename}_power_factor
  121. - platform: template
  122. name: "Power factor"
  123. id: ${low_devicename}_power_factor
  124. unit_of_measurement: ''
  125. device_class: power_factor
  126. lambda: |-
  127. return id(${low_devicename}_power).state / id(${low_devicename}_apparent_power).state;
  128. filters:
  129. - clamp:
  130. min_value: 0
  131. max_value: 1
  132. update_interval: never
  133. light:
  134. - platform: binary
  135. name: "led"
  136. internal: true
  137. id: led
  138. output: red_led
  139. output:
  140. - platform: gpio
  141. id: red_led
  142. pin:
  143. number: P8
  144. # inverted: true
  145. status_led:
  146. pin:
  147. number: P10
  148. # inverted: true
  149. binary_sensor:
  150. - platform: gpio
  151. pin:
  152. number: P7
  153. mode:
  154. input: true
  155. pullup: true
  156. inverted: true
  157. id: button1
  158. filters:
  159. - delayed_on: 50ms
  160. - delayed_off: 50ms
  161. on_click:
  162. - switch.toggle: outlet
  163. switch:
  164. - platform: gpio
  165. name: ${friendly_devicename} Outlet
  166. id: outlet
  167. pin: P6
  168. icon: mdi:power-socket-eu
  169. on_turn_on:
  170. - light.turn_on: led
  171. on_turn_off:
  172. - light.turn_off: led
  173. restore_mode: RESTORE_DEFAULT_OFF
  174. # Switch to restart the plug
  175. - platform: restart
  176. name: ${friendly_devicename} Restart Switch
  177. # Enable time component to reset energy at midnight
  178. time:
  179. - platform: homeassistant
  180. id: homeassistant_time