lscp01.yaml~ 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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. esphome:
  7. name: $devicename
  8. friendly_name: $friendly_devicename
  9. bk72xx:
  10. board: generic-bk7231t-qfn32-tuya
  11. #framework:
  12. # version: dev
  13. # Enable logging
  14. logger:
  15. web_server:
  16. port: 80
  17. # Enable Home Assistant API
  18. api:
  19. encryption:
  20. key: "ejeMnlF5M60w/yuYwAWn/kIBz701xLwVkUGf9iN8uLA="
  21. ota:
  22. password: "2c27af3ab81f992e23745c20ab5dfc02"
  23. wifi:
  24. ssid: !secret iot_ssid
  25. password: !secret iot_password
  26. domain: .int.mmax.cloud
  27. sensor:
  28. - platform: wifi_signal
  29. name: "WiFi Signal Sensor"
  30. update_interval: 60s
  31. - platform: uptime
  32. name: Uptime Sensor
  33. id: uptime_sensor
  34. update_interval: 60s
  35. on_raw_value:
  36. then:
  37. - text_sensor.template.publish:
  38. id: uptime_human
  39. state: !lambda |-
  40. int seconds = round(id(uptime_sensor).raw_state);
  41. int days = seconds / (24 * 3600);
  42. seconds = seconds % (24 * 3600);
  43. int hours = seconds / 3600;
  44. seconds = seconds % 3600;
  45. int minutes = seconds / 60;
  46. seconds = seconds % 60;
  47. return (
  48. (days ? to_string(days) + "d " : "") +
  49. (hours ? to_string(hours) + "h " : "") +
  50. (minutes ? to_string(minutes) + "m " : "") +
  51. (to_string(seconds) + "s")
  52. ).c_str();
  53. #
  54. # power monitoring
  55. #
  56. # PC191HA includes a BL0937 chip for measuring power consumption
  57. # and BL0937 is a variation of hlw8012, but using inverted SEL pin functionality
  58. - platform: hlw8012
  59. model: BL0937 # note that the model must be specified to use special calculation parameters
  60. sel_pin: # I believe that cf_pin reports either Voltage or Current depending on this select pin
  61. inverted: false # determine whether true reports Voltage
  62. number: P11
  63. cf_pin: # current or voltage (ele_pin: 7)
  64. inverted: true # the logic of BL0937 is opposite from HLW8012
  65. number: P24
  66. cf1_pin: # Power (vi_pin: 8)
  67. inverted: true # the logic of BL0937 is opposite from HLW8012
  68. number: P26
  69. update_interval: 2s
  70. # PC191HA measures and returns Voltage OR Current according to the value of sel_pin,
  71. # but it can change the value of sel_pin periodically
  72. initial_mode: "VOLTAGE"
  73. change_mode_every: 4294967295
  74. # Adjust according to the actual resistor values on board to calibrate the specific unit
  75. voltage_divider: "895" # LOWER VALUE GIVES LOWER VOLTAGE
  76. current_resistor: "0.0006" # HIGHER VALUE GIVES LOWER WATTAGE
  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. power:
  86. name: $friendly_devicename Power
  87. id: ${low_devicename}_power
  88. unit_of_measurement: W
  89. accuracy_decimals: 2
  90. filters:
  91. - skip_initial: 2
  92. # current:
  93. # name: $friendly_devicename Current
  94. # id: ${low_devicename}_current
  95. # unit_of_measurement: A
  96. # accuracy_decimals: 3
  97. # filters:
  98. # - multiply: 0.18
  99. # - skip_initial: 2
  100. # power is simply current x voltage -- except that the pc191ha doesn't follow that formula.
  101. # Setting current_resistor to give an accurate Amperage does NOT also give the correct Wattage
  102. # my work-around is to calculate current from power / voltage
  103. # - platform: template
  104. # name: $friendly_devicename Current
  105. # id: ${low_devicename}_current
  106. # unit_of_measurement: A
  107. # accuracy_decimals: 2
  108. # update_interval: $update_interval_seconds
  109. # lambda: |-
  110. # return (id(${low_devicename}_power).state / id(${low_devicename}_voltage).state);
  111. # filters:
  112. # - skip_initial: 5 # give time for data to settle to avoid NaN
  113. - platform: total_daily_energy
  114. name: $friendly_devicename daily consumption
  115. id: ${low_devicename}_total_daily_energy
  116. power_id: ${low_devicename}_power
  117. filters:
  118. - multiply: 0.001 # to kWh
  119. unit_of_measurement: kWh
  120. text_sensor:
  121. - platform: template
  122. name: Uptime Human Readable
  123. id: uptime_human
  124. icon: mdi:clock-start
  125. - platform: wifi_info
  126. ip_address:
  127. name: IP Address
  128. entity_category: diagnostic
  129. light:
  130. - platform: status_led
  131. name: "led"
  132. internal: true
  133. id: led
  134. pin:
  135. number: P8
  136. inverted: true
  137. status_led:
  138. pin:
  139. number: P10
  140. inverted: true
  141. binary_sensor:
  142. - platform: status
  143. name: Status
  144. entity_category: diagnostic
  145. - platform: gpio
  146. pin:
  147. number: P7
  148. mode:
  149. input: true
  150. pullup: true
  151. inverted: true
  152. id: button1
  153. filters:
  154. - delayed_on: 50ms
  155. - delayed_off: 50ms
  156. on_click:
  157. - switch.toggle: outlet
  158. - platform: status
  159. name: ${friendly_devicename} status
  160. switch:
  161. - platform: gpio
  162. name: ${friendly_devicename} Outlet
  163. id: outlet
  164. pin: P6
  165. icon: mdi:power-socket-eu
  166. on_turn_on:
  167. - light.turn_on: led
  168. on_turn_off:
  169. - light.turn_off: led
  170. restore_mode: RESTORE_DEFAULT_OFF
  171. # Switch to restart the plug
  172. - platform: restart
  173. name: ${friendly_devicename} Restart Switch
  174. # Enable time component to reset energy at midnight
  175. time:
  176. - platform: homeassistant
  177. id: homeassistant_time