LSC_Action_1681PG_plug.yaml 5.6 KB

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