IR message from HA to mysensors arduino node. How?

Hi,

I just can’t figure out how the IR send should work in HA with MySensors. The example here is made for old version of the mysensors and does not help much.

I made a switch to mysensors and set it’s value for HA to register. But I dont understand how I’m supposed to send the IR codes from HA. And how does HA know where to send the code? I get nothing in my receive function at arduino. It should at least print the “New message”

This is how I called the service
Service: switch.mysensors_send_ir_code
Json: { “entity_id”: “switch.ir_20_23”, “V_IR_SEND”:“0xC284”}

Arduino sketch. The actual IR code is not done as I tried first to get the communication working between the node and HA.

// Enable debug prints to serial monitor
#define MY_DEBUG

// Enable and select radio type attached
#define MY_RADIO_NRF24

#define MY_NODE_ID 20
#define CHILD_ID_RECEIVE 21
#define CHILD_ID_RECORD 22
#define CHILD_ID_SWITCH 23

#include <MyConfig.h>
#include <MySensors.h>
#include <IRremote.h>

MyMessage msgIrReceive(CHILD_ID_RECEIVE, V_IR_RECEIVE);
MyMessage msgIrRecord(CHILD_ID_RECORD, V_IR_RECORD); 
MyMessage msgSwitch(CHILD_ID_SWITCH, V_LIGHT); 

// Arduino pin to connect the IR receiver, button and normal led (status)
int RECV_PIN = 5;
int BUTTON_PIN = 4;
int STATUS_PIN = 2;

IRrecv irrecv(RECV_PIN);
IRsend irsend;
decode_results results;

// temporary workaround
boolean bootDone = false;

void presentation()
{
    // Send the sketch version information to the gateway and Controller
    sendSketchInfo("IR", "0.01");

    // Register all sensors to gateway (they will be created as child devices)
    present(CHILD_ID_RECEIVE, S_IR, "Receive IR");
    present(CHILD_ID_RECORD, S_IR, "Record IR");
    present(CHILD_ID_SWITCH, S_BINARY, "IR Switch");
}

void setup() 
{
    Serial.begin(9600);
    irrecv.enableIRIn(); // Start the receiver
    pinMode(BUTTON_PIN, INPUT);
    pinMode(STATUS_PIN, OUTPUT);


}


void loop() 
{
    if( bootDone == false )
    {    
        // Tell MYS Controller that we're NOT recording
        send(msgIrRecord.set(0));
        send(msgSwitch.set(0));
        delay(1000);
        send(msgSwitch.set(1));
        delay(1000);
        send(msgSwitch.set(0));  
              
        bootDone = true;

        
    }    
    wait(20);


}

// Message received functions from the central node
void receive(const MyMessage &message)
{
    Serial.print("New message: ");
    Serial.println(message.type);
    
    if (message.type == V_IR_RECORD) 
    { 
        // Tell MYS Controller that we're now in recording mode
        //send(msgIrRecord.set(1));
        
        Serial.print("Record new IR for: ");
    }
    
    if (message.type == V_IR_SEND) 
    {
        // Send an IR code from offset: paramvalue - no check for legal value
        Serial.print("Send IR preset: ");
        byte code = message.getByte();
        Serial.print(code);
    }
    
    // Start receiving ir again...
    irrecv.enableIRIn(); 
    
}

You have to send an initial value for each value type that you’re using. So send a value for V_IR_SEND in the loop in the bootDone block. I’m guessing the device hasn’t been added properly to home assistant due to this missing information.

You can check this by looking for the entity_id in the state tab under developer tools in the GUI.

Thanks Martin,

The trick seemed to be to select correct types for MyMessages (V_IR_SEND) and send the init values.

I can paste the code after some cleanup in case someone is interested using mysensors and IR with HA.

1 Like

I’m trying to do the same thing. Could you paste what you have? When trying to send an initial value for V_IR_SEND, I get:

Invalid values: {32: '0'}: switch platform: node 11 child 2: S_IR requires value_type V_STATUS @ data[2]

Also, have you tried recording using V_IR_RECORD? What service do you use to send the value?

Thanks!

Hi,

I stopped using this long time ago and not really develop it much. But here are the parts from the code it worked. I cant anymore remember what was the HA version. I was using the ethernet gateway from mysensors so that the radio was directly connected to Raspberry. Had to also use development branch of the gateway.

