
// Process commands received from X10 compatible IR remote
void infraredEvent(char house, byte unit, byte command, bool isRepeat)
{

  //Show Status IR icon
  sendCommand("p0.pic=54");
  sendCommand("tm1.en=1");

#ifdef DEBUG
  Serial.println("!! IR Received !!");
#endif
  if (!isRepeat)
  {
#ifdef DEBUG
    Serial.println(command);
#endif
    // Handle Address Command (House + Unit)
    if (command == CMD_ADDRESS)
    {
#ifdef DEBUG
      Serial.println("cmd == CMD_ADDRESS");
      Serial.println(house);
      Serial.println(unit);
      Serial.println(command);
#endif
      if (unit <= 16)
      {
#ifdef DEBUG
        Serial.println("Switch...");
#endif
        ir_code = unit;
      }
    }
  }
}


void ir_action()
{

#ifdef DEBUG
      Serial.println("Ir_code == ");
      Serial.println(ir_code);
#endif


        if (ir_code == 1)  //Staandelamp
          if(main_btn_staandelamp==0)
            domoticz_send_nvalue(idx_staandelamp, 1);
          else
            domoticz_send_nvalue(idx_staandelamp, 0);
          
        if (ir_code == 2)  //Haard
          if(main_btn_haardverlichting==0)
            domoticz_send_nvalue(idx_haardverlichting, 1);
          else
            domoticz_send_nvalue(idx_haardverlichting, 0);
          
       if (ir_code == 4)  //Rooster
          if(main_btn_rooster==0)
            domoticz_send_nvalue(idx_rooster, 1);
          else
            domoticz_send_nvalue(idx_rooster, 0);
        
        if (ir_code == 5)  //Hanglamp
          if(main_btn_hanglamp==0)
            domoticz_send_nvalue(idx_hanglamp, 1);
          else
            domoticz_send_nvalue(idx_hanglamp, 0);
          
        if (ir_code == 3)  //Tuin
           if(main_btn_tuinverlichting==0)
            domoticz_send_nvalue(idx_tuinverlichting, 1);
          else
            domoticz_send_nvalue(idx_tuinverlichting, 0);

        if (ir_code == 6)  //Kaarsen
          if(main_btn_ir06==0)
            domoticz_send_nvalue(idx_ir06, 1);
          else
            domoticz_send_nvalue(idx_ir06, 0);

        if (ir_code == 7)
          if(main_btn_ir07 == 0)
            domoticz_send_nvalue(idx_ir07, 1);
          else
            domoticz_send_nvalue(idx_ir07, 0);
              
        if (ir_code == 8)
          if(main_btn_ir08 == 0)
            domoticz_send_nvalue(idx_ir08, 1);
          else
            domoticz_send_nvalue(idx_ir08, 0);

        if (ir_code == 9)
          if(main_btn_ir09 == 0)
            domoticz_send_nvalue(idx_ir09, 1);
          else
            domoticz_send_nvalue(idx_ir09, 0);

        if (ir_code == 10)
          if(main_btn_ir10 == 0)
            domoticz_send_nvalue(idx_ir10, 1);
          else
            domoticz_send_nvalue(idx_ir10, 0);

    ir_code = 0;
#ifdef DEBUG
      Serial.println("Ir_code set to 0 ");
#endif


  
}
