Mi-Light controller for Mysensors
-
spent some more time working on this. Still not having luck figuring out a what to send to the V_VAR1 to get the bulb to do anything
I can send simple on off for S_LIGHT V_STATUS
if (message.type == V_STATUS) { //Serial.println("triggered V_STATUS"); mlr.begin(); // Change light status Serial.println(message.getBool()); if ( message.getBool()) { Serial.println("here"); // Serial.println("triggered ON"); sendCommand (outgoingPacket_on, sizeof(outgoingPacket_on)); } else { // Serial.println("triggered off"); sendCommand(outgoingPacket_off, sizeof(outgoingPacket_off)); } _begin(); }Easy. But the V_VAR1 on S_CUSTOM I can't figure out what to put in the payload
if (message.type == V_VAR1) { // Serial.println("triggered V_VAR1"); incomingCommand = (char *)message.getCustom(); Serial.println((char *)message.getCustom()); mlr.begin(); Serial.println("#############"); for (int i=0; i<sizeof(outgoingPacket); i++) { outgoingPacket[i] = 16*char_to_uint8_t(incomingCommand[i*2]) + char_to_uint8_t(incomingCommand[i*2+1]); Serial.println(outgoingPacket[i]); } Serial.println("#############"); Serial.write(outgoingPacket, 7); sendCommand(outgoingPacket, sizeof(outgoingPacket)); _begin(); }I have referenced the hacking milight protocol pages and many other, I just can't seem to get it right to get my bulb to do anything.
Anyone want to take a shot at it? or have payload data I could try?
full sketch
#define MY_DEBUG #define MY_RADIO_NRF24 #define MY_REPEATER_FEATURE #include <MyConfig.h> #include <MySensors.h> #include <SPI.h> #define CE_PIN 9 //CE and CSN pin for nrf24 radio #define CSN_PIN 10 #include <nRF_24L01.h> #include <avr/power.h> #include <printf.h> #include "PL1167_nRF24.h" #include "MiLightRadio.h" #define NODE_ID 100 #define mi_command_repeat 30 //# of times to resend the command to bulb RF_24 mi_radio(CE_PIN, CSN_PIN); PL1167_nRF24 prf(mi_radio); MiLightRadio mlr(prf); // B0-176 F2-242 EA-234 6D B0 02 f0 static uint8_t outgoingPacket_on[7] = { 0xB0, 0xF2, 0xEA, 0x6D, 0x91, 0x03, 0x00}; //the first three #s are remote ID, replace with yours static uint8_t outgoingPacket_off[7] = { 0xB0, 0xF2, 0xEA, 0x04, 0x91, 0x04, 0x00}; uint8_t outgoingPacket[7]; #define sizeofincomingCommand 15 //command comes in text form of 7 uint8_t, with an additional NULL at end char *incomingCommand; //array for incoming command boolean mi_radio_state = false; void presentation() { //Send the sensor node sketch version information to the gateway sendSketchInfo("Milight controller", "1.0"); } void setup() { //clock_prescale_set(clock_div_2); //for a barebone atmega328p, this will make the CPU running at 4MHz. //Serial.begin(115200); // The third argument enables repeater mode. //Send the sensor node sketch version information to the gateway present(0, S_LIGHT); present(1, S_CUSTOM); } void receive(const MyMessage &message) { // The command will be transmitted in V_VAR1 type, in the following 7 byte format: ID1 ID2 ID3 COLOR BRIGHTNESS COMMAND. // see https://hackaday.io/project/5888-reverse-engineering-the-milight-on-air-protocol Serial.println(message.type); if (message.type == V_STATUS) { //Serial.println("triggered V_STATUS"); mlr.begin(); // Change light status Serial.println(message.getBool()); if ( message.getBool()) { Serial.println("here"); // Serial.println("triggered ON"); sendCommand (outgoingPacket_on, sizeof(outgoingPacket_on)); } else { // Serial.println("triggered off"); sendCommand(outgoingPacket_off, sizeof(outgoingPacket_off)); } _begin(); } if (message.type == V_VAR1) { // Serial.println("triggered V_VAR1"); incomingCommand = (char *)message.getCustom(); Serial.println((char *)message.getCustom()); mlr.begin(); Serial.println("#############"); for (int i=0; i<sizeof(outgoingPacket); i++) { outgoingPacket[i] = 16*char_to_uint8_t(incomingCommand[i*2]) + char_to_uint8_t(incomingCommand[i*2+1]); Serial.println(outgoingPacket[i]); } Serial.println("#############"); Serial.write(outgoingPacket, 7); sendCommand(outgoingPacket, sizeof(outgoingPacket)); _begin(); } //gw.begin(incomingMessage, NODE_ID, true); } void sendCommand(uint8_t mi_Command[7], int sizeofcommand) { for (int i = 0; i < mi_command_repeat; i++) { mlr.write(mi_Command, sizeofcommand); } } uint8_t char_to_uint8_t(char c) { uint8_t i; if (c <= '9') i = c - '0'; else if (c >= 'a') i = c - 'a' + 10; else i = c - 'A' + 10; return i; } -
@Jason-Brunk
unfortunately i havnt got my own milight bulbs but for what i've seen on the
reverse engineered protocol page the payload must be something like
"07B0F2EA359001B9ACF9" for all on or
"07B0F2EA7D910FD4EC72" for greenor the part "07B0F2EA" must be the ID so the payload
is somethink like "359001B9ACF9" for all on and
"7D910FD4EC72" for green -
@n1ck1355
sorry for the delay. Here is what I learned from https://hackaday.io/project/5888-reverse-engineering-the-milight-on-air-protocolBasically, the mi controller will receive text string and convert them into HEX format and send it to the bulb. The text string should be formatted as the following (+ added for easy of reading, no '+' in the actual command):
ID + color + brightness + button code + seq
The ID is the ID of the bulb to be controlled, it is six byte in ASCII but will be converted into 3 byte HEX before sending to the bulb.
color, brightness and button code are each 2 byte in ASCII and will be converted into 1 byte HEX and send to bulb.
Seq is 2 byte in ASCII but it appears that you can just use "00".To change color, you need to send a color code (e.g.: "00"=purple, "1B"=red, "40"=yellow,e tc) and using button code "OF".
To change back to white, you use "04" as color code and "13" as button code.The detailed button code definition can be found here:
https://cdn.hackaday.io/images/1224221432724803073.jpgHope this helps.
-
Thank you @ted :)
i already played with it and can turn the bulbs on/off. i will play around with your
information to make the other funktions work.But what i see is that you cannot e.g. dim the bulbs softly from say 100% to 20% cause
that would be more commands behind each other. But the node must reset itself after
each command by calling _Begin() and that takes some time..
any suggestions to resolve that? -
Thank you @ted :)
i already played with it and can turn the bulbs on/off. i will play around with your
information to make the other funktions work.But what i see is that you cannot e.g. dim the bulbs softly from say 100% to 20% cause
that would be more commands behind each other. But the node must reset itself after
each command by calling _Begin() and that takes some time..
any suggestions to resolve that? -
@n1ck1355
my only solution is to use two radios, one receives command from the gateway and the other sending command to the bulbs. it might be doable with just 1 arduino by using softSPI.@ted said:
@n1ck1355
my only solution is to use two radios, one receives command from the gateway and the other sending command to the bulbs. it might be doable with just 1 arduino by using softSPI.I don't see why you would need SoftSPI for that ? It should just need some change for CE and CSN pins for the NRF that is used to send data to the milights. I will try to find time to check that this week.
-
I just tried out openhab2, would it be easier controling the bulbs from openhab2 or do I still to do alot of "coding" on my own?
-
Hello, few months have passed and I finally had a look at the code from @Jason-Brunk
I made a MiLightBulb class with methods to set on/off, set brightness level, set color and set animation. It still needs improvements as brightness is not working, some colors are a bit off and I didn't test animation yet but it's starting to take shape and I can use it from RGB light control in domoticz.I have connected 2 nrf24 also, using pins 7&8 for the one sending MiLight messages instead of 9&10 and it running fine as expected, no use to call begin() all the time: much more reactive.
I'll publish the code as soon as I have time to finish and clean up. -
Great news @Nca78
-
any updates? I have a couple milight bulbs ready to test :)
-
any updates? I have a couple milight bulbs ready to test :)
@Jason-Brunk sorry I received my PCBs for Livolo switches so these will have my priority at the moment. And we're still in the lunar new year holidays here, not much time available.
-
Totally understand. That's another project I am interested in :)
-
Hi
I have read through this thread fully and the concept look great. I am confused as to the hardware that is required thought. I have a mysensors gateway connetcted to wifi and some sensors setup and working on Home Assistant. What do I need to build to implement this solution, and what would I have to install in HA.
Thanks for any help
Laurie -
Hello,
is this thread still alive ?
I am on a Raspberry Pi 3 an i have connected an nrf radio.PiGateway or PiGatewaySerial are both working and also openmilight_pi is compiled and ready.
My Problem is:
In the first post its said to send multiple On commands to the milight to pair it.
This shall work even without the original remote controller.But how ?
How to use the Gateway or openmilight to send a general on command ?
I cannot see it from the hackaday page. Everywhere the ID is needed. Which i dont have when using only Pi, nRF and a milight rgb box to controll a strip.Please can someone light me up ???
-
Hello,
is this thread still alive ?
I am on a Raspberry Pi 3 an i have connected an nrf radio.PiGateway or PiGatewaySerial are both working and also openmilight_pi is compiled and ready.
My Problem is:
In the first post its said to send multiple On commands to the milight to pair it.
This shall work even without the original remote controller.But how ?
How to use the Gateway or openmilight to send a general on command ?
I cannot see it from the hackaday page. Everywhere the ID is needed. Which i dont have when using only Pi, nRF and a milight rgb box to controll a strip.Please can someone light me up ???