logo elektroda
logo elektroda
X
logo elektroda

[ BK7231N/CBU] New Device USB Rechargeable LED Night Light Tuya WiFi Smart Motion Sensor

lionboy 1413 7
ADVERTISEMENT
  • #1 20931956
    lionboy
    Level 10  

    Hello,

    Today I bought a new device with CBU on it. Flashing only works via UART, and the version is MCU v1.0.10.

    WiFi cabinet LED lamp for smart home lighting.
    https://vi.aliexpress.com/item/10050056714858...t_main.16.4e5f1c24BrcPTA&gatewayAdapt=glo2vnm

    After I did a full backup, I tried to put Open Beken on it, but it is not working. I can only control the LED, but not the PIR and Lux sensors, which I have from the extracted bin file.

    Device configuration, as extracted from Tuya: 
    - LED Cool (Channel 4) on P24
    - PWM Frequency 1000
    - PIR Sensitivity 8
    - PIR Frequency 20000
    - Control Pin (TODO) on P26
    - PIR Low Duty 16
    - PIR High Duty 7
    - PIR Input 6
    Device seems to be using CBU module, which is using BK7231N.
    And the Tuya section starts, as usual, at 2023424


    On ESPHome, I have the same problem. But on ESPHome, I can control the LUX and PIR sensors, but not like on the Tuya App. On the Tuya App, you can control the LED as a switch and can control the LED with the PIR and Lux sensors.

    Lighting control panel Lampa Hol 1 with on/off button. App interface with settings for Lamp Hol 1 User interface of a lighting control app for Lampa Hol 1”. App screen for Lampa Hol 1 with sensor settings. Close-up of a circuit board with a micro USB connector and LEDs on a strip.

    ESPHOME yaml:

    esphome:
      name: lumina-hol1
    bk72xx:
      board: generic-bk7231n-qfn32-tuya
    logger:
    web_server:
    captive_portal:
    mdns:
    api:
      password: ""
    ota:
      password: ""
    wifi:
      ssid: !secret wifi_smart
      password: !secret wifi_smart_pass
      ap:
    button:
      - platform: restart
        name: Restart
    debug:
      update_interval: 30s
    text_sensor:
      - platform: debug
        reset_reason:
          name: Reset Reason
      - platform: libretiny
        version:
          name: LibreTiny Version
    sensor:
      - platform: uptime
        name: Uptime
      - platform: adc
        pin: P23
        id: lux_sensor
        name: "LUX Sensor"
        update_interval: '10s'
        unit_of_measurement: lux
        filters:
          - lambda: |- 
              return (x / 10000.0) * 2000000.0;
    output:
      - platform: libretiny_pwm
        id: output_cold
        pin: P24
        frequency: 1000 Hz
    light:
      - platform: monochromatic
        id: light_monochromatic
        name: Light
        output: output_cold
    binary_sensor:
      - platform: gpio
        pin: 26
        name: "PIR Sensor"
        device_class: motion
        id: pir_sensor_light
        on_press:
          then:
            - component.update: lux_sensor
    


    I will attach a 2 MB binary file.
  • ADVERTISEMENT
  • #2 20932480
    lionboy
    Level 10  
    And this is JSON:

    {
    	"Jsonver":"1.0.8",
    	"brightmin":"10",
    	"gmwb":"75",
    	"title20":"0",
    	"dimval":"0",
    	"dusk":"265",
    	"gmwg":"70",
    	"cdsval":"2",
    	"pirsense_lv":"1",
    	"wfcfg":"spcl",
    	"colormin":"10",
    	"lockt":"7",
    	"preheatt":"20",
    	"pmemory":"1",
    	"gmkb":"60",
    	"cmod":"c",
    	"evenfall":"460",
    	"cwtype":"0",
    	"day":"0",
    	"pirin_lv":"1",
    	"rstbr":"10",
    	"colormax":"100",
    	"c_pin":"24",
    	"pirhduty":"0",
    	"notdisturb":"0",
    	"night":"2180",
    	"module":"CBU",
    	"pirrange":"0",
    	"ctrl_lv":"1",
    	"cwmaxp":"100",
    	"dmod":"0",
    	"brightmax":"100",
    	"trigmod":"0",
    	"wfct":"3",
    	"pwmhz":"1000",
    	"pirsense_pin":"8",
    	"defbright":"100",
    	"rstnum":"5",
    	"rstcor":"c",
    	"dimt":"1",
    	"deftemp":"100",
    	"c_lv":"1",
    	"pirfreq":"20000",
    	"trigdelay":"10",
    	"keyfunc":"0",
    	"ctrl_pin":"26",
    	"pirmod":"0",
    	"pirlduty":"16",
    	"pirir":"7",
    	"wt":"0",
    	"prodagain":"1",
    	"remdmode":"0",
    	"pirmduty":"7",
    	"cagt":"20",
    	"dimmod":"1",
    	"colorpfun":"0",
    	"pirin_pin":"6",
    	"gmwr":"100",
    	"rgbt":"0",
    	"colormaxp":"100",
    	"gmkg":"60",
    	"onoffmode":"1",
    	"pirwarn":"0",
    	"rsttemp":"100",
    	"evening":"1400",
    	"category":"0501",
    	"gmkr":"80",
    	"defcolor":"c",
    	"crc":"46"
    }
    
  • ADVERTISEMENT
  • #4 20976457
    lionboy
    Level 10  
    Hello,

    Yes i change CBU with ESP32-C3 and now i am running on ESP32 with deep sleep implemented and Esphome;

    
    esphome:
      name: "lumina-hol2"
      friendly_name: "lumina-hol2"
      on_boot:
        priority: -100.0
        then:
          - light.turn_on:
              id: light_monochromatic
              transition_length: 1s
              brightness: 50%
          - light.turn_off:
              id: light_monochromatic
              transition_length: 1s
    esp32:
      board: esp32-c3-devkitm-1
      framework:
        type: arduino
    substitutions:
      # Timer duration (Minutes). E.G.: "60" 1 hour, "0.1" 6 Seconds
      off_time: "0.1"
    
    # Enable logging
    logger:
    
    web_server:
    
    # Enable Home Assistant API
    api:
    
    ota:
    
    wifi:
      ssid: !secret wifi_smart
      password: !secret wifi_smart_pass
    
      # Enable fallback hotspot (captive portal) in case wifi connection fails
      ap:
        ssid: "Lampa Hol 2"
        password: "puiuscrieparola"
    
    captive_portal:
    
    debug:
      update_interval: 30s
    
    
    globals:
      - id: manual_mode
        type: bool
        restore_value: yes
        initial_value: 'false'
      - id: light_sensitivity
        type: int
        restore_value: no
        initial_value: '0'
    
    script:
      - id: fullOnWhenMotion
        then:
          - logger.log:
              format: "fullOnWhenMotion"
          - light.turn_on:
              id: light_monochromatic
              brightness: 50%
      - id: waitThenDIM
        then:
          - logger.log:
              format: "waitThenDIM (%d, %d)"
              args: ["id(full_light_duration_s).state", "id(dim_light_percent).state"]
          - delay: !lambda "return id(full_light_duration_s).state;"
          - if:
              condition:
                - light.is_on: light_monochromatic
              then:
                - light.dim_relative:
                    id: light_monochromatic
                    relative_brightness: !lambda "return id(dim_light_percent).state;"
                - script.execute: waitThenOff
      - id: waitThenOff
        then:
          - logger.log:
              format: "waitThenOff (%d)"
              args: ["id(dim_light_duration_s).state"]
          - if:
              condition:
                - light.is_on: light_monochromatic
              then:
              - delay: !lambda "return id(dim_light_duration_s).state;"
              - light.turn_off: light_monochromatic
    
    text_sensor:
      - platform: debug
        reset_reason:
          name: Reset Reason
    
    sensor:
      - platform: uptime
        name: Uptime
      - platform: adc
        id: ambient
        name: Ambient
        unit_of_measurement: "V"
        state_class: "measurement"
        update_interval: 60s
        pin: 0
        filters:
          - multiply: 2.8
    
    deep_sleep: 
      id: deep_sleep_1
    
    time:
      - platform: homeassistant
        id: homeassistant_time
        on_time:
          #Deep sleep at 6am and wake up at 1am.
          - hours: 6
            then:
            - deep_sleep.enter:
                id: deep_sleep_1
                until: "00:59:00"
                time_id: homeassistant_time
    #      - hours: 1
    #        minutes: 00
    #        seconds: 00
    #        then:
    #        - switch.turn_on:
    #            id: day_night_mode
      - platform: sntp
        id: sntp_time
        timezone: Europe/Bucharest
        servers:
         - 0.pool.ntp.org
         - 1.pool.ntp.org
         - 2.pool.ntp.org
    
    binary_sensor:
      - platform: template
        id: timer
      - platform: gpio
        id: pir_sensor
        name: Motion
        device_class: motion
        pin:
          number: 6
          mode:
            input: true
        on_press:
          then:
            - if:
                condition:
                  - lambda: !lambda return (!id(manual_mode) && (id(ambient).state > id(light_sensitivity)));
                then:
                  - script.stop: waitThenDIM
                  - script.stop: fullOnWhenMotion
                  - script.execute: fullOnWhenMotion
        on_release:
          then:
            - if:
                condition:
                  - lambda: !lambda return (!id(manual_mode) && (id(light_monochromatic).current_values.is_on()));
                then:
                  - logger.log:
                      format: "Executing on_release"
                  - script.execute: waitThenDIM
    
    output:
      - platform: ledc
        id: output_pirsense
        pin: GPIO3
        frequency: 20000 Hz
        inverted: True
      - platform: ledc
        pin: GPIO5
        id: output_cold
        frequency: 1000Hz
    
    
    light:
      - platform: monochromatic
        id: light_monochromatic
        name: Light
        output: output_cold
    
    switch:
      - platform: template
        id: manual_mode_switch
        name: "Manual mode"
        lambda: !lambda |-
          return id(manual_mode);
        turn_on_action:
          then:
            if:
              condition:
                - lambda: "return !id(manual_mode);"
              then:
                - globals.set:
                    id: manual_mode
                    value: 'true'
                - script.stop: waitThenDIM
                - script.stop: waitThenOff
                - light.turn_on: light_monochromatic
        turn_off_action:
          then:
            if:
              condition:
                - lambda: "return id(manual_mode);"
              then:
                - script.stop: waitThenDIM
                - script.stop: waitThenOff
                - light.turn_off: light_monochromatic
                - globals.set:
                    id: manual_mode
                    value: 'false'
    
    number:
      - platform: template
        id: full_light_duration_s
        restore_value: yes
        name: Full light duration
        icon: "mdi:clock"
        entity_category: config
        unit_of_measurement: "s"
        min_value: 0
        max_value: 600
        initial_value: 10
        step: 1
        optimistic: true
    
      - platform: template
        id: dim_light_duration_s
        restore_value: yes
        name: Dim light duration
        icon: "mdi:clock"
        entity_category: config
        unit_of_measurement: "s"
        min_value: 0
        max_value: 60
        initial_value: 10
        step: 1
        optimistic: true
    
      - platform: template
        id: dim_light_percent
        restore_value: yes
        name: Dim light percent
        icon: "mdi:clock"
        entity_category: config
        unit_of_measurement: "%"
        min_value: 0
        max_value: 100
        initial_value: 50
        step: 1
        optimistic: true
    
      - platform: template
        id: pirduty_pwm
        restore_value: yes
        initial_value: 7
        name: PIR sensitivity
        icon: "mdi:chip"
        entity_category: config
        min_value: 7
        max_value: 16
        step: 1
        optimistic: true
        on_value:
          then:
            lambda: !lambda |-
              id(output_pirsense).set_level(x/100);
    
    select:
      - platform: template
        id: light_sensitivity_setting
        name: "Ambient light trigger"
        entity_category: config
        restore_value: yes
        options:
         - "Day"
         - "Dusk"
         - "Evenfall"
         - "Evening"
         - "Night"
        initial_option: "Evenfall"
        optimistic: true
        set_action:
          - logger.log:
              format: "Chosen option: %s"
              args: ["x.c_str()"]
        on_value:
          then:
            lambda: !lambda |-
              if (i == 1)
              {
                id(light_sensitivity) = 0.265f;
              }
              else
              if (i == 2)
              {
                id(light_sensitivity) = 0.460f;
              }
              else
              if (i == 3)
              {
                id(light_sensitivity) = 1.400f;
              }
              else
              if (i == 4)
              {
                id(light_sensitivity) = 2.180f;
              }
              else id(light_sensitivity) = 0.0f;
    
  • #5 20976683
    ferbulous
    Level 18  
    Hi @lionboy
    Thanks for the yaml
    Since I’ve never tried deep sleep/using battery powered device on esphome with esp32

    From the config, the device is in deep sleep for 18 hours, and stays online from 1am to 6am.
    Assuming it’s dark outside of that time frame so it won’t respond to any motion/lux changes?
    What’s the expected battery life on this?
  • ADVERTISEMENT
  • #6 20976694
    lionboy
    Level 10  

    Yes, but be careful on cbu deep sleep not working like on esp32, and you have 4 mode for night and day.

    This i used to replace CBU

    Just found this amazing item on AliExpress. Check it out! RON19.65 5% Off | ESP8685-WROOM-06 module, built-in ESP8685 chip, RISC-V 32-bit single-core microprocessor
    https://a.aliexpress.com/_EzAoERb

    H4
  • ADVERTISEMENT
  • #7 20976700
    divadiow
    Level 34  
    Cool. OpenBK has deep sleep support though..?
  • #8 20976709
    lionboy
    Level 10  

    Yea have but I didn’t know how to setup with open beken

Topic summary

The discussion revolves around a USB rechargeable LED night light equipped with a Tuya WiFi smart motion sensor, utilizing the BK7231N chip and CBU module. The user encountered issues while attempting to flash Open Beken firmware, successfully controlling the LED but failing to manage the PIR and Lux sensors. A JSON configuration was shared, detailing various parameters such as PWM frequency and PIR sensitivity. Another participant provided a template for Open Beken, indicating the device's compatibility with the Tuya ecosystem. The conversation also touched on transitioning to an ESP32-C3 setup, implementing deep sleep functionality, and the expected battery life under specific conditions. Concerns regarding the deep sleep functionality of the CBU module compared to the ESP32 were raised, along with a mention of OpenBK's support for deep sleep.
Summary generated by the language model.
ADVERTISEMENT