lscp02.yaml 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  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. 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. cf1_pin:
  65. inverted: true
  66. number: P24
  67. cf_pin:
  68. inverted: true
  69. number: P26
  70. update_interval: 5s
  71. change_mode_every: 4
  72. # update_interval: 5s
  73. # initial_mode: "VOLTAGE"
  74. # change_mode_every: 4294967295
  75. # Adjust according to the actual resistor values on board to calibrate the specific unit
  76. # voltage_divider: "895" # LOWER VALUE GIVES LOWER VOLTAE
  77. # current_resistor: "0.0006" # HIGHER VALUE GIVES LOWER WATTAGE
  78. voltage_divider: "795"
  79. current_resistor: "0.001"
  80. # how the power monitoring values are returned to ESPHome
  81. voltage:
  82. name: $friendly_devicename Voltage
  83. id: ${low_devicename}_voltage
  84. unit_of_measurement: V
  85. accuracy_decimals: 1
  86. filters:
  87. - skip_initial: 2
  88. - sliding_window_moving_average:
  89. window_size: 4
  90. send_every: 2
  91. on_value:
  92. component.update: ${low_devicename}_apparent_power
  93. power:
  94. name: $friendly_devicename Power
  95. id: ${low_devicename}_power
  96. unit_of_measurement: W
  97. accuracy_decimals: 0
  98. on_value:
  99. component.update: ${low_devicename}_power_factor
  100. filters:
  101. # - skip_initial: 15
  102. - skip_initial: 2
  103. - sliding_window_moving_average:
  104. window_size: 4
  105. send_every: 2
  106. current:
  107. name: $friendly_devicename Current
  108. id: ${low_devicename}_current
  109. unit_of_measurement: A
  110. accuracy_decimals: 3
  111. filters:
  112. # - multiply: 1
  113. - multiply: 0.450
  114. - skip_initial: 2
  115. - sliding_window_moving_average:
  116. window_size: 4
  117. send_every: 2
  118. # power is simply current x voltage -- except that the pc191ha doesn't follow that formula.
  119. # Setting current_resistor to give an accurate Amperage does NOT also give the correct Wattage
  120. # my work-around is to calculate current from power / voltage
  121. # - platform: template
  122. # name: $friendly_devicename Current
  123. # id: ${low_devicename}_current
  124. # unit_of_measurement: A
  125. # accuracy_decimals: 2
  126. # update_interval: $update_interval_seconds
  127. # lambda: |-
  128. # return (id(${low_devicename}_power).state / id(${low_devicename}_voltage).state);
  129. # filters:
  130. # - skip_initial: 5 # give time for data to settle to avoid NaN
  131. - platform: total_daily_energy
  132. name: $friendly_devicename daily consumption
  133. id: ${low_devicename}_total_daily_energy
  134. power_id: ${low_devicename}_apparent_power
  135. filters:
  136. - multiply: 0.001 # to kWh
  137. unit_of_measurement: kWh
  138. - platform: template
  139. name: "Apparent power"
  140. id: ${low_devicename}_apparent_power
  141. unit_of_measurement: VA
  142. device_class: apparent_power
  143. lambda: |-
  144. return id(${low_devicename}_voltage).state * id(${low_devicename}_current).state;
  145. update_interval: never
  146. on_value:
  147. component.update: ${low_devicename}_power_factor
  148. - platform: template
  149. name: "Power factor"
  150. id: ${low_devicename}_power_factor
  151. unit_of_measurement: ''
  152. device_class: power_factor
  153. lambda: |-
  154. return id(${low_devicename}_power).state / id(${low_devicename}_apparent_power).state;
  155. filters:
  156. - clamp:
  157. min_value: 0
  158. max_value: 1
  159. update_interval: never
  160. text_sensor:
  161. - platform: template
  162. name: Uptime Human Readable
  163. id: uptime_human
  164. icon: mdi:clock-start
  165. - platform: wifi_info
  166. ip_address:
  167. name: IP Address
  168. entity_category: diagnostic
  169. light:
  170. - platform: status_led
  171. name: "led"
  172. internal: true
  173. id: led
  174. pin:
  175. number: P8
  176. inverted: true
  177. status_led:
  178. pin:
  179. number: P10
  180. inverted: true
  181. binary_sensor:
  182. - platform: status
  183. name: Status
  184. entity_category: diagnostic
  185. - platform: gpio
  186. pin:
  187. number: P7
  188. mode:
  189. input: true
  190. pullup: true
  191. inverted: true
  192. id: button1
  193. filters:
  194. - delayed_on: 50ms
  195. - delayed_off: 50ms
  196. on_click:
  197. - switch.toggle: outlet
  198. - platform: status
  199. name: ${friendly_devicename} status
  200. switch:
  201. - platform: gpio
  202. name: ${friendly_devicename} Outlet
  203. id: outlet
  204. pin: P6
  205. icon: mdi:power-socket-eu
  206. on_turn_on:
  207. - light.turn_on: led
  208. on_turn_off:
  209. - light.turn_off: led
  210. restore_mode: RESTORE_DEFAULT_OFF
  211. # Switch to restart the plug
  212. - platform: restart
  213. name: ${friendly_devicename} Restart Switch
  214. # Enable time component to reset energy at midnight
  215. time:
  216. - platform: homeassistant
  217. id: homeassistant_time