But the arduino code is the following:

// Enable debug prints to serial monitor
// #define MY_DEBUG

// Enable and select radio type attached
#define MY_RADIO_NRF24

#define MY_NODE_ID 20
#define CHILD_ID 24

#include <MyConfig.h>
#include <MySensors.h>
#include <IRremote.h>

MyMessage msgIrReceive(CHILD_ID, V_IR_RECEIVE);
MyMessage msgIrRecord(CHILD_ID, V_IR_SEND); 
MyMessage msgSwitch(CHILD_ID, V_LIGHT); 

// Arduino pin to connect the IR receiver, button and normal led (status)
int RECV_PIN = 5;
// int BUTTON_PIN = 4;
int STATUS_PIN = 2;
// int lastButtonState = digitalRead(BUTTON_PIN);

IRrecv irrecv(RECV_PIN);
IRsend irsend;
decode_results results;

// Storage for the recorded code
int codeType = -1; // The type of code
unsigned long codeValue; // The code value if not raw
unsigned int rawCodes[RAWBUF]; // The durations if raw
int codeLen; // The length of the code
int toggle = 0; // The RC5/6 toggle state

// Variable to track switch state.
// Set it to FALSE after some ms.
bool ir_switch = false;
unsigned long ir_switch_time = millis();

// temporary workaround
boolean bootDone = false;

void presentation()
{
    // Send the sketch version information to the gateway and Controller
    sendSketchInfo("IR", "0.11");

    // Register all sensors to gateway (they will be created as child devices)
    present(CHILD_ID, S_IR, "Make IR stuff");

}

void setup() 
{
    Serial.begin(115200);
    irrecv.enableIRIn(); // Start the receiver
    // pinMode(BUTTON_PIN, INPUT);
    pinMode(STATUS_PIN, OUTPUT);


}


void loop() 
{
    if( bootDone == false )
    {    
        char code[10] = "bootcode";
        
        send(msgSwitch.set(0));
        send(msgIrReceive.set(code));
        send(msgIrRecord.set(code));
        delay(1000);
        send(msgSwitch.set(1));
        send(msgIrReceive.set(code));
        send(msgIrRecord.set(code));
        delay(1000);
        send(msgSwitch.set(0));  
        send(msgIrReceive.set(code)); 
        send(msgIrRecord.set(code)); 
              
        bootDone = true;
        
        
    }    

    if (irrecv.decode(&results)) 
    {
        digitalWrite(STATUS_PIN, HIGH);
        storeCode(&results);
        irrecv.resume(); // resume receiver
        digitalWrite(STATUS_PIN, LOW);
    }

    // Turn off ir_switch (switch light entity at HA) after 
    // a delay to prevent accidental IR code sending.
    if( ir_switch_time + 2000 < millis() && ir_switch == true )
    {
        ir_switch = false;
        send(msgSwitch.set(0));

        // Re-enable receiver after transmitting some other signals
        irrecv.enableIRIn();
    }

}

// Message received functions from the central node
void receive(const MyMessage &message)
{
    // Serial.print("New message: ");
    // Serial.println(message.type);

    // Message received from the gateway
    if (message.type == V_IR_SEND) 
    {        
        // Serial.print("# Transmitting IR code for #");

        // Read u_long DEC value from received message
        // and compare to which manufacturer it belongs to
        unsigned long code = message.getULong();

        // LG codes
        if( code >> 16 == 0x20DF )
        {
            // Serial.print("LG: "); 
            // Serial.print(code);
            // Serial.print(", ");
            // Serial.println(code, HEX);

            // codeType, codeValue, codeLen
            prepareForSending(NEC, code, 32);
        }
        else if( code >> 16 == 0xE0E0 )
        {
            // Serial.print("SAMSUNG: "); 
            // Serial.print(code);
            // Serial.print(", ");
            // Serial.println(code, HEX);

            // codeType, codeValue, codeLen
            prepareForSending(SAMSUNG, code, 32);
        }
        else if( code >> 16 == 0xA55A )
        {
            // Serial.print("PIONEER: "); 
            // Serial.print(code);
            // Serial.print(", ");
            // Serial.println(code, HEX);

            // codeType, codeValue, codeLen
            prepareForSending(NEC, code, 32);
        }
        else
        {
            // Serial.println("Unkown code received");
        }
    }

    // 
    if (message.type == V_LIGHT) 
    {
        if (message.getBool()== 1)
        {
            // Serial.println("Switch -> HIGH");
            send(msgSwitch.set(1));
            ir_switch = true;
            ir_switch_time = millis();
        }
        else
        {
            // Serial.println("Switch -> LOW");
            send(msgSwitch.set(0));
            ir_switch = false;
        }
    }
    
}

// Stores the code for later playback
// Most of this code is just logging
void storeCode(decode_results *results) {
  codeType = results->decode_type;
  int count = results->rawlen;
  if (codeType == UNKNOWN) {
    // Serial.println("Received unknown code, saving as raw");
    codeLen = results->rawlen - 1;
    // To store raw codes:
    // Drop first value (gap)
    // Convert from ticks to microseconds
    // Tweak marks shorter, and spaces longer to cancel out IR receiver distortion
    for (int i = 1; i <= codeLen; i++) {
      if (i % 2) {
        // Mark
        rawCodes[i - 1] = results->rawbuf[i]*USECPERTICK - MARK_EXCESS;
        // Serial.print(" m");
      } 
      else {
        // Space
        rawCodes[i - 1] = results->rawbuf[i]*USECPERTICK + MARK_EXCESS;
        // Serial.print(" s");
      }
      // Serial.print(rawCodes[i - 1], DEC);
    }
    // Serial.println("");
  }
  else {
    if (codeType == NEC) {
      // Serial.print("Received NEC: ");
      if (results->value == REPEAT) {
        // Don't record a NEC repeat value as that's useless.
        // Serial.println("repeat; ignoring.");
        return;
      }
    } 
    else if (codeType == SONY) {
      // Serial.print("Received SONY: ");
    } 
    else if (codeType == PANASONIC) {
      // Serial.print("Received PANASONIC: ");
    }
    else if (codeType == JVC) {
      // Serial.print("Received JVC: ");
    }
    else if (codeType == RC5) {
      // Serial.print("Received RC5: ");
    } 
    else if (codeType == RC6) {
      // Serial.print("Received RC6: ");
    } 
    else if (codeType == SAMSUNG) {
      // Serial.print("Received SAMSUNG: ");
    } 
    else {
      // Serial.print("Unexpected codeType ");
      // Serial.print(codeType, DEC);
      // Serial.println("");
    }
    // Serial.println(results->value, HEX);
    codeValue = results->value;
    codeLen = results->bits;
    // Serial.print("CodeLen: "); // Serial.println(codeLen);


    // Send to gateway
    send(msgIrReceive.set(codeValue));
  }
}

void prepareForSending(int codetype,unsigned long codevalue, int codelen)
{
    codeType = codetype;
    codeValue = codevalue;
    codeLen = codelen;

    sendCode(0);
}

void sendCode(int repeat) {
  if (codeType == NEC) {
    if (repeat) {
      irsend.sendNEC(REPEAT, codeLen);
      // Serial.println("Sent NEC repeat");
    } 
    else {
      irsend.sendNEC(codeValue, codeLen);
      // Serial.print("Sent NEC ");
      // Serial.println(codeValue, HEX);
    }
  } 
  else if (codeType == SONY) {
    irsend.sendSony(codeValue, codeLen);
    // Serial.print("Sent Sony ");
    // Serial.println(codeValue, HEX);
  } 
  else if (codeType == PANASONIC) {
    irsend.sendPanasonic(codeValue, codeLen);
    // Serial.print("Sent Panasonic");
    // Serial.println(codeValue, HEX);
  }
  else if (codeType == JVC) {
    irsend.sendJVC(codeValue, codeLen, false);
    // Serial.print("Sent JVC");
    // Serial.println(codeValue, HEX);
  }
  else if (codeType == SAMSUNG) {
    irsend.sendSAMSUNG(codeValue, codeLen);
    // Serial.print("Sent SAMSUNG: ");
    // Serial.println(codeValue, HEX);
  }
  else if (codeType == RC5 || codeType == RC6) {
    if (!repeat) {
      // Flip the toggle bit for a new button press
      toggle = 1 - toggle;
    }
    // Put the toggle bit into the code to send
    codeValue = codeValue & ~(1 << (codeLen - 1));
    codeValue = codeValue | (toggle << (codeLen - 1));
    if (codeType == RC5) {
      // Serial.print("Sent RC5 ");
      // Serial.println(codeValue, HEX);
      irsend.sendRC5(codeValue, codeLen);
    } 
    else {
      irsend.sendRC6(codeValue, codeLen);
      // Serial.print("Sent RC6 ");
      // Serial.println(codeValue, HEX);
    }
  } 
  else if (codeType == UNKNOWN /* i.e. raw */) {
    // Assume 38 KHz
    irsend.sendRaw(rawCodes, codeLen, 38);
    // Serial.println("Sent raw");
  }
}

