Created
April 23, 2017 22:36
-
-
Save Br3nda/3f24ad0346c7d8f0ebfdbbdf55d72f31 to your computer and use it in GitHub Desktop.
This file contains 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
//#define MY_DEBUG | |
#define MY_RADIO_NRF24 | |
#define CHILD_ID_HVAC 10 | |
#define CHILD_ID_POWERFUL 0 | |
#include <MySensors.h> | |
#include <PanasonicCKPHeatpumpIR.h> | |
#include <PanasonicHeatpumpIR.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; | |
bool STRENGTH_STATE; | |
IRSenderPWM irSender(3); // IR led on Arduino digital pin 3, using Arduino PWM | |
HeatpumpIR *heatpumpIR = new PanasonicNKEHeatpumpIR(); | |
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); | |
MyMessage msgPowerful(CHILD_ID_POWERFUL, V_STATUS); | |
void presentation() { | |
sendSketchInfo("Heatpump", "2.1"); | |
present(CHILD_ID_HVAC, S_HVAC, "Thermostat"); | |
present(CHILD_ID_POWERFUL, S_BINARY); | |
send(msgHVACFlowState.set("Off")); | |
send(msgHVACSetPointC.set(22)); | |
send(msgHVACSpeed.set("Max")); | |
} | |
void setup() { | |
// put your setup code here, to run once: | |
} | |
void loop() { | |
// put your main code here, to run repeatedly: | |
} | |
void receive(const MyMessage &message) { | |
if (message.isAck()) { | |
Serial.println("This is an ack from gateway"); | |
return; | |
} | |
Serial.print("Incoming change for sensor:"); | |
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 = 0; | |
else if(recvData.equalsIgnoreCase("min")) FAN_STATE = 1; | |
else if(recvData.equalsIgnoreCase("normal")) FAN_STATE = 2; | |
else if(recvData.equalsIgnoreCase("max")) FAN_STATE = 3; | |
sendHeatpumpCommand(); | |
send(msgHVACSpeed.set(recvData)); | |
break; | |
case V_HVAC_SETPOINT_COOL: | |
Serial.println("V_HVAC_SETPOINT_COOL"); | |
TEMP_STATE = message.getFloat(); | |
Serial.println(TEMP_STATE); | |
sendHeatpumpCommand(); | |
send(msgHVACSetPointC.set(TEMP_STATE)); | |
break; | |
case V_HVAC_FLOW_STATE: | |
Serial.println("V_HVAC_FLOW_STATE"); | |
if (recvData.equalsIgnoreCase("coolon")) { | |
POWER_STATE = 1; | |
MODE_STATE = MODE_COOL; | |
} | |
else if (recvData.equalsIgnoreCase("heaton")) { | |
POWER_STATE = 1; | |
MODE_STATE = MODE_HEAT; | |
} | |
else if (recvData.equalsIgnoreCase("autochangeover")) { | |
POWER_STATE = 1; | |
MODE_STATE = MODE_AUTO; | |
} | |
else if (recvData.equalsIgnoreCase("off")){ | |
POWER_STATE = 0; | |
} | |
sendHeatpumpCommand(); | |
send(msgHVACFlowState.set(recvData)); | |
break; | |
} | |
} | |
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); | |
boolean powerful; boolean quiet; | |
if (STRENGTH_STATE) { | |
powerful = true; | |
quiet = false; | |
} else { | |
powerful= false; | |
quiet = true; | |
} | |
heatpumpIR->send(irSender, POWER_STATE, MODE_STATE, FAN_STATE, TEMP_STATE, VDIR_AUTO, HDIR_AUTO); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment