lscp03.yaml 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  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. bk72xx:
  11. board: generic-bk7231t-qfn32-tuya
  12. #framework:
  13. # version: dev
  14. packages:
  15. # Enable Home Assistant API
  16. esphome: !include common/keys.yaml
  17. logger:
  18. web_server:
  19. port: 80
  20. wifi:
  21. ssid: !secret iot_ssid
  22. password: !secret iot_password
  23. domain: .int.mmax.cloud
  24. sensor:
  25. - platform: wifi_signal
  26. name: "WiFi Signal Sensor"
  27. update_interval: 60s
  28. - platform: uptime
  29. name: Uptime Sensor
  30. id: uptime_sensor
  31. update_interval: 60s
  32. on_raw_value:
  33. then:
  34. - text_sensor.template.publish:
  35. id: uptime_human
  36. state: !lambda |-
  37. int seconds = round(id(uptime_sensor).raw_state);
  38. int days = seconds / (24 * 3600);
  39. seconds = seconds % (24 * 3600);
  40. int hours = seconds / 3600;
  41. seconds = seconds % 3600;
  42. int minutes = seconds / 60;
  43. seconds = seconds % 60;
  44. return (
  45. (days ? to_string(days) + "d " : "") +
  46. (hours ? to_string(hours) + "h " : "") +
  47. (minutes ? to_string(minutes) + "m " : "") +
  48. (to_string(seconds) + "s")
  49. ).c_str();
  50. #
  51. # power monitoring
  52. #
  53. # PC191HA includes a BL0937 chip for measuring power consumption
  54. # and BL0937 is a variation of hlw8012, but using inverted SEL pin functionality
  55. - platform: hlw8012
  56. model: BL0937 # note that the model must be specified to use special calculation parameters
  57. sel_pin: # I believe that cf_pin reports either Voltage or Current depending on this select pin
  58. inverted: true # determine whether true reports Voltage
  59. number: P11
  60. cf1_pin:
  61. inverted: true
  62. number: P24
  63. cf_pin:
  64. inverted: true
  65. number: P26
  66. update_interval: 5s
  67. change_mode_every: 4
  68. # update_interval: 5s
  69. # initial_mode: "VOLTAGE"
  70. # change_mode_every: 4294967295
  71. # Adjust according to the actual resistor values on board to calibrate the specific unit
  72. # voltage_divider: "895" # LOWER VALUE GIVES LOWER VOLTAE
  73. # current_resistor: "0.0006" # HIGHER VALUE GIVES LOWER WATTAGE
  74. voltage_divider: "795"
  75. current_resistor: "0.001"
  76. # how the power monitoring values are returned to ESPHome
  77. voltage:
  78. name: $friendly_devicename Voltage
  79. id: ${low_devicename}_voltage
  80. unit_of_measurement: V
  81. accuracy_decimals: 1
  82. filters:
  83. - skip_initial: 2
  84. - sliding_window_moving_average:
  85. window_size: 4
  86. send_every: 2
  87. on_value:
  88. component.update: ${low_devicename}_apparent_power
  89. power:
  90. name: $friendly_devicename Power
  91. id: ${low_devicename}_power
  92. unit_of_measurement: W
  93. accuracy_decimals: 0
  94. on_value:
  95. component.update: ${low_devicename}_power_factor
  96. filters:
  97. # - skip_initial: 15
  98. - skip_initial: 2
  99. - sliding_window_moving_average:
  100. window_size: 4
  101. send_every: 2
  102. current:
  103. name: $friendly_devicename Current
  104. id: ${low_devicename}_current
  105. unit_of_measurement: A
  106. accuracy_decimals: 3
  107. filters:
  108. # - multiply: 1
  109. - multiply: 0.450
  110. - skip_initial: 2
  111. - sliding_window_moving_average:
  112. window_size: 4
  113. send_every: 2
  114. # power is simply current x voltage -- except that the pc191ha doesn't follow that formula.
  115. # Setting current_resistor to give an accurate Amperage does NOT also give the correct Wattage
  116. # my work-around is to calculate current from power / voltage
  117. # - platform: template
  118. # name: $friendly_devicename Current
  119. # id: ${low_devicename}_current
  120. # unit_of_measurement: A
  121. # accuracy_decimals: 2
  122. # update_interval: $update_interval_seconds
  123. # lambda: |-
  124. # return (id(${low_devicename}_power).state / id(${low_devicename}_voltage).state);
  125. # filters:
  126. # - skip_initial: 5 # give time for data to settle to avoid NaN
  127. - platform: total_daily_energy
  128. name: $friendly_devicename daily consumption
  129. id: ${low_devicename}_total_daily_energy
  130. power_id: ${low_devicename}_apparent_power
  131. filters:
  132. - multiply: 0.001 # to kWh
  133. unit_of_measurement: kWh
  134. - platform: template
  135. name: "Apparent power"
  136. id: ${low_devicename}_apparent_power
  137. unit_of_measurement: VA
  138. device_class: apparent_power
  139. lambda: |-
  140. return id(${low_devicename}_voltage).state * id(${low_devicename}_current).state;
  141. update_interval: never
  142. on_value:
  143. component.update: ${low_devicename}_power_factor
  144. - platform: template
  145. name: "Power factor"
  146. id: ${low_devicename}_power_factor
  147. unit_of_measurement: ''
  148. device_class: power_factor
  149. lambda: |-
  150. return id(${low_devicename}_power).state / id(${low_devicename}_apparent_power).state;
  151. filters:
  152. - clamp:
  153. min_value: 0
  154. max_value: 1
  155. update_interval: never
  156. text_sensor:
  157. - platform: template
  158. name: Uptime Human Readable
  159. id: uptime_human
  160. icon: mdi:clock-start
  161. - platform: wifi_info
  162. ip_address:
  163. name: IP Address
  164. entity_category: diagnostic
  165. light:
  166. - platform: binary
  167. name: "led"
  168. internal: true
  169. id: led
  170. output: red_led
  171. output:
  172. - platform: gpio
  173. id: red_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