Skip to content

Commit eb560a8

Browse files
Br3ndaLandrash
authored andcommitted
Update HVAC example to MySensors 2 (home-assistant#2517)
* Add example arduino sketch for MySensors 2.x HVAC * Send mysensor HVAC status back to gateway on each change
1 parent 4b095fa commit eb560a8

File tree

1 file changed

+138
-1
lines changed

1 file changed

+138
-1
lines changed

source/_components/climate.mysensors.markdown

Lines changed: 138 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,144 @@ You can use V_TEMP to send the current temperature from the node to Home Assista
4242

4343
For more information, visit the [serial api] of MySensors.
4444

45-
### {% linkable_title Example sketch %}
45+
### {% linkable_title Example sketch for MySensors 2.x %}
46+
47+
48+
```cpp
49+
/*
50+
* Documentation: http://www.mysensors.org
51+
* Support Forum: http://forum.mysensors.org
52+
*/
53+
54+
#define MY_RADIO_NRF24
55+
#define CHILD_ID_HVAC 0
56+
57+
#include <MySensors.h>
58+
59+
// Uncomment your heatpump model
60+
//#include <FujitsuHeatpumpIR.h>
61+
//#include <PanasonicCKPHeatpumpIR.h>
62+
//#include <PanasonicHeatpumpIR.h>
63+
//#include <CarrierHeatpumpIR.h>
64+
//#include <MideaHeatpumpIR.h>
65+
//#include <MitsubishiHeatpumpIR.h>
66+
//#include <SamsungHeatpumpIR.h>
67+
//#include <SharpHeatpumpIR.h>
68+
//#include <DaikinHeatpumpIR.h>
69+
70+
//Some global variables to hold the states
71+
int POWER_STATE;
72+
int TEMP_STATE;
73+
int FAN_STATE;
74+
int MODE_STATE;
75+
int VDIR_STATE;
76+
int HDIR_STATE;
77+
78+
IRSenderPWM irSender(3); // IR led on Arduino digital pin 3, using Arduino PWM
79+
80+
//Change to your Heatpump
81+
HeatpumpIR *heatpumpIR = new PanasonicNKEHeatpumpIR();
82+
83+
/*
84+
new PanasonicDKEHeatpumpIR()
85+
new PanasonicJKEHeatpumpIR()
86+
new PanasonicNKEHeatpumpIR()
87+
new CarrierHeatpumpIR()
88+
new MideaHeatpumpIR()
89+
new FujitsuHeatpumpIR()
90+
new MitsubishiFDHeatpumpIR()
91+
new MitsubishiFEHeatpumpIR()
92+
new SamsungHeatpumpIR()
93+
new SharpHeatpumpIR()
94+
new DaikinHeatpumpIR()
95+
*/
96+
97+
MyMessage msgHVACSetPointC(CHILD_ID_HVAC, V_HVAC_SETPOINT_COOL);
98+
MyMessage msgHVACSpeed(CHILD_ID_HVAC, V_HVAC_SPEED);
99+
MyMessage msgHVACFlowState(CHILD_ID_HVAC, V_HVAC_FLOW_STATE);
100+
101+
void presentation() {
102+
sendSketchInfo("Heatpump", "2.1");
103+
present(CHILD_ID_HVAC, S_HVAC, "Thermostat");
104+
}
105+
106+
void setup() {
107+
}
108+
109+
void loop() {
110+
// put your main code here, to run repeatedly:
111+
}
112+
113+
void receive(const MyMessage &message) {
114+
if (message.isAck()) {
115+
Serial.println("This is an ack from gateway");
116+
return;
117+
}
118+
119+
Serial.print("Incoming message for: ");
120+
Serial.print(message.sensor);
121+
122+
String recvData = message.data;
123+
recvData.trim();
124+
125+
Serial.print(", New status: ");
126+
Serial.println(recvData);
127+
switch (message.type) {
128+
case V_HVAC_SPEED:
129+
Serial.println("V_HVAC_SPEED");
130+
131+
if(recvData.equalsIgnoreCase("auto")) FAN_STATE = 0;
132+
else if(recvData.equalsIgnoreCase("min")) FAN_STATE = 1;
133+
else if(recvData.equalsIgnoreCase("normal")) FAN_STATE = 2;
134+
else if(recvData.equalsIgnoreCase("max")) FAN_STATE = 3;
135+
break;
136+
137+
case V_HVAC_SETPOINT_COOL:
138+
Serial.println("V_HVAC_SETPOINT_COOL");
139+
TEMP_STATE = message.getFloat();
140+
Serial.println(TEMP_STATE);
141+
break;
142+
143+
case V_HVAC_FLOW_STATE:
144+
Serial.println("V_HVAC_FLOW_STATE");
145+
if (recvData.equalsIgnoreCase("coolon")) {
146+
POWER_STATE = 1;
147+
MODE_STATE = MODE_COOL;
148+
}
149+
else if (recvData.equalsIgnoreCase("heaton")) {
150+
POWER_STATE = 1;
151+
MODE_STATE = MODE_HEAT;
152+
}
153+
else if (recvData.equalsIgnoreCase("autochangeover")) {
154+
POWER_STATE = 1;
155+
MODE_STATE = MODE_AUTO;
156+
}
157+
else if (recvData.equalsIgnoreCase("off")){
158+
POWER_STATE = 0;
159+
}
160+
break;
161+
}
162+
sendHeatpumpCommand();
163+
sendNewStateToGateway();
164+
}
165+
166+
void sendNewStateToGateway() {
167+
send(msgHVACSetPointC.set(TEMP_STATE));
168+
send(msgHVACSpeed.set(FAN_STATE));
169+
send(msgHVACFlowState.set(MODE_STATE));
170+
}
171+
172+
void sendHeatpumpCommand() {
173+
Serial.println("Power = " + (String)POWER_STATE);
174+
Serial.println("Mode = " + (String)MODE_STATE);
175+
Serial.println("Fan = " + (String)FAN_STATE);
176+
Serial.println("Temp = " + (String)TEMP_STATE);
177+
178+
heatpumpIR->send(irSender, POWER_STATE, MODE_STATE, FAN_STATE, TEMP_STATE, VDIR_AUTO, HDIR_AUTO);
179+
}
180+
```
181+
182+
### {% linkable_title Example sketch for MySensors 1.x %}
46183
47184
```cpp
48185
/*

0 commit comments

Comments
 (0)