Some values I recorded and hard coded in HA automations:

#### LG, codelen = 32, codetype = NEC
POWER = 20DF10EF, 551489775


#### SAMSUNG, codelen = 32, codetype = SAMSUNG
POWER = E0E040BF, 3772793023
VOL_UP = E0E0E01F, 3772833823
VOL_DOWN = E0E0D02F, 3772829743
SOURCE = E0E0807F, 3772809343
HDMI = E0E0D12E, 3772829998
UP = E0E006F9, 3772778233
DOWN = E0E08679, 3772810873
ENTER = E0E016E9, 3772782313

RED = E0E036C9, 3772790473
GREEN = E0E028D7, 3772786903
YELLOW = E0E0A857, 3772819543
BLUE = E0E06897, 3772803223

STOP = E0E0629D, 3772801693
0 = E0E08877, 3772811383
1 = E0E020DF, 3772784863
2 = E0E0A05F, 3772817503
3 = E0E0609F, 3772801183
4 = E0E010EF, 3772780783
5 = E0E0906F, 3772813423
6 = E0E050AF, 3772797103
7 = E0E030CF, 3772788943
8 = E0E0B04F, 3772821583
9 = E0E0708F, 3772805263


#### PIONEER, codelen = 32, codetype = NEC
POWER = A55A38C7, 2774153415
VOL_UP = A55A50AF, 2774159535
VOL_DOWN = A55AD02F, 2774192175

Few automations I was running. The latter part changes light color when remote is pointed at the ir-arduino and it reports the received code through the gateway to HA. note that in some places I use HEX and other places DEC. I had some formatting issues and found this working and let it be.

Then the last part are the scripts mentioned in the code:

#####################################################################
### IR codes PIONEER
#####################################################################
pioneer_power:
  alias: IR Pioneer toggle power
  sequence:
  - service: switch.mysensors_send_ir_code
    entity_id: switch.ir_20_24
    data:
      V_IR_SEND: 2774153415

pioneer_vol_up:
  alias: IR Pioneer vol up
  sequence:
  - service: switch.mysensors_send_ir_code
    entity_id: switch.ir_20_24
    data:
      V_IR_SEND: 2774159535

pioneer_vol_down:
  alias: IR Pioneer vol down
  sequence:
  - service: switch.mysensors_send_ir_code
    entity_id: switch.ir_20_24
    data:
      V_IR_SEND: 2774192175

#####################################################################
### IR codes SAMSUNG
#####################################################################
samsung_power:
  alias: IR Samsung toggle power
  sequence:
  - service: switch.mysensors_send_ir_code
    entity_id: switch.ir_20_24
    data:
      V_IR_SEND: 3772793023

samsung_vol_up:
  alias: IR Samsung vol up
  sequence:
  - service: switch.mysensors_send_ir_code
    entity_id: switch.ir_20_24
    data:
      V_IR_SEND: 3772833823

samsung_vol_down:
  alias: IR Samsung vol down
  sequence:
  - service: switch.mysensors_send_ir_code
    entity_id: switch.ir_20_24
    data:
      V_IR_SEND: 3772829743

in the arduino code I shift bits to regognice what was the device sending the message. There are some more elegant methods and the code itself could be improved a lot. But worked just fine as long as I was using it :slight_smile:

Well, occasionally I lost the messages somewhere in the vortex and I did not come up with a good solution to change volume. If I would click fast (more than once per 1-2 seconds) my volume script in HA the actual behaviour was really bad performance.

Hope this helps you :slight_smile:

Hi All,

understand it is an old post. I am going to chance by asking for the clarification. i am building something very similar and have a Pioneer brand Amplifier.

