lscp01.yaml 6.6 KB

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