lscp02.yaml 5.6 KB

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