2
0

2 Commity 26e4d98031 ... 7fd00cf7f7

Autor SHA1 Správa Dátum
  Patryk M. Gutowski 7fd00cf7f7 LSC Action Plug with power meter template 2 mesiacov pred
  Patryk M. Gutowski 0262a9c54e lscp move diag to common 2 mesiacov pred
5 zmenil súbory, kde vykonal 243 pridanie a 700 odobranie
  1. 200 0
      common/LSC_Action_1681PG_plug.yaml
  2. 30 0
      common/diag.yaml
  3. 4 236
      lscp01.yaml
  4. 4 233
      lscp02.yaml
  5. 5 231
      lscp03.yaml

+ 200 - 0
common/LSC_Action_1681PG_plug.yaml

@@ -0,0 +1,200 @@
+# https://github.com/FlorianSoler/OpenBeken-Action-lsc-smartplug-with-monitoring-guide/tree/main?tab=readme-ov-file
+# substitutions:
+#   devicename: lscp01
+#   low_devicename: lscp01
+#   friendly_devicename: LSC Plug 01
+#   update_interval_seconds: "15s"
+#   voltage_divider: "814"
+#   current_resistor: "0.001"
+#   multiply: 0.450
+# packages: 
+#  esphome: !include common/keys.yaml
+#  diag: !include common/diag.yaml
+#  lsc: !include common/LSC_Action_1681PG_plug.yaml
+  
+esphome:
+  name: $devicename
+  friendly_name: $friendly_devicename
+  platformio_options:
+    lib_ignore:
+      - RPAsyncTCP
+
+bk72xx:
+  board: generic-bk7231t-qfn32-tuya
+
+# Enable logging
+logger:
+
+web_server:
+  port: 80
+
+wifi:
+  ssid: !secret iot_ssid
+  password: !secret iot_password
+  domain: .int.mmax.cloud
+
+sensor:
+#
+# power monitoring
+#
+    # PC191HA includes a BL0937 chip for measuring power consumption
+    #     and BL0937 is a variation of hlw8012, but using inverted SEL pin functionality
+  - platform: hlw8012
+    model: BL0937     # note that the model must be specified to use special calculation parameters
+    sel_pin:          # I believe that cf_pin reports either Voltage or Current depending on this select pin
+      inverted: true  # determine whether true reports Voltage
+      number: P11
+    cf1_pin:
+      inverted: true 
+      number: P24
+    cf_pin: 
+      inverted: true 
+      number: P26
+    update_interval: 5s
+    change_mode_every: 4
+    # update_interval: 5s
+    # initial_mode: "VOLTAGE"
+    # change_mode_every: 4294967295
+    # Adjust according to the actual resistor values on board to calibrate the specific unit
+    # voltage_divider:  "895"               # LOWER VALUE GIVES LOWER VOLTAE
+    # current_resistor: "0.0006"          # HIGHER VALUE GIVES LOWER WATTAGE
+    voltage_divider: $voltage_divider
+    current_resistor: $current_resistor
+    # how the power monitoring values are returned to ESPHome
+    voltage:
+      name: $friendly_devicename Voltage
+      id:   ${low_devicename}_voltage
+      unit_of_measurement: V
+      accuracy_decimals: 1
+      filters:
+        - skip_initial: 2
+        - sliding_window_moving_average:
+            window_size: 4
+            send_every: 2
+      on_value:
+        component.update: ${low_devicename}_apparent_power
+    power:
+      name: $friendly_devicename Power
+      id:   ${low_devicename}_power
+      unit_of_measurement: W
+      accuracy_decimals: 0
+      on_value:
+        component.update: ${low_devicename}_power_factor
+      filters:
+        # - skip_initial: 15
+        - skip_initial: 2
+        - sliding_window_moving_average:
+            window_size: 4
+            send_every: 2
+    current:
+      name: $friendly_devicename Current
+      id:   ${low_devicename}_current
+      unit_of_measurement: A
+      accuracy_decimals: 3
+      filters:
+        # - multiply: 1
+        - multiply: $multiply
+        - skip_initial: 2
+        - sliding_window_moving_average:
+            window_size: 4
+            send_every: 2
+
+    # power is simply current x voltage -- except that the pc191ha doesn't follow that formula.
+        # Setting current_resistor to give an accurate Amperage does NOT also give the correct Wattage
+        # my work-around is to calculate current from power / voltage
+        #  - platform: template  
+        #    name: $friendly_devicename Current
+        #    id:   ${low_devicename}_current
+        #    unit_of_measurement: A
+        #    accuracy_decimals: 2
+        #    update_interval: $update_interval_seconds
+        #    lambda: |-
+        #      return (id(${low_devicename}_power).state / id(${low_devicename}_voltage).state);
+        #    filters:  
+        #      - skip_initial: 5     # give time for data to settle to avoid NaN
+  - platform: total_daily_energy
+    name: $friendly_devicename daily consumption
+    id: ${low_devicename}_total_daily_energy
+    power_id: ${low_devicename}_apparent_power
+    filters: 
+      - multiply: 0.001 # to kWh
+    unit_of_measurement: kWh
+  - platform: template
+    name: "Apparent power"
+    id: ${low_devicename}_apparent_power
+    unit_of_measurement: VA
+    device_class: apparent_power
+    lambda: |-
+      return id(${low_devicename}_voltage).state * id(${low_devicename}_current).state;
+    update_interval: never
+    on_value:
+        component.update: ${low_devicename}_power_factor
+  - platform: template
+    name: "Power factor"
+    id: ${low_devicename}_power_factor
+    unit_of_measurement: ''
+    device_class: power_factor
+    lambda: |-
+      return id(${low_devicename}_power).state / id(${low_devicename}_apparent_power).state;
+    filters:
+      - clamp:
+          min_value: 0
+          max_value: 1
+    update_interval: never
+
+light:
+  - platform: binary
+    name: "led"
+    internal: true
+    id: led
+    output: red_led
+
+output:
+  - platform: gpio
+    id: red_led
+    pin:
+      number: P8
+      # inverted: true
+
+status_led:
+    pin:
+      number: P10
+      # inverted: true
+
+binary_sensor:
+  - platform: gpio
+    pin:
+      number: P7
+      mode:
+        input: true
+        pullup: true
+      inverted: true
+    id: button1
+    filters:
+      - delayed_on: 50ms
+      - delayed_off: 50ms
+    on_click:
+      - switch.toggle: outlet
+
+switch:
+  - platform: gpio
+    name: ${friendly_devicename} Outlet
+    id: outlet
+    pin: P6
+    icon: mdi:power-socket-eu
+    on_turn_on:
+      - light.turn_on: led
+    on_turn_off:
+      - light.turn_off: led
+    restore_mode: RESTORE_DEFAULT_OFF
+  # Switch to restart the plug
+  - platform: restart
+    id: restart_button
+    name: ${friendly_devicename} Restart Switch
+    entity_category: diagnostic
+  
+
+# Enable time component to reset energy at midnight
+time:
+  - platform: homeassistant
+    id: homeassistant_time

