Skip to content

Instantly share code, notes, and snippets.

@boozeman
Last active May 8, 2024 16:23
Show Gist options
  • Save boozeman/571e0efc94938724b691577b8353f080 to your computer and use it in GitHub Desktop.
Save boozeman/571e0efc94938724b691577b8353f080 to your computer and use it in GitHub Desktop.
ESPHome configuration for Nedis WIFIPO120FWT
esphome:
name: nedis-esp-003
substitutions:
device_name: nedis_esp_003
friendly_name: Nedis ESP 003
# Nedis WIFIPO120FWT with bk7231N chip has markings "10T40 and µ" on it's label
# Nedis WIFIPO120FWT with bk7231T chip has no those markings on it's label (BL0937 pins CF=P7, CF1=P8 and sel=P24, Light=P6 other pins the same)
# Use Cloud Cutter profile: tuya-generic-fs-02we-1ch-16a-smart-switch-with-energy-monitoring
# Generate correct API-key after copy-paste
# Create HA input Helper (example 0-7200 seconds) with device friendly_name for pulsetime Function
# DISCLAIMER: The Rear Lights Warranty is on. Use at your own risk!
bk72xx:
board: generic-bk7231n-qfn32-tuya
logger:
web_server:
captive_portal:
ota:
password: !secret ota_password
mdns:
api:
encryption:
key: "Generate API-key: https://esphome.io/components/api.html?highlight=randomly%20generated"
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
ap:
ssid: "${friendly_name} Fallback Hotspot"
password: !secret ap_password
text_sensor:
- platform: libretiny
version:
name: ${device_name} LibreTiny Version
binary_sensor:
- platform: gpio
id: ${device_name}_binary_switch_1
pin:
number: P10
inverted: true
mode: INPUT_PULLUP
on_press:
then:
- switch.toggle: ${device_name}_switch_1
switch:
- platform: gpio
id: ${device_name}_switch_1
name: ${friendly_name} Relay 1
pin: P26
on_turn_on:
- light.turn_on: ${device_name}_light_status
- script.execute: pulsetime # Initialize pulsetime script
on_turn_off:
- light.turn_off: ${device_name}_light_status
- script.stop: pulsetime # Initialize pulsetime script
light:
- platform: status_led
id: ${device_name}_light_status
pin:
number: P8
inverted: true
sensor:
- platform: hlw8012
model: BL0937
cf_pin:
number: P7
inverted: true
cf1_pin:
number: P6
inverted: true
sel_pin:
number: P24
inverted: true
current:
name: ${friendly_name} Current
id: ${device_name}_current
voltage:
name: ${friendly_name} Voltage
id: ${device_name}_voltage
filters:
# Map from sensor -> measured value Check values for your own plug!
- calibrate_linear:
- 0.0 -> 0.0
- 604.8 -> 236
power:
name: ${friendly_name} Power
id: ${device_name}_power
filters:
# Map from sensor -> measured value Check values for your own plug!
- calibrate_linear:
- 0.0 -> 0.0
- 720.7 -> 266.8
energy:
name: ${friendly_name} Energy
id: ${device_name}_energy
voltage_divider: 1881 # 4 * 470K resistors upstream and 1k resistor downstream for voltage divider (4 x 470 000 + 1000) / 1000
current_resistor: 0.001 ohm
update_interval: 60s
# Example configuration entry with 2 sensors and filter
- platform: wifi_signal # Reports the WiFi signal strength/RSSI in dB
name: "${friendly_name} WiFi Signal dB"
id: ${device_name}_wifi_signal_db
update_interval: 60s
entity_category: "diagnostic"
- platform: copy # Reports the WiFi signal strength in %
source_id: ${device_name}_wifi_signal_db
name: "${friendly_name} WiFi Signal Percent"
filters:
- lambda: return min(max(2 * (x + 100.0), 0.0), 100.0);
unit_of_measurement: "%"
entity_category: "diagnostic"
# Input helper as sensor for pulsetime script
- platform: homeassistant
name: "${friendly_name} Pulsetime"
id: ${device_name}_pulsetime
entity_id: input_number.${device_name}_pulsetime #The entity of input_number in HA
# Tasmota like pulsetime script
script:
- id: pulsetime
then:
- if:
condition:
lambda: 'return id(${device_name}_pulsetime).state > 0;' # Disable pulsetime if Helper is set to 0
then:
- delay: !lambda |-
return id(${device_name}_pulsetime).state * 1000;
- switch.turn_off: ${device_name}_switch_1
@Klorins
Copy link

Klorins commented May 8, 2024

Thank you..
I got everything working now. I managed to calibrate the HLW8012 Power Sensor as well, but I used guide on the ESPHome site for that.
Its a bit different from how you did it in your code here, I am not sure if its any right or wrong.

I used another powerplug and a 1000w heater when adjusting it, and they seem to show pretty much the same values now.

Here is my entire code now, could you see if I messed up something.

esphome:
  name: nedis-120fwt
  friendly_name: Nedis-Smartplug-120fwt

substitutions:
  device_name: nedis_120fwt
  voltage_divider: "4252.79"  # Default value: "3451"   | HLW8012 Power Sensor
  current_resistor: "0.00043" # Default value: "0.001"  | Check guide at: https://esphome.io/components/sensor/hlw8012.html#hlw8012-power-sensor
  current_multiply: "0.470"   # Default value: "1"      | to make Power Sensor show correct values

esp8266:
  board: esp01_1m
  framework:
    version: latest
    
# Enable logging
logger:

# Enable web-interface
web_server:

# Enable Home Assistant API
api:

ota:

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Nedis-120Fwt Hotspot"

captive_portal:

text_sensor:
  - platform: version
    name: "ESPHome Version"

binary_sensor:
  - platform: gpio
    id: ${device_name}_binary_switch_1
    pin:
      number: GPIO00
      inverted: true
      mode: INPUT_PULLUP
    on_press:
      then:
        - switch.toggle: ${device_name}_switch_1

switch:
  - platform: gpio
    id: ${device_name}_switch_1
    name: Switch
    pin: GPIO14
    on_turn_on:
      - light.turn_on: ${device_name}_light_status
      - script.execute: pulsetime # Initialize pulsetime script
    on_turn_off:
      - light.turn_off: ${device_name}_light_status
      - script.stop: pulsetime # Initialize pulsetime script

light:
  - platform: status_led
    id: ${device_name}_light_status
    pin:
      number: GPIO13
      inverted: true

sensor:
  - platform: hlw8012
    model: BL0937
    cf_pin:
      number: GPIO04
      inverted: true
    cf1_pin:
      number: GPIO05
      inverted: true
    sel_pin:
      number: GPIO12
      inverted: true
    current:
      name: Current
      id: ${device_name}_current
      filters:
        - multiply: ${current_multiply}
    voltage:
      name: Voltage
      id: ${device_name}_voltage
    power:
      name: Power
      id: ${device_name}_power
    energy:
      name: Energy
      id: ${device_name}_energy
    voltage_divider: ${voltage_divider}
    current_resistor: ${current_resistor}
    update_interval: 60s

  - platform: wifi_signal # Reports the WiFi signal strength/RSSI in dB
    name: WiFi Signal dB
    id: ${device_name}_wifi_signal_db
    update_interval: 240s
    entity_category: "diagnostic"

# Input helper as sensor for pulsetime script
  - platform: homeassistant
    name: "${friendly_name} Pulsetime"
    id: ${device_name}_pulsetime
    entity_id: input_number.${device_name}_pulsetime #The entity of input_number in HA   

script:
  - id: pulsetime
    then:
      - if:
          condition:
            lambda: 'return id(${device_name}_pulsetime).state > 0;' # Disable pulsetime if Helper is set to 0
          then:
            - delay: !lambda |-
                return id(${device_name}_pulsetime).state * 1000; 
            - switch.turn_off: ${device_name}_switch_1

Another thing.. I have no idea what this does:

# Input helper as sensor for pulsetime script
  - platform: homeassistant
    name: "${friendly_name} Pulsetime"
    id: ${device_name}_pulsetime
    entity_id: input_number.${device_name}_pulsetime #The entity of input_number in HA   

script:
  - id: pulsetime
    then:
      - if:
          condition:
            lambda: 'return id(${device_name}_pulsetime).state > 0;' # Disable pulsetime if Helper is set to 0
          then:
            - delay: !lambda |-
                return id(${device_name}_pulsetime).state * 1000; 
            - switch.turn_off: ${device_name}_switch_1

I dont see anything in Home Assistant from it either.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment