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
@boozeman
Copy link
Author

boozeman commented May 5, 2024

I have been cutting a few 130fwt in the past, but this wont even let Cloudcutter connect to the accesspoint on the device for some reason. This is quite a old device, maybe a couple years old. I think you are right.. I think I have to just open it and find out what chip its actually using.

I have one 130FWT with WB2S (BK7231T) and i originally rip this open to flash it with OpenBeken. It was really annoying process because cover was clued. I did not try any heat gun on it. Just sharp X-Acto blade hobby knife.

The programming went using traditional serial-connection .

I think that esphome firmware can be uploaded serial too. Did not tested myself..

@Klorins
Copy link

Klorins commented May 5, 2024

Screws wasnt too bad, but the clips was really holding it together. Tried to be as careful as I could, broke one clip, but doesnt matter as the screws will hold it nicely together. They dont want us to open them, thats for sure.

Anyways this is how the chip looks like:
chip1

chip2

@boozeman
Copy link
Author

boozeman commented May 5, 2024

Ooh, you got lucky! That TYWE3S is ESP8266 based. You can Flash it with Tasmota. Some soldering work with Rx, Tx, Gnd and 3V3 and enable to that I00 pin. You can flash it with Tasmotizer https://github.com/tasmota/tasmotizer Use USB to Serial converter for the job.

Or of course use ESPHome, but the yaml here need to be modified. I have several of these TYWE3S plugs in use. with Tasmota.

@Klorins
Copy link

Klorins commented May 5, 2024

Yes, at least easy access to the soldering points. I am a bit rusty on this, been a few months. I would like to flash it to use with ESPHome as I have a few devices in there from before and use Home Assistant.

I forgot what the 100 pin does, but will read up a bit on this. I have a USB to serial programmer so hopefully that will work without taking off some capacitors.

This is a picture of the fwt130 I did late last year:

c260a339-c25e-430d-9122-620d9448c960

I actually messed up the housing for it on my first one (we have 4 of them). I fixed it by making a custom case for it and it works fine, but I learned that you can solder off those big solder points you see in the next picture to take it all apart:

c5da9af8-bd95-426f-a09f-75fd700f2d9e

I am posting the pictures since there seem to be several versions of it, but I am not sure about that.

@boozeman
Copy link
Author

boozeman commented May 5, 2024

Yeah, I have one of 130FWT too, Tuya has good documents about the chips they used https://developer.tuya.com/en/docs/iot/wb-series-module?id=Kaiuyh0h7g3f2

Some flashing instructions can be found in https://www.elektroda.com/ forums. Search Beken 7231. Firmware git https://github.com/openshwprojects/OpenBK7231T_App

@Klorins
Copy link

Klorins commented May 6, 2024

Hi again, sorry to bother you. Do you normally solder the chip off the board?
I cant seem to provide enough power too the board. I tried first with 3.3 from the usb cable and the diode on the board blink and the board turns off again. Today I tried with a PC PSU and take 3.3v from the sata cable, but it still does the same.
I dont think there should be any shorts or other things here, maybe best to solder out the whole chip from the board?

@boozeman
Copy link
Author

boozeman commented May 6, 2024

Hi again, sorry to bother you. Do you normally solder the chip off the board? I cant seem to provide enough power too the board. I tried first with 3.3 from the usb cable and the diode on the board blink and the board turns off again. Today I tried with a PC PSU and take 3.3v from the sata cable, but it still does the same. I dont think there should be any shorts or other things here, maybe best to solder out the whole chip from the board?

Hi, this doesn't really bother me :) I really forgot to tell you that when flashing the device for the first time, the easiest thing is to remove the 0R resistor R33 during the flashing. It is connected to P10 pin which is RX. This work with Beken-based chips.

ESP-ones can be flashed without any modifications. Just connect that I00 pin to ground using example push button for a while when start flashing. I was feeding 3V3 from usb-serial adapter during the process.

wifip120FWT

@Klorins
Copy link

Klorins commented May 6, 2024

Thanks for the tips, you was right... I didnt need external power.

Main issue I had was that data connection needs to be connected like this:

rx<--->tx
tx<--->rx

connect GPIO 0 to Ground

put the USB of programmer into PC and keep GPIO 0 connected to ground for 5-6 seconds while chip boots up and disconnect it.

Now its programmable from ESPHome.

I can access the device now in the browser, awesome!

Next step is to make the plug actually do something.. he he

I guess cant just copy your code, I assume the pinout is different.. but I havent had time to look into that yet.

This is what I got so far:

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

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:

@boozeman
Copy link
Author

boozeman commented May 7, 2024

Hi,

I can get pin config from Tasmotized device tomorrow for you :)

@boozeman
Copy link
Author

boozeman commented May 8, 2024

Pin Config for Tasmota device.

image

@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