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