Created
March 24, 2018 08:35
-
-
Save joshmcarthur/08ef4c30c4576421a79d819a6fd22cf5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Documentation: http://www.mysensors.org | |
* Support Forum: http://forum.mysensors.org | |
*/ | |
#define MY_RADIO_NRF24 | |
#define CHILD_ID_HVAC 10 | |
#define MY_DEBUG | |
#include <MySensors.h> | |
#include <IRremote2.h> | |
//Some global variables to hold the states | |
int POWER_STATE; | |
int TEMP_STATE; | |
int FAN_STATE; | |
int MODE_STATE; | |
int VDIR_STATE; | |
int HDIR_STATE; | |
IRsend irsend; | |
MyMessage msgHVACSetPointC(CHILD_ID_HVAC, V_HVAC_SETPOINT_COOL); | |
MyMessage msgHVACSpeed(CHILD_ID_HVAC, V_HVAC_SPEED); | |
MyMessage msgHVACFlowState(CHILD_ID_HVAC, V_HVAC_FLOW_STATE); | |
bool initialValueSent = false; | |
void presentation() { | |
sendSketchInfo("Heatpump", "2.2"); | |
present(CHILD_ID_HVAC, S_HVAC, "Thermostat"); | |
} | |
void setup() { | |
Serial.begin(115200); | |
Serial.println("Ready"); | |
} | |
void loop() { | |
// put your main code here, to run repeatedly: | |
if (!initialValueSent) { | |
send(msgHVACSetPointC.set(21)); | |
send(msgHVACSpeed.set("Auto")); | |
send(msgHVACFlowState.set("Off")); | |
initialValueSent = true; | |
} | |
} | |
void receive(const MyMessage &message) { | |
if (message.isAck()) { | |
Serial.println("This is an ack from gateway"); | |
return; | |
} | |
Serial.print("Incoming message for: "); | |
Serial.print(message.sensor); | |
String recvData = message.data; | |
recvData.trim(); | |
Serial.print(", New status: "); | |
Serial.println(recvData); | |
switch (message.type) { | |
case V_HVAC_SPEED: | |
Serial.println("V_HVAC_SPEED"); | |
if(recvData.equalsIgnoreCase("auto")) FAN_STATE = FAN_SPEED_AUTO; | |
else if(recvData.equalsIgnoreCase("min")) FAN_STATE = FAN_SPEED_1; | |
else if(recvData.equalsIgnoreCase("normal")) FAN_STATE = FAN_SPEED_3; | |
else if(recvData.equalsIgnoreCase("max")) FAN_STATE = FAN_SPEED_5; | |
break; | |
case V_HVAC_SETPOINT_COOL: | |
Serial.println("V_HVAC_SETPOINT_COOL"); | |
TEMP_STATE = message.getFloat(); | |
Serial.println(TEMP_STATE); | |
break; | |
case V_HVAC_FLOW_STATE: | |
Serial.println("V_HVAC_FLOW_STATE"); | |
if (recvData.equalsIgnoreCase("coolon")) { | |
POWER_STATE = 1; | |
MODE_STATE = HVAC_COLD; | |
} | |
else if (recvData.equalsIgnoreCase("heaton")) { | |
POWER_STATE = 1; | |
MODE_STATE = HVAC_HOT; | |
} | |
else if (recvData.equalsIgnoreCase("autochangeover")) { | |
POWER_STATE = 1; | |
MODE_STATE = HVAC_HOT; | |
} | |
else if (recvData.equalsIgnoreCase("off")){ | |
POWER_STATE = 0; | |
} | |
break; | |
} | |
sendHeatpumpCommand(); | |
sendNewStateToGateway(); | |
} | |
void sendNewStateToGateway() { | |
send(msgHVACSetPointC.set(TEMP_STATE)); | |
send(msgHVACSpeed.set(FAN_STATE)); | |
send(msgHVACFlowState.set(MODE_STATE)); | |
} | |
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); | |
irsend.sendHvacMitsubishi(MODE_STATE, TEMP_STATE, FAN_STATE, VANNE_AUTO_MOVE, POWER_STATE); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment