Heatpump Sketch Help



  • Hi,

    I need some help converting the Heatpump sketch example to 2.0 and also isolating to just the Mitsubishi model as i have no need or memory for all the models.... i guess my biggest issue is where in the sketch is the model actually defined?

    Link to sketch that i need converting below:

    https://www.mysensors.org/build/heatpump

    Cheers
    Scott


  • Hardware Contributor

    @SGi - check this out: https://forum.mysensors.org/topic/4276/converting-a-sketch-from-1-5-x-to-2-0-x

    In the sketch it looks like you just define which you want to use:
    Just remove/erase the ones you dont want.

    #include <FujitsuHeatpumpIR.h>
    #include <PanasonicCKPHeatpumpIR.h>
    #include <PanasonicHeatpumpIR.h>
    #include <CarrierHeatpumpIR.h>
    #include <MideaHeatpumpIR.h>
    #include <MitsubishiHeatpumpIR.h>
    #include <SamsungHeatpumpIR.h>
    #include <SharpHeatpumpIR.h>
    #include <DaikinHeatpumpIR.h>```


  • Ok, i have managed to get a heatpump IR sketch working somewhat. I can see the node in 'hardware' and even the children but they do not appear in 'devices'... is there something fundamentally wrong in my sketch?

    I am using Domoticz and a RPI controller.

    0_1485842430447_upload-0a99d4c1-0ede-4128-a926-481cb0270315

    // Enable debug prints to serial monitor
    #define MY_DEBUG
    
    // Enable and select radio type attached
    #define MY_RADIO_NRF24
    
    #include <SPI.h>
    #include <MySensors.h>
    
    #include <MitsubishiHeatpumpIR.h>
    
    #define POWER_ID 0
    #define MODE_ID 1
    #define FAN_ID 2
    #define TEMP_ID 3
    #define VDIR_ID 4
    #define HDIR_ID 5
    
    MyMessage powerMsg(POWER_ID, V_STATUS); 
    MyMessage modeMsg(MODE_ID, V_HVAC_FLOW_STATE);
    MyMessage fanMsg(FAN_ID, V_PERCENTAGE);
    MyMessage tempMsg(TEMP_ID, V_TEMP);
    MyMessage vdirMsg(VDIR_ID, V_VAR1); 
    MyMessage hdirMsg(HDIR_ID, V_VAR2); 
    
    IRSenderPWM irSender(3);       // IR led on Arduino digital pin 3, using Arduino PWM
    
    HeatpumpIR *heatpumpIR = new MitsubishiFDHeatpumpIR();
    
    //Some global variables to hold the states
    int POWER_STATE;
    int TEMP_STATE;
    int FAN_STATE;
    int MODE_STATE;
    
    void setup()  
    {  
      // begin(incomingMessage, AUTO, false);
    }
      
    void presentation()  
    {     
      // Send the sketch version information to the gateway and Controller
      sendSketchInfo("Heatpump", "1.0");
    
      // Register all sensors to gw (they will be created as child devices)
      present(POWER_ID, S_BINARY);
      present(MODE_ID, S_HVAC);
      present(FAN_ID, S_HVAC);
      present(TEMP_ID, S_HVAC);
      present(VDIR_ID, S_CUSTOM);
      present(HDIR_ID, S_CUSTOM);
         
      // Load our values on start
      POWER_STATE = loadState(POWER_ID);
      TEMP_STATE = loadState(TEMP_ID);
      FAN_STATE = loadState(FAN_ID);
      MODE_STATE = loadState(MODE_ID);
      
      sendHeatpumpCommand();
    }
    
    void loop() {
    
    } 
    
    void handlePowerMessage(bool newState) {
      if (newState) {
        POWER_STATE = POWER_ON;
      }
      else {
        POWER_STATE = POWER_OFF;
      }
      saveState(POWER_ID, newState);
    }
    
    void handleModeMessge(int newMode) {
      switch(newMode) {    
        case 0:
          MODE_STATE = MODE_HEAT; break;
        case 1:
          MODE_STATE = MODE_COOL; break;
        case 2:
          MODE_STATE = MODE_AUTO; break;
        case 3:
          MODE_STATE = MODE_FAN; break;
         case 4:
          MODE_STATE = MODE_DRY; break;
      }
      MODE_STATE = newMode;
      saveState(MODE_ID, newMode);
    }
    
    void handleFanMessage(int newFan) {
      if (newFan > 5) newFan=5;
      switch(newFan) {
        case 0:
          FAN_STATE = FAN_AUTO; break;
        case 1:
          FAN_STATE = FAN_1; break;
        case 2:
          FAN_STATE = FAN_2; break;
        case 3:
          FAN_STATE = FAN_3; break;
        case 4:
          FAN_STATE = FAN_4; break;
        case 5:
          FAN_STATE = FAN_5; break;
        default:
          FAN_STATE = FAN_AUTO; break;
      }
      FAN_STATE = newFan;
      saveState(FAN_ID, newFan);
    }
    
    void handleTempMessage(int newTemp) {
      TEMP_STATE = newTemp;
      saveState(TEMP_ID, newTemp);
    }
    
    void sendHeatpumpCommand() {
      Serial.println("Power = " + (String)POWER_STATE);
      Serial.println("Mode = " + (String)MODE_STATE);
      Serial.println("Fan = " + (String)FAN_STATE);
      Serial.println("Temp = " + (String)TEMP_STATE);
      heatpumpIR->send(irSender, POWER_STATE, MODE_STATE, FAN_STATE, TEMP_STATE, VDIR_AUTO, HDIR_AUTO);
    }
    void incomingMessage(const MyMessage &message) {
      // We only expect one type of message from controller. But we better check anyway.
      if (message.isAck()) {
         Serial.println("This is an ack from gateway");
      }
       Serial.print("Incoming change for sensor:");
       Serial.print(message.sensor);
       Serial.print(", New status: ");
       Serial.println(message.getBool());
    
       switch(message.sensor) {
        case POWER_ID: {
          bool newState = message.getBool();
          handlePowerMessage(newState);
          break;
        }
        case MODE_ID: {
          int newMode = message.getInt();
          handleModeMessge(newMode);
          break;
        }
        case FAN_ID: {
          int newFan = message.getInt();
          handleFanMessage(newFan);
          break;
        }
        case TEMP_ID: {
          int newTemp = message.getInt();
          handleTempMessage(newTemp);
          break;
        }
       }
      sendHeatpumpCommand();
    }
    

  • Hardware Contributor

    @SGi - you will not see any device before first value is sent. Make sure you send status or something on startup.



  • @sundberg84 Ok thanks, i thought the following part of the code in Presentation() was doing that?

    // Load our values on start
      POWER_STATE = loadState(POWER_ID);
      TEMP_STATE = loadState(TEMP_ID);
      FAN_STATE = loadState(FAN_ID);
      MODE_STATE = loadState(MODE_ID);
      
      sendHeatpumpCommand();```

  • Hardware Contributor

    @SGi - not sure, but I think that is load the saved state from EEPROM.
    You should have some sort of send(value);



  • I can see the topic is quite old but myabe a complete sensor 2.1 example?
    I can see that this code for openhab is quite popular. But i'm facing an issue constructing the proper MQTT topic
    As on my set up all my control messages look like

          topic: "mys-in/41/2/1/0/2"
          payload: "0"
    

    So wonder which ones to use with this sketch?


Log in to reply
 

Suggested Topics

  • 1
  • 2
  • 2
  • 2
  • 10
  • 3

1
Online

11.2k
Users

11.1k
Topics

112.5k
Posts