I checked the IR code and it matches with the IR code mentioned in last post. I downloaded the code and program Arduino. to my surprise it works as intended so thanks for sharing it.

For POWER command, when I send A55A38C7 from HA, nothing happens but if send commands 2774153415 from HA ,it turns on the divide no issue so not sure how to convert A55A48B7 to 277XXXX number for mute commands.

For the the mute command, I am getting following raw data usring <IRremote.h> library.

13:21:21.992 -> unsigned int rawData[67] = {8450,4250, 550,1550, 500,500, 550,1550, 500,550, 500,500, 500,1600, 450,600, 450,1600, 500,550, 500,1550, 500,550, 500,1600, 450,1600, 500,550, 450,1600, 500,550, 500,550, 450,1600, 500,550, 500,550, 500,1550, 500,550, 500,550, 500,550, 450,1600, 500,550, 450,1600, 500,1600, 500,550, 450,1600, 500,1600, 450,1600, 550}; // NEC A55A48B7
13:21:22.368 -> unsigned int data = 0xA55A48B7`

thanks in advance for any pointer. appreciate it.

The arduino gives output as hexa and HA wants to use int format. Or that was how I had it working.

Use e.g. this to convert it https://www.rapidtables.com/convert/number/hex-to-decimal.html

A55A48B7 -> 2774157495

Thank you very much. I can confirm this is working and thanks for the link. Appreciate all your help

Hi @taikapanu,

I am posting another query here as I think this is relevant to the topic instead of creating a new post.

As I mentioned, the solution posted above works seamlessly. However, I tried the above solution with Panasonic remote N2QAYZ000002 Dvd play remote and for some reason, it is not accepting either hex or decimal value. There is no IR emitting signal if I run a script. I tried to run “IRsenddemo” code from IRlibrary, it is emitting signal from IR emitter using raw Data. For example for Power command, if i use the following, device turns on without issue.

16:46:35.483 -> unsigned int  rawData[99] = {3350,1700, 400,450, 450,1250, 400,450, 350,450, 450,400, 450,400, 400,450, 450,400, 400,450, 400,450, 400,450, 450,400, 350,500, 400,1250, 450,400, 400,450, 400,450, 450,400, 400,450, 400,450, 400,450, 350,1300, 400,450, 400,1300, 400,450, 400,450, 400,1300, 350,1350, 400,1250, 450,400, 400,450, 400,450, 400,1300, 400,450, 450,1250, 350,1300, 450,1250, 450,1250, 400,450, 400,450, 350,1300, 450,400, 450,400, 450,400, 450,400, 450,400, 400,450, 400,1300, 350}

Other thing i notice with Panasonic remote is that it emits different hex and rawdata if press again but it repeats itself. I tried all combination but cannot seem to make it works from HA.

I then tried to hardcode the rawDATA into the ardiuno, it seems to work with 3 rawDATA codes only. if i go beyond 4 to 5, it restarts ardunio everytime i tried to run the script and throwing low memory error during compiling.

// Message received functions from the central node
void receive(const MyMessage & message)
{
  // Serial.print("New message: ");
  // Serial.println(message.type);

 int khz = 38; // 38kHz carrier frequency for the NEC protocol
  unsigned int irSignalP[] = {3350,1700, 400,450, 450,1250, 400,450, 350,450, 450,400, 450,400, 400,450, 450,400, 400,450, 400,450, 400,450, 450,400, 350,500, 400,1250, 450,400, 400,450, 400,450, 450,400, 400,450, 400,450, 400,450, 350,1300, 400,450, 400,1300, 400,450, 400,450, 400,1300, 350,1350, 400,1250, 450,400, 400,450, 400,450, 400,1300, 400,450, 450,1250, 350,1300, 450,1250, 450,1250, 400,450, 400,450, 350,1300, 450,400, 450,400, 450,400, 450,400, 450,400, 400,450, 400,1300, 350}; //AnalysIR Batch Export (IRremote) - RAW
  unsigned int irSignalvu[] = {3350,1700, 400,450, 400,1250, 450,400, 450,400, 400,450, 400,450, 400,450, 400,450, 400,450, 400,450, 400,400, 450,400, 450,400, 450,1250, 400,450, 400,450, 400,450, 400,450, 400,450, 400,400, 450,400, 450,1250, 450,400, 400,1300, 400,450, 400,450, 400,450, 400,400, 450,400, 450,400, 450,400, 400,450, 400,450, 400,450, 450,400, 400,450, 400,450, 350,1300, 450,400, 450,400, 400,450, 400,450, 400,450, 400,450, 400,450, 400,450, 400,400, 450,1250, 450}; //AnalysIR Batch Export (IRremote) - RAW
  //unsigned int irSignalvd[] = {3350,1650, 450,450, 400,1250, 400,500, 350,450, 400,450, 400,450, 400,450, 400,450, 400,450, 400,450, 400,450, 400,400, 400,500, 350,1300, 400,450, 400,450, 400,450, 400,400, 450,400, 450,450, 350,500, 350,1300, 400,450, 400,1300, 400,450, 400,450, 400,450, 400,450, 350,500, 350,450, 400,450, 450,400, 400,1300, 400,450, 400,450, 400,450, 400,400, 400,1350, 350,450, 400,450, 400,1300, 400,450, 400,400, 450,400, 450,450, 350,500, 350,450, 400,1300, 400}; //AnalysIR Batch Export (IRremote) - RAW
  unsigned int irSignalvm[] = {3350,1700, 400,450, 400,1250, 450,400, 400,450, 450,400, 400,450, 400,450, 400,450, 400,450, 400,450, 350,500, 400,400, 450,400, 450,1250, 400,450, 400,450, 400,450, 400,450, 400,450, 400,400, 400,450, 450,1250, 450,400, 400,1300, 400,450, 400,450, 400,450, 400,400, 450,400, 400,450, 400,450, 450,400, 400,450, 400,1300, 400,450, 400,450, 400,1250, 450,1250, 450,400, 400,450, 400,450, 400,1300, 350,500, 350,450, 450,1250, 450,400, 450,400, 400,1300, 400}; //AnalysIR Batch Export (IRremote) - RAW
  //unsigned int irSignalext[] = {3400,1650, 450,400, 450,1250, 450,400, 450,350, 450,400, 450,400, 450,400, 500,350, 450,400, 450,400, 450,400, 450,400, 450,400, 450,1200, 450,400, 450,400, 450,400, 450,400, 450,400, 450,400, 450,400, 450,1200, 450,400, 450,1250, 450,400, 450,400, 450,400, 450,400, 450,400, 450,400, 450,350, 450,400, 450,400, 450,1250, 450,400, 400,1300, 450,1200, 450,400, 450,400, 450,1250, 450,400, 450,1250, 400,450, 450,1200, 450,1250, 450,1250, 450,400, 450,400, 450}; //AnalysIR Batch Export (IRremote) - RAW
  
  // Message received from the gateway
  if (message.type == V_IR_SEND)
  {
    // Serial.print("# Transmitting IR code for #");

    // Read u_long DEC value from received message
    // and compare to which manufacturer it belongs to
    unsigned long code = message.getULong();

    // LG codes
    if ( code == 1 )
    {
      // Serial.print("LG: ");
      // Serial.print(code);
      // Serial.print(", ");
      // Serial.println(code, HEX);

      irsend.sendRaw(irSignalP, sizeof(irSignalP) / sizeof(irSignalP[0]), khz); //Note the approach used to automatically calculate the size of the array.
    }
    else if ( code == 2 )
    {
      // Serial.print("SAMSUNG: ");
      // Serial.print(code);
      // Serial.print(", ");
      // Serial.println(code, HEX);

      // codeType, codeValue, codeLen
      irsend.sendRaw(irSignalvm, sizeof(irSignalvm) / sizeof(irSignalvm[0]), khz); //Note the approach used to automatically calculate the size of the array.
    }
//    else if ( code == 3 )
//    {
//      // Serial.print("PIONEER: ");
//      // Serial.print(code);
//      // Serial.print(", ");
//      // Serial.println(code, HEX);
//
//      // codeType, codeValue, codeLen
//      irsend.sendRaw(irSignalvd, sizeof(irSignalvd) / sizeof(irSignalvd[0]), khz); //Note the approach used to automatically calculate the size of the array.
//    }
    else if ( code == 4 )
    {
      // Serial.print("PIONEER: ");
      // Serial.print(code);
      // Serial.print(", ");
      // Serial.println(code, HEX);

      // codeType, codeValue, codeLen
      irsend.sendRaw(irSignalvu, sizeof(irSignalvu) / sizeof(irSignalvu[0]), khz); //Note the approach used to automatically calculate the size of the array.
    }
//    else if ( code == 5 )
//    {
//      // Serial.print("PIONEER: ");
//      // Serial.print(code);
//      // Serial.print(", ");
//      // Serial.println(code, HEX);
//
//      // codeType, codeValue, codeLen
//      irsend.sendRaw(irSignalext, sizeof(irSignalext) / sizeof(irSignalext[0]), khz); //Note the approach used to automatically calculate the size of the array.
//    }
   
  }

  //
  if (message.type == V_LIGHT)
  {
    if (message.getBool() == 1)
    {
      // Serial.println("Switch -> HIGH");
      send(msgSwitch.set(1));
      ir_switch = true;
      ir_switch_time = millis();
    }
    else
    {
      // Serial.println("Switch -> LOW");
      send(msgSwitch.set(0));
      ir_switch = false;
    }
  }

Just checking if anyone have experienced similar issue and how to go about addressing it. appreciate any help in this regard.

Thanks

You need to send the panasonic IR codes with the specific command for that (in the arduino). Won’t work with NEC for example.

I don’t have Panasonic devices so I have taken it out from the function “void receive(const MyMessage &message)”.

There is this part for sending out Panasonic specific codes.

  else if (codeType == PANASONIC) {
    irsend.sendPanasonic(codeValue, codeLen);
    // Serial.print("Sent Panasonic");
    // Serial.println(codeValue, HEX);
  }

The IR libraries work differently, some send the message multiple times, some send “repeat last command” signals etc, they are different. From HA it is impossible to have this, must be implemented on the Arduino side (to e.g. repeat the codes).
HA will then only trigger these functions on Arduino side.

I haven’t had this node running for years but hopefully this guides you a bit to right direction :slight_smile:

Thanks for the reply. I modified the code as advised and got the emitter to emit a signal via HA script. previously it was not emitting the signal. however, by doing this it emits the signal but not turning the device.
To troubleshoot, I modified basic IRlibrary code to use HEX, decimal and rawDATA. to confirm, Panasonic device is only responding to rawData. it does not response to any decimal and HEX value I tried sending.

here is my code I used

#include <IRremote.h>

IRsend irsend;

void setup()
{
  Serial.begin(115200);
}

void loop() {

  int khz = 38; // 38kHz carrier frequency for the NEC protocol
  unsigned int irSignal[] = {3350,1700, 400,450, 450,1250, 400,450, 350,450, 450,400, 450,400, 400,450, 450,400, 400,450, 400,450, 400,450, 450,400, 350,500, 400,1250, 450,400, 400,450, 400,450, 450,400, 400,450, 400,450, 400,450, 350,1300, 400,450, 400,1300, 400,450, 400,450, 400,1300, 350,1350, 400,1250, 450,400, 400,450, 400,450, 400,1300, 400,450, 450,1250, 350,1300, 450,1250, 450,1250, 400,450, 400,450, 350,1300, 450,400, 450,400, 450,400, 450,400, 450,400, 400,450, 400,1300, 350}; //AnalysIR Batch Export (IRremote) - RAW
 
  Serial.println("HEX code");
  irsend.sendPanasonic(0xF0921D6, 32);
  delay(5000); //5 second delay between each signal burst
  Serial.println("Decimal code");
  irsend.sendNEC(252256726, 32); //0xD5AD0B51
  delay(5000); //5 second delay between each signal burstSerial.println("RAW code");
  Serial.println("RAW code");
  irsend.sendRaw(irSignal, sizeof(irSignal) / sizeof(irSignal[0]), khz); //Note the approach used to automatically calculate the size of the array.
  delay(5000); //5 second delay between each signal burst


}

Any other suggestions please?

I don’t know for a fancy solution but if you have only few panasonic codes you want to use, hardcode them in the arduino. Then from HA send something simple e.g. 1, 2, 3 etc of which each corresponds to one hardcoded raw code.

Have the logic in the arduino to decide what raw code goes out when receiving simple short number from HA.

yes, this is what i did yesterday so guess need to go with hardcoding … not a pretty solution but works for my need :slight_smile: … thanks for your time and input… appreciate it.