lscp01.yaml 5.4 KB

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