jdobry

Untitled

Jan 16th, 2026
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
YAML 4.63 KB | Software | 0 0
  1. esphome:
  2.   name: lscsmartplug
  3.   friendly_name: ${friendly_name}
  4.  
  5. bk72xx:
  6.   board: generic-bk7231n-qfn32-tuya
  7.  
  8. logger:
  9.   baud_rate: 0
  10.   level: INFO
  11.  
  12. web_server:
  13.   version: 3
  14.  
  15. captive_portal:
  16. substitutions:
  17.   friendly_name: LSC Powerplug
  18.   voltage_divider: "795"
  19.   current_resistor: "0.001"
  20.   current_multiply: "0.450"
  21.  
  22. #mdns:
  23.  
  24. api:
  25.   encryption:
  26.     key: !secret api_encryption_key
  27.  
  28. ota:
  29.   platform: esphome
  30.   id: my_ota
  31.   password: !secret ota_password
  32.  
  33. wifi:
  34.   networks:
  35.     - ssid: !secret esphome2_ssid
  36.       password: !secret esphome2_psk
  37.   #ap:
  38.  
  39. button:
  40.   - platform: restart
  41.     name: Restart
  42.  
  43. #debug:
  44.   #update_interval: 30s
  45.  
  46.  
  47. # text_sensor:
  48. #   - platform: debug
  49. #     reset_reason:
  50. #       name: Reset Reason
  51.   # - platform: libretiny
  52.   #   version:
  53.   #     name: LibreTiny Version
  54.  
  55. sensor:
  56.   - platform: uptime
  57.     name: Uptime
  58.   - platform: hlw8012
  59.     model: BL0937
  60.     update_interval: 500ms
  61.     change_mode_every: 2
  62.     cf_pin:
  63.       number: P26
  64.       inverted: true
  65.     cf1_pin:
  66.       number: P24
  67.       inverted: true
  68.     sel_pin:
  69.       number: P11
  70.       inverted: true
  71.     current:
  72.       name: Current
  73.       id: current
  74.       accuracy_decimals: 3
  75.       on_value:
  76.         component.update: apparent_power
  77.       filters:
  78.         - multiply: ${current_multiply}
  79.         - sliding_window_moving_average:
  80.             window_size: 4
  81.             send_every: 2
  82.     voltage:
  83.       name: Voltage
  84.       id: voltage
  85.       on_value:
  86.         component.update: apparent_power
  87.       filters:
  88.         - sliding_window_moving_average:
  89.             window_size: 4
  90.             send_every: 2
  91.     power:
  92.       name: Power
  93.       id: power
  94.       on_value:
  95.         component.update: power_factor
  96.       filters:
  97.         - sliding_window_moving_average:
  98.             window_size: 4
  99.             send_every: 2
  100.     energy:
  101.       name: Energy
  102.     voltage_divider: ${voltage_divider}
  103.     current_resistor: ${current_resistor}
  104.   - platform: template
  105.     name: "Apparent power"
  106.     id: apparent_power
  107.     unit_of_measurement: VA
  108.     device_class: apparent_power
  109.     lambda: |-
  110.       return id(voltage).state * id(current).state;
  111.     update_interval: never
  112.     on_value:
  113.       component.update: power_factor
  114.   - platform: template
  115.     name: "Power factor"
  116.     id: power_factor
  117.     unit_of_measurement: ""
  118.     device_class: power_factor
  119.     lambda: |-
  120.       return id(power).state / id(apparent_power).state;
  121.     filters:
  122.       - clamp:
  123.           min_value: 0
  124.           max_value: 1
  125.     update_interval: never
  126.  
  127. binary_sensor:
  128.   - platform: gpio
  129.     id: binary_switch_1
  130.     pin:
  131.       number: P7
  132.       inverted: true
  133.       mode: INPUT_PULLUP
  134.     filters:
  135.       - delayed_on: 10ms
  136.     on_press:
  137.       then:
  138.         - switch.toggle: switch_1
  139.  
  140. switch:
  141.   - platform: gpio
  142.     id: switch_1
  143.     name: none
  144.     pin: P8
  145.     restore_mode: RESTORE_DEFAULT_OFF
  146.     on_turn_on:
  147.       script.execute: set_status_led
  148.     on_turn_off:
  149.       script.execute: set_status_led
  150.  
  151. light:
  152.   - platform: status_led
  153.     id: light_red
  154.     name: "Red led"
  155.     pin: P6
  156.     restore_mode: RESTORE_DEFAULT_OFF
  157.   - platform: binary
  158.     name: "Status led"
  159.     id: blue_led
  160.     output: output_blue_led
  161.     restore_mode: RESTORE_DEFAULT_OFF
  162.     internal: true
  163.  
  164. output:
  165.   - platform: gpio
  166.     id: output_blue_led
  167.     pin: P10
  168.  
  169. select:
  170.   - platform: template
  171.     name: "Status led mode"
  172.     id: status_led_mode
  173.     optimistic: true
  174.     restore_value: True
  175.     entity_category: CONFIG
  176.     update_interval: never
  177.     options:
  178.      - "Normal"
  179.       - "Invert"
  180.       - "Off"
  181.     initial_option: "Normal"
  182.     on_value:
  183.       script.execute: set_status_led
  184.  
  185. script:
  186.   - id: set_status_led
  187.     then:
  188.       - if:
  189.           condition:
  190.             lambda: |-
  191.               return strcmp(id(status_led_mode).state.c_str(), "Normal") == 0;
  192.           then:
  193.             if:
  194.               condition:
  195.                 switch.is_on: switch_1
  196.               then:
  197.                 light.turn_on: blue_led
  198.               else:
  199.                 light.turn_off: blue_led
  200.       - if:
  201.           condition:
  202.             lambda: |-
  203.               return strcmp(id(status_led_mode).state.c_str(), "Invert") == 0;
  204.           then:
  205.             if:
  206.               condition:
  207.                 switch.is_on: switch_1
  208.               then:
  209.                 light.turn_off: blue_led
  210.               else:
  211.                 light.turn_on: blue_led
  212.       - if:
  213.           condition:
  214.             lambda: |-
  215.               return strcmp(id(status_led_mode).state.c_str(), "Off") == 0;
  216.           then:
  217.             light.turn_off: blue_led
Advertisement
Add Comment
Please, Sign In to add comment