+ 30 - 0
common/diag.yaml

@@ -7,6 +7,28 @@ button:
     entity_category: diagnostic
     entity_category: diagnostic
 
 
 sensor:
 sensor:
+  - platform: uptime
+    name: Uptime Sensor
+    id: uptime_sensor
+    update_interval: 60s
+    on_raw_value:
+      then:
+        - text_sensor.template.publish:
+            id: uptime_human
+            state: !lambda |-
+              int seconds = round(id(uptime_sensor).raw_state);
+              int days = seconds / (24 * 3600);
+              seconds = seconds % (24 * 3600);
+              int hours = seconds / 3600;
+              seconds = seconds % 3600;
+              int minutes = seconds /  60;
+              seconds = seconds % 60;
+              return (
+                (days ? to_string(days) + "d " : "") +
+                (hours ? to_string(hours) + "h " : "") +
+                (minutes ? to_string(minutes) + "m " : "") +
+                (to_string(seconds) + "s")
+              ).c_str();
   - platform: wifi_signal
   - platform: wifi_signal
     name: "${friendly_devicename} WiFi Signal"
     name: "${friendly_devicename} WiFi Signal"
     id: ${low_devicename}_wifi_signal
     id: ${low_devicename}_wifi_signal
@@ -30,3 +52,11 @@ binary_sensor:
 text_sensor:
 text_sensor:
   - platform: version
   - platform: version
     name: "${friendly_devicename} Version"
     name: "${friendly_devicename} Version"
+  - platform: template
+    name: Uptime Human Readable
+    id: uptime_human
+    icon: mdi:clock-start
+  - platform: wifi_info
+    ip_address:
+      name: IP Address
+      entity_category: diagnostic

+ 4 - 236
lscp01.yaml

@@ -1,246 +1,14 @@
-# https://github.com/FlorianSoler/OpenBeken-Action-lsc-smartplug-with-monitoring-guide/tree/main?tab=readme-ov-file
 substitutions:
 substitutions:
   devicename: lscp01
   devicename: lscp01
   low_devicename: lscp01
   low_devicename: lscp01
   friendly_devicename: LSC Plug 01
   friendly_devicename: LSC Plug 01
   update_interval_seconds: "15s"
   update_interval_seconds: "15s"
-  
-esphome:
-  name: $devicename
-  friendly_name: $friendly_devicename
-  platformio_options:
-    lib_ignore:
-      - RPAsyncTCP
-
-bk72xx:
-  board: generic-bk7231t-qfn32-tuya
-  #framework:
-  #   version: dev
+  voltage_divider: "830.98"
+  current_resistor: "0.00102"
+  multiply: "0.454"
 
 
 packages:
 packages:
   # Enable Home Assistant API
   # Enable Home Assistant API
   esphome: !include common/keys.yaml
   esphome: !include common/keys.yaml
   diag: !include common/diag.yaml
   diag: !include common/diag.yaml
-
-
-# Enable logging
-logger:
-
-web_server:
-  port: 80
-
-wifi:
-  ssid: !secret iot_ssid
-  password: !secret iot_password
-  domain: .int.mmax.cloud
-
-
-sensor:
-  - platform: wifi_signal
-    name: "WiFi Signal Sensor"
-    update_interval: 60s
-
-  - platform: uptime
-    name: Uptime Sensor
-    id: uptime_sensor
-    update_interval: 60s
-    on_raw_value:
-      then:
-        - text_sensor.template.publish:
-            id: uptime_human
-            state: !lambda |-
-              int seconds = round(id(uptime_sensor).raw_state);
-              int days = seconds / (24 * 3600);
-              seconds = seconds % (24 * 3600);
-              int hours = seconds / 3600;
-              seconds = seconds % 3600;
-              int minutes = seconds /  60;
-              seconds = seconds % 60;
-              return (
-                (days ? to_string(days) + "d " : "") +
-                (hours ? to_string(hours) + "h " : "") +
-                (minutes ? to_string(minutes) + "m " : "") +
-                (to_string(seconds) + "s")
-              ).c_str();
-#
-# power monitoring
-#
-    # PC191HA includes a BL0937 chip for measuring power consumption
-    #     and BL0937 is a variation of hlw8012, but using inverted SEL pin functionality
-  - platform: hlw8012
-    model: BL0937     # note that the model must be specified to use special calculation parameters
-    sel_pin:          # I believe that cf_pin reports either Voltage or Current depending on this select pin
-      inverted: true  # determine whether true reports Voltage
-      number: P11
-    cf1_pin:
-      inverted: true 
-      number: P24
-    cf_pin: 
-      inverted: true 
-      number: P26
-    update_interval: 5s
-    change_mode_every: 4
-    # update_interval: 5s
-    # initial_mode: "VOLTAGE"
-    # change_mode_every: 4294967295
-    # Adjust according to the actual resistor values on board to calibrate the specific unit
-    # voltage_divider:  "895"               # LOWER VALUE GIVES LOWER VOLTAE
-    # current_resistor: "0.0006"          # HIGHER VALUE GIVES LOWER WATTAGE
-    voltage_divider: "814"
-    current_resistor: "0.001"
-    # how the power monitoring values are returned to ESPHome
-    voltage:
-      name: $friendly_devicename Voltage
-      id:   ${low_devicename}_voltage
-      unit_of_measurement: V
-      accuracy_decimals: 1
-      filters:
-        - skip_initial: 2
-        - sliding_window_moving_average:
-            window_size: 4
-            send_every: 2
-      on_value:
-        component.update: ${low_devicename}_apparent_power
-    power:
-      name: $friendly_devicename Power
-      id:   ${low_devicename}_power
-      unit_of_measurement: W
-      accuracy_decimals: 0
-      on_value:
-        component.update: ${low_devicename}_power_factor
-      filters:
-        # - skip_initial: 15
-        - skip_initial: 2
-        - sliding_window_moving_average:
-            window_size: 4
-            send_every: 2
-    current:
-      name: $friendly_devicename Current
-      id:   ${low_devicename}_current
-      unit_of_measurement: A
-      accuracy_decimals: 3
-      filters:
-        # - multiply: 1
-        - multiply: 0.450
-        - skip_initial: 2
-        - sliding_window_moving_average:
-            window_size: 4
-            send_every: 2
-
-    # power is simply current x voltage -- except that the pc191ha doesn't follow that formula.
-        # Setting current_resistor to give an accurate Amperage does NOT also give the correct Wattage
-        # my work-around is to calculate current from power / voltage
-        #  - platform: template  
-        #    name: $friendly_devicename Current
-        #    id:   ${low_devicename}_current
-        #    unit_of_measurement: A
-        #    accuracy_decimals: 2
-        #    update_interval: $update_interval_seconds
-        #    lambda: |-
-        #      return (id(${low_devicename}_power).state / id(${low_devicename}_voltage).state);
-        #    filters:  
-        #      - skip_initial: 5     # give time for data to settle to avoid NaN
-  - platform: total_daily_energy
-    name: $friendly_devicename daily consumption
-    id: ${low_devicename}_total_daily_energy
-    power_id: ${low_devicename}_apparent_power
-    filters: 
-      - multiply: 0.001 # to kWh
-    unit_of_measurement: kWh
-  - platform: template
-    name: "Apparent power"
-    id: ${low_devicename}_apparent_power
-    unit_of_measurement: VA
-    device_class: apparent_power
-    lambda: |-
-      return id(${low_devicename}_voltage).state * id(${low_devicename}_current).state;
-    update_interval: never
-    on_value:
-        component.update: ${low_devicename}_power_factor
-  - platform: template
-    name: "Power factor"
-    id: ${low_devicename}_power_factor
-    unit_of_measurement: ''
-    device_class: power_factor
-    lambda: |-
-      return id(${low_devicename}_power).state / id(${low_devicename}_apparent_power).state;
-    filters:
-      - clamp:
-          min_value: 0
-          max_value: 1
-    update_interval: never
-
-
-
-text_sensor:
-  - platform: template
-    name: Uptime Human Readable
-    id: uptime_human
-    icon: mdi:clock-start
-  - platform: wifi_info
-    ip_address:
-      name: IP Address
-      entity_category: diagnostic
-
-light:
-  - platform: binary
-    name: "led"
-    internal: true
-    id: led
-    output: red_led
-
-
-output:
-  - platform: gpio
-    id: red_led
-    pin:
-      number: P8
-      # inverted: true
-
-
-status_led:
-    pin:
-      number: P10
-      # inverted: true
-
-binary_sensor:
-  # - platform: status
-  #   name: Status
-  #  entity_category: diagnostic
-
-  - platform: gpio
-    pin:
-      number: P7
-      mode:
-        input: true
-        pullup: true
-      inverted: true
-    id: button1
-    filters:
-      - delayed_on: 50ms
-      - delayed_off: 50ms
-    on_click:
-      - switch.toggle: outlet
-
-  # - platform: status
-  #  name: ${friendly_devicename} status
-
-switch:
-  - platform: gpio
-    name: ${friendly_devicename} Outlet
-    id: outlet
-    pin: P6
-    icon: mdi:power-socket-eu
-    on_turn_on:
-      - light.turn_on: led
-    on_turn_off:
-      - light.turn_off: led
-    restore_mode: RESTORE_DEFAULT_OFF
-  # Switch to restart the plug
-  - platform: restart
-    name: ${friendly_devicename} Restart Switch
-
-# Enable time component to reset energy at midnight
-time:
-  - platform: homeassistant
-    id: homeassistant_time
+  lsc: !include common/LSC_Action_1681PG_plug.yaml 

+ 4 - 233
lscp02.yaml

@@ -4,241 +4,12 @@ substitutions:
   low_devicename: lscp02
   low_devicename: lscp02
   friendly_devicename: LSC Plug 02
   friendly_devicename: LSC Plug 02
   update_interval_seconds: "15s"
   update_interval_seconds: "15s"
-  
-esphome:
-  name: $devicename
-  friendly_name: $friendly_devicename
-  platformio_options:
-    lib_ignore:
-      - RPAsyncTCP
-
-bk72xx:
-  board: generic-bk7231t-qfn32-tuya
-  #framework:
-  #   version: dev
+  voltage_divider: "814"
+  current_resistor: "0.001"
+  multiply: 0.450
 
 
 packages:
 packages:
   # Enable Home Assistant API
   # Enable Home Assistant API
   esphome: !include common/keys.yaml
   esphome: !include common/keys.yaml
   diag: !include common/diag.yaml
   diag: !include common/diag.yaml
-
-logger:
-
-web_server:
-  port: 80
-
-wifi:
-  ssid: !secret iot_ssid
-  password: !secret iot_password
-  domain: .int.mmax.cloud
-
-
-sensor:
-  - platform: wifi_signal
-    name: "WiFi Signal Sensor"
-    update_interval: 60s
-
-  - platform: uptime
-    name: Uptime Sensor
-    id: uptime_sensor
-    update_interval: 60s
-    on_raw_value:
-      then:
-        - text_sensor.template.publish:
-            id: uptime_human
-            state: !lambda |-
-              int seconds = round(id(uptime_sensor).raw_state);
-              int days = seconds / (24 * 3600);
-              seconds = seconds % (24 * 3600);
-              int hours = seconds / 3600;
-              seconds = seconds % 3600;
-              int minutes = seconds /  60;
-              seconds = seconds % 60;
-              return (
-                (days ? to_string(days) + "d " : "") +
-                (hours ? to_string(hours) + "h " : "") +
-                (minutes ? to_string(minutes) + "m " : "") +
-                (to_string(seconds) + "s")
-              ).c_str();
-#
-# power monitoring
-#
-    # PC191HA includes a BL0937 chip for measuring power consumption
-    #     and BL0937 is a variation of hlw8012, but using inverted SEL pin functionality
-  - platform: hlw8012
-    model: BL0937     # note that the model must be specified to use special calculation parameters
-    sel_pin:          # I believe that cf_pin reports either Voltage or Current depending on this select pin
-      inverted: true  # determine whether true reports Voltage
-      number: P11
-    cf1_pin:
-      inverted: true 
-      number: P24
-    cf_pin: 
-      inverted: true 
-      number: P26
-    update_interval: 5s
-    change_mode_every: 4
-    # update_interval: 5s
-    # initial_mode: "VOLTAGE"
-    # change_mode_every: 4294967295
-    # Adjust according to the actual resistor values on board to calibrate the specific unit
-    # voltage_divider:  "895"               # LOWER VALUE GIVES LOWER VOLTAE
-    # current_resistor: "0.0006"          # HIGHER VALUE GIVES LOWER WATTAGE
-    voltage_divider: "814"
-    current_resistor: "0.001"
-    # how the power monitoring values are returned to ESPHome
-    voltage:
-      name: $friendly_devicename Voltage
-      id:   ${low_devicename}_voltage
-      unit_of_measurement: V
-      accuracy_decimals: 1
-      filters:
-        - skip_initial: 2
-        - sliding_window_moving_average:
-            window_size: 4
-            send_every: 2
-      on_value:
-        component.update: ${low_devicename}_apparent_power
-    power:
-      name: $friendly_devicename Power
-      id:   ${low_devicename}_power
-      unit_of_measurement: W
-      accuracy_decimals: 0
-      on_value:
-        component.update: ${low_devicename}_power_factor
-      filters:
-        # - skip_initial: 15
-        - skip_initial: 2
-        - sliding_window_moving_average:
-            window_size: 4
-            send_every: 2
-    current:
-      name: $friendly_devicename Current
-      id:   ${low_devicename}_current
-      unit_of_measurement: A
-      accuracy_decimals: 3
-      filters:
-        # - multiply: 1
-        - multiply: 0.450
-        - skip_initial: 2
-        - sliding_window_moving_average:
-            window_size: 4
-            send_every: 2
-
-    # power is simply current x voltage -- except that the pc191ha doesn't follow that formula.
-        # Setting current_resistor to give an accurate Amperage does NOT also give the correct Wattage
-        # my work-around is to calculate current from power / voltage
-        #  - platform: template  
-        #    name: $friendly_devicename Current
-        #    id:   ${low_devicename}_current
-        #    unit_of_measurement: A
-        #    accuracy_decimals: 2
-        #    update_interval: $update_interval_seconds
-        #    lambda: |-
-        #      return (id(${low_devicename}_power).state / id(${low_devicename}_voltage).state);
-        #    filters:  
-        #      - skip_initial: 5     # give time for data to settle to avoid NaN
-  - platform: total_daily_energy
-    name: $friendly_devicename daily consumption
-    id: ${low_devicename}_total_daily_energy
-    power_id: ${low_devicename}_apparent_power
-    filters: 
-      - multiply: 0.001 # to kWh
-    unit_of_measurement: kWh
-  - platform: template
-    name: "Apparent power"
-    id: ${low_devicename}_apparent_power
-    unit_of_measurement: VA
-    device_class: apparent_power
-    lambda: |-
-      return id(${low_devicename}_voltage).state * id(${low_devicename}_current).state;
-    update_interval: never
-    on_value:
-        component.update: ${low_devicename}_power_factor
-  - platform: template
-    name: "Power factor"
-    id: ${low_devicename}_power_factor
-    unit_of_measurement: ''
-    device_class: power_factor
-    lambda: |-
-      return id(${low_devicename}_power).state / id(${low_devicename}_apparent_power).state;
-    filters:
-      - clamp:
-          min_value: 0
-          max_value: 1
-    update_interval: never
-
-
-
-text_sensor:
-  - platform: template
-    name: Uptime Human Readable
-    id: uptime_human
-    icon: mdi:clock-start
-  - platform: wifi_info
-    ip_address:
-      name: IP Address
-      entity_category: diagnostic
-
-light:
-  - platform: binary
-    name: "led"
-    internal: true
-    id: led
-    output: red_led
-
-
-output:
-  - platform: gpio
-    id: red_led
-    pin:
-      number: P8
-      # inverted: true
-
-
-status_led:
-    pin:
-      number: P10
-      # inverted: true
-
-binary_sensor:
- # - platform: status
- #   name: Status
- #   entity_category: diagnostic
-
-  - platform: gpio
-    pin:
-      number: P7
-      mode:
-        input: true
-        pullup: true
-      inverted: true
-    id: button1
-    filters:
-      - delayed_on: 50ms
-      - delayed_off: 50ms
-    on_click:
-      - switch.toggle: outlet
-
-  #- platform: status
-  #  name: ${friendly_devicename} status
-
-switch:
-  - platform: gpio
-    name: ${friendly_devicename} Outlet
-    id: outlet
-    pin: P6
-    icon: mdi:power-socket-eu
-    on_turn_on:
-      - light.turn_on: led
-    on_turn_off:
-      - light.turn_off: led
-    restore_mode: RESTORE_DEFAULT_ON
-  # Switch to restart the plug
-  - platform: restart
-    name: ${friendly_devicename} Restart Switch
-
-# Enable time component to reset energy at midnight
-time:
-  - platform: homeassistant
-    id: homeassistant_time
+  lsc: !include common/LSC_Action_1681PG_plug.yaml 

+ 5 - 231
lscp03.yaml

@@ -4,237 +4,11 @@ substitutions:
   low_devicename: lscp03
   low_devicename: lscp03
   friendly_devicename: LSC Plug 03
   friendly_devicename: LSC Plug 03
   update_interval_seconds: "15s"
   update_interval_seconds: "15s"
-  
-esphome:
-  name: $devicename
-  friendly_name: $friendly_devicename
-
-bk72xx:
-  board: generic-bk7231t-qfn32-tuya
-  #framework:
-  #   version: dev
+  voltage_divider: "814"
+  current_resistor: "0.001"
+  multiply: 0.450
 
 
 packages:
 packages:
-  # Enable Home Assistant API
   esphome: !include common/keys.yaml
   esphome: !include common/keys.yaml
-
-logger:
-
-web_server:
-  port: 80
-
-wifi:
-  ssid: !secret iot_ssid
-  password: !secret iot_password
-  domain: .int.mmax.cloud
-
-
-sensor:
-  - platform: wifi_signal
-    name: "WiFi Signal Sensor"
-    update_interval: 60s
-
-  - platform: uptime
-    name: Uptime Sensor
-    id: uptime_sensor
-    update_interval: 60s
-    on_raw_value:
-      then:
-        - text_sensor.template.publish:
-            id: uptime_human
-            state: !lambda |-
-              int seconds = round(id(uptime_sensor).raw_state);
-              int days = seconds / (24 * 3600);
-              seconds = seconds % (24 * 3600);
-              int hours = seconds / 3600;
-              seconds = seconds % 3600;
-              int minutes = seconds /  60;
-              seconds = seconds % 60;
-              return (
-                (days ? to_string(days) + "d " : "") +
-                (hours ? to_string(hours) + "h " : "") +
-                (minutes ? to_string(minutes) + "m " : "") +
-                (to_string(seconds) + "s")
-              ).c_str();
-#
-# power monitoring
-#
-    # PC191HA includes a BL0937 chip for measuring power consumption
-    #     and BL0937 is a variation of hlw8012, but using inverted SEL pin functionality
-  - platform: hlw8012
-    model: BL0937     # note that the model must be specified to use special calculation parameters
-    sel_pin:          # I believe that cf_pin reports either Voltage or Current depending on this select pin
-      inverted: true  # determine whether true reports Voltage
-      number: P11
-    cf1_pin:
-      inverted: true 
-      number: P24
-    cf_pin: 
-      inverted: true 
-      number: P26
-    update_interval: 5s
-    change_mode_every: 4
-    # update_interval: 5s
-    # initial_mode: "VOLTAGE"
-    # change_mode_every: 4294967295
-    # Adjust according to the actual resistor values on board to calibrate the specific unit
-    # voltage_divider:  "895"               # LOWER VALUE GIVES LOWER VOLTAE
-    # current_resistor: "0.0006"          # HIGHER VALUE GIVES LOWER WATTAGE
-    voltage_divider: "814"
-    current_resistor: "0.001"
-    # how the power monitoring values are returned to ESPHome
-    voltage:
-      name: $friendly_devicename Voltage
-      id:   ${low_devicename}_voltage
-      unit_of_measurement: V
-      accuracy_decimals: 1
-      filters:
-        - skip_initial: 2
-        - sliding_window_moving_average:
-            window_size: 4
-            send_every: 2
-      on_value:
-        component.update: ${low_devicename}_apparent_power
-    power:
-      name: $friendly_devicename Power
-      id:   ${low_devicename}_power
-      unit_of_measurement: W
-      accuracy_decimals: 0
-      on_value:
-        component.update: ${low_devicename}_power_factor
-      filters:
-        # - skip_initial: 15
-        - skip_initial: 2
-        - sliding_window_moving_average:
-            window_size: 4
-            send_every: 2
-    current:
-      name: $friendly_devicename Current
-      id:   ${low_devicename}_current
-      unit_of_measurement: A
-      accuracy_decimals: 3
-      filters:
-        # - multiply: 1
-        - multiply: 0.450
-        - skip_initial: 2
-        - sliding_window_moving_average:
-            window_size: 4
-            send_every: 2
-
-    # power is simply current x voltage -- except that the pc191ha doesn't follow that formula.
-        # Setting current_resistor to give an accurate Amperage does NOT also give the correct Wattage
-        # my work-around is to calculate current from power / voltage
-        #  - platform: template  
-        #    name: $friendly_devicename Current
-        #    id:   ${low_devicename}_current
-        #    unit_of_measurement: A
-        #    accuracy_decimals: 2
-        #    update_interval: $update_interval_seconds
-        #    lambda: |-
-        #      return (id(${low_devicename}_power).state / id(${low_devicename}_voltage).state);
-        #    filters:  
-        #      - skip_initial: 5     # give time for data to settle to avoid NaN
-  - platform: total_daily_energy
-    name: $friendly_devicename daily consumption
-    id: ${low_devicename}_total_daily_energy
-    power_id: ${low_devicename}_apparent_power
-    filters: 
-      - multiply: 0.001 # to kWh
-    unit_of_measurement: kWh
-  - platform: template
-    name: "Apparent power"
-    id: ${low_devicename}_apparent_power
-    unit_of_measurement: VA
-    device_class: apparent_power
-    lambda: |-
-      return id(${low_devicename}_voltage).state * id(${low_devicename}_current).state;
-    update_interval: never
-    on_value:
-        component.update: ${low_devicename}_power_factor
-  - platform: template
-    name: "Power factor"
-    id: ${low_devicename}_power_factor
-    unit_of_measurement: ''
-    device_class: power_factor
-    lambda: |-
-      return id(${low_devicename}_power).state / id(${low_devicename}_apparent_power).state;
-    filters:
-      - clamp:
-          min_value: 0
-          max_value: 1
-    update_interval: never
-
-
-
-text_sensor:
-  - platform: template
-    name: Uptime Human Readable
-    id: uptime_human
-    icon: mdi:clock-start
-  - platform: wifi_info
-    ip_address:
-      name: IP Address
-      entity_category: diagnostic
-
-light:
-  - platform: binary
-    name: "led"
-    internal: true
-    id: led
-    output: red_led
-
-
-output:
-  - platform: gpio
-    id: red_led
-    pin:
-      number: P8
-      # inverted: true
-
-
-status_led:
-    pin:
-      number: P10
-      # inverted: true
-
-binary_sensor:
-  - platform: status
-    name: Status
-    entity_category: diagnostic
-
-  - platform: gpio
-    pin:
-      number: P7
-      mode:
-        input: true
-        pullup: true
-      inverted: true
-    id: button1
-    filters:
-      - delayed_on: 50ms
-      - delayed_off: 50ms
-    on_click:
-      - switch.toggle: outlet
-
-  - platform: status
-    name: ${friendly_devicename} status
-
-switch:
-  - platform: gpio
-    name: ${friendly_devicename} Outlet
-    id: outlet
-    pin: P6
-    icon: mdi:power-socket-eu
-    on_turn_on:
-      - light.turn_on: led
-    on_turn_off:
-      - light.turn_off: led
-    restore_mode: RESTORE_DEFAULT_OFF
-  # Switch to restart the plug
-  - platform: restart
-    name: ${friendly_devicename} Restart Switch
-
-# Enable time component to reset energy at midnight
-time:
-  - platform: homeassistant
-    id: homeassistant_time
+  diag: !include common/diag.yaml
+  lsc: !include common/LSC_Action_1681PG_plug.yaml