lscp01.yaml 6.7 KB

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