logo elektroda
logo elektroda
X
logo elektroda

[BK7231N] Smart Plug with BL0937 - How to turn off relay when "Energy Today" surpasses a v

Porkoltszaft 675 2
ADVERTISEMENT
  • #1 20908803
    Porkoltszaft
    Level 3  

    Hi!

    I successfully flashed OpenBeken to a CB2S module, which is in a smart socket. Started the BL0937 and NTP driver, calibrated the power meter, this all works flawlessly.

    My goal is:
    - firstly, I want to turn off the relay AFTER the "Energy Today" has reached/surpassed a value. Eg. Turn off a lamp automatically if it reached 10Wh a day. After that, I may manually re-power the lamp.

    I manage to get the current value of the "Energy Today" from $energy. However, if I try this:

    
    echo $energy
    Info:CMD:6.908343
    Info:CMD:[WebApp Cmd 'echo $energy' Result] OK
    addChangeHandler $energy >= 7 backlog SetChannel 1 0;
    Info:EVENT:CMD_AddChangeHandler: 6 is not a valid event
    Info:CMD:[WebApp Cmd 'addChangeHandler $energy >= 7 backlog SetChannel 1 0;' Result] Bad argument
    


    Now, this is the first step.
    My final goal is this:
    - A Midea AC (Midea Oasis Plus MOP3-12-SP) is plugged in this socket. I do not want to just cut the power after the AC consumed eg. 3kW a day, I want it to turn off, by sending the "turn off" IR signal to it. So ultimately, the socket is just a power meter, I do not operate the relay of it. To send the IR signal, I figured out 2 ways:

    a) have OpenBeken manage it, and I know there are IREnable & IRSend commands, however, I do not know what to send (don't know what protocol the Midea uses, what is the command, etc.). If you can help me with this, it will be appreciated. Do I have to connect the IR led to a PWM output, or a simple GPIO will do? If PWM is required I have to modify the socket's circuit, but that's fine, I can do it.
    b) I have a spare remote control for the AC, and I'm willing to dismantle it. I can build a circuit to simulate the press of the "power" button on the remote (basically a transistor switch, which is operated by the socket) This is a more bulky approach, because I have to wire the remote to the socket, but if this is the only way, I will do it.

    So in overall:
    - how can I execute commands after the $energy has reached a value?
    - If I want to use the IR functions, do I have to connect the IR LED to a PWM output? Do I need to drive the LED with a transistor, or just wire the IR LED to a pin of the uC?
    - If you know the protocol/IR command of the Midea AC "turn off" (Midea Oasis Plus MOP3-12-SP), can you share it please?

    Thanks in advance!
    Have a nice day,
    David
  • ADVERTISEMENT
  • #2 20912580
    p.kaczmarek2
    Moderator Smart Home
    Hello, for energy checking, you can try something like this:
    
    alias alarm backlog POWER OFF; EnergyCntReset
    again:
    delay_s 10
    if $energy>10 then alarm
    goto again
    
    

    Alternatively, you can use the following driver:
    
    ChargingLimit
    

    You can find more about here on forum, use search function.

    For IR, you should follow the same approach as you'd with Tasmota:
    https://tasmota.github.io/docs/IR-Remote/
    Information about IR Remote control and IR transmitter.
    Connection diagram with IR sensor, 2N222 transistor, and IR LED.
    Circuit diagrams with FET and NPN transistors

    Regarding Midea AC, unfotunatelly, I have no idea. I just will say that we have OBK fork with extended IR support (IRRemote update by VFonov) on Github, so you may consider trying that as well if the public OBK release does not work for you.
    Helpful post? Buy me a coffee.
  • #3 20929702
    Porkoltszaft
    Level 3  
    Thanks for your reply, it helped with the relay. Unfortunately for the IR part, I could not get it to work. So after learning that ESPHome has Midea IR control too, I used that for this project.

    Have a nice day!
    David
ADVERTISEMENT