MySensors Library & Examples  2.3.2
MockMySensors.ino
1 /*
2  * The MySensors Arduino library handles the wireless radio link and protocol
3  * between your home built sensors/actuators and HA controller of choice.
4  * The sensors forms a self healing radio network with optional repeaters. Each
5  * repeater and gateway builds a routing tables in EEPROM which keeps track of the
6  * network topology allowing messages to be routed to nodes.
7  *
8  * Created by Henrik Ekblad <[email protected]>
9  * Copyright (C) 2013-2019 Sensnology AB
10  * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors
11  *
12  * Documentation: http://www.mysensors.org
13  * Support Forum: http://forum.mysensors.org
14  *
15  * This program is free software; you can redistribute it and/or
16  * modify it under the terms of the GNU General Public License
17  * version 2 as published by the Free Software Foundation.
18  *
19  *******************************
20  *
21  * REVISION HISTORY
22  * Version 1.0 - Barduino 2015, GizMoCuz 2015
23  *
24  * DESCRIPTION
25  * This sketch is intended to create fake sensors which register and respond to the controller
26  *
27  */
28 
29 // Enable debug prints to serial monitor
30 #define MY_DEBUG
31 
32 // Enable and select radio type attached
33 #define MY_RADIO_RF24
34 //#define MY_RADIO_NRF5_ESB
35 //#define MY_RADIO_RFM69
36 //#define MY_RADIO_RFM95
37 
38 #define MY_NODE_ID 254
39 
40 #include <MySensors.h>
41 
42 #define RADIO_ERROR_LED_PIN 4 // Error led pin
43 #define RADIO_RX_LED_PIN 6 // Receive led pin
44 #define RADIO_TX_LED_PIN 5 // the PCB, on board LED
45 
46 // Wait times
47 #define LONG_WAIT 500
48 #define SHORT_WAIT 50
49 
50 #define SKETCH_NAME "MockMySensors "
51 #define SKETCH_VERSION "v0.5"
52 
53 // Define Sensors ids
54 /* S_DOOR, S_MOTION, S_SMOKE, S_LIGHT, S_DIMMER, S_COVER, S_TEMP, S_HUM, S_BARO, S_WIND,
55  S_RAIN, S_UV, S_WEIGHT, S_POWER, S_HEATER, S_DISTANCE, S_LIGHT_LEVEL, S_ARDUINO_NODE,
56  S_ARDUINO_REPEATER_NODE, S_LOCK, S_IR, S_WATER, S_AIR_QUALITY, S_CUSTOM, S_DUST,
57  S_SCENE_CONTROLLER
58 */
59 
62 
63 
64 // Some of these ID's have not been updated for v1.5. Uncommenting too many of them
65 // will make the sketch too large for a pro mini's memory so it's probably best to try
66 // one at a time.
67 
68 #define ID_S_ARMED 0 // dummy to control armed stated for several sensors
69 #define ID_S_DOOR 1
70 //#define ID_S_MOTION 2
71 //#define ID_S_SMOKE 3
72 //#define ID_S_LIGHT 4
73 //#define ID_S_DIMMER 5
74 //#define ID_S_COVER 6
75 //#define ID_S_TEMP 7
76 //#define ID_S_HUM 8
77 //#define ID_S_BARO 9
78 //#define ID_S_WIND 10
79 //#define ID_S_RAIN 11
80 //#define ID_S_UV 12
81 //#define ID_S_WEIGHT 13
82 //#define ID_S_POWER 14
83 //#define ID_S_HEATER 15
84 //#define ID_S_DISTANCE 16
85 //#define ID_S_LIGHT_LEVEL 17
86 //#define ID_S_LOCK 18
87 //#define ID_S_IR 19
88 //#define ID_S_WATER 20
89 //#define ID_S_AIR_QUALITY 21
90 //#define ID_S_DUST 22
91 //#define ID_S_SCENE_CONTROLLER 23
93 //#define ID_S_RGB_LIGHT 24
94 //#define ID_S_RGBW_LIGHT 25
95 //#define ID_S_COLOR_SENSOR 26
96 //#define ID_S_HVAC 27
97 //#define ID_S_MULTIMETER 28
98 //#define ID_S_SPRINKLER 29
99 //#define ID_S_WATER_LEAK 30
100 //#define ID_S_SOUND 31
101 //#define ID_S_VIBRATION 32
102 //#define ID_S_MOISTURE 33
103 //
104 //#define ID_S_CUSTOM 99
105 
106 
107 
108 // Global Vars
109 uint32_t SLEEP_TIME = 900000; // Sleep time between reads (in milliseconds)
110 bool metric = true;
111 long randNumber;
112 
113 
114 //Instantiate Messages objects
115 
116 #ifdef ID_S_ARMED
117 bool isArmed;
118 #endif
119 
120 #ifdef ID_S_DOOR // V_TRIPPED, V_ARMED
121 MyMessage msg_S_DOOR_T(ID_S_DOOR,V_TRIPPED);
122 MyMessage msg_S_DOOR_A(ID_S_DOOR,V_ARMED);
123 #endif
124 
125 #ifdef ID_S_MOTION // V_TRIPPED, V_ARMED
126 MyMessage msg_S_MOTION_A(ID_S_MOTION,V_ARMED);
127 MyMessage msg_S_MOTION_T(ID_S_MOTION,V_TRIPPED);
128 #endif
129 
130 #ifdef ID_S_SMOKE // V_TRIPPED, V_ARMED
131 MyMessage msg_S_SMOKE_T(ID_S_SMOKE,V_TRIPPED);
132 MyMessage msg_S_SMOKE_A(ID_S_SMOKE,V_ARMED);
133 #endif
134 
135 #ifdef ID_S_LIGHT
136 MyMessage msg_S_LIGHT(ID_S_LIGHT,V_LIGHT);
137 bool isLightOn=0;
138 #endif
139 
140 #ifdef ID_S_DIMMER
141 MyMessage msg_S_DIMMER(ID_S_DIMMER,V_DIMMER);
142 int dimmerVal=100;
143 #endif
144 
145 #ifdef ID_S_COVER
146 MyMessage msg_S_COVER_U(ID_S_COVER,V_UP);
147 MyMessage msg_S_COVER_D(ID_S_COVER,V_DOWN);
148 MyMessage msg_S_COVER_S(ID_S_COVER,V_STOP);
149 MyMessage msg_S_COVER_V(ID_S_COVER,V_VAR1);
150 int coverState=0; //0=Stop; 1=up; -1=down
151 #endif
152 
153 #ifdef ID_S_TEMP
154 MyMessage msg_S_TEMP(ID_S_TEMP,V_TEMP);
155 #endif
156 
157 #ifdef ID_S_HUM
158 MyMessage msg_S_HUM(ID_S_HUM,V_HUM);
159 #endif
160 
161 #ifdef ID_S_BARO
162 MyMessage msg_S_BARO_P(ID_S_BARO,V_PRESSURE);
163 MyMessage msg_S_BARO_F(ID_S_BARO,V_FORECAST);
164 #endif
165 
166 #ifdef ID_S_WIND
167 MyMessage msg_S_WIND_S(ID_S_WIND,V_WIND);
168 MyMessage msg_S_WIND_G(ID_S_WIND,V_GUST);
169 MyMessage msg_S_WIND_D(ID_S_WIND,V_DIRECTION);
170 #endif
171 
172 #ifdef ID_S_RAIN
173 MyMessage msg_S_RAIN_A(ID_S_RAIN,V_RAIN);
174 MyMessage msg_S_RAIN_R(ID_S_RAIN,V_RAINRATE);
175 #endif
176 
177 #ifdef ID_S_UV
178 MyMessage msg_S_UV(ID_S_UV,V_UV);
179 #endif
180 
181 #ifdef ID_S_WEIGHT
182 MyMessage msg_S_WEIGHT(ID_S_WEIGHT,V_WEIGHT);
183 #endif
184 
185 #ifdef ID_S_POWER
186 MyMessage msg_S_POWER_W(ID_S_POWER,V_WATT);
187 MyMessage msg_S_POWER_K(ID_S_POWER,V_KWH);
188 #endif
189 
190 
191 #ifdef ID_S_HEATER
192 
194 
195 MyMessage msg_S_HEATER_SET_POINT(ID_S_HEATER,
196  V_HVAC_SETPOINT_HEAT); // HVAC/Heater setpoint (Integer between 0-100). S_HEATER, S_HVAC
197 MyMessage msg_S_HEATER_FLOW_STATE(ID_S_HEATER,
198  V_HVAC_FLOW_STATE); // Mode of header. One of "Off", "HeatOn", "CoolOn", or "AutoChangeOver" // S_HVAC, S_HEATER
199 
200 //MyMessage msg_S_HEATER_STATUS(ID_S_HEATER,V_STATUS);
201 //MyMessage msg_S_HEATER_TEMP(ID_S_HEATER,V_TEMP);
202 
203 float heater_setpoint=21.5;
204 String heater_flow_state="Off";
205 
206 // float heater_temp=23.5;
207 // bool heater_status=false;
208 
209 
210 // V_TEMP // Temperature
211 // V_STATUS // Binary status. 0=off 1=on
212 // V_HVAC_FLOW_STATE // Mode of header. One of "Off", "HeatOn", "CoolOn", or "AutoChangeOver"
213 // V_HVAC_SPEED // HVAC/Heater fan speed ("Min", "Normal", "Max", "Auto")
214 // V_HVAC_SETPOINT_HEAT // HVAC/Heater setpoint
215 #endif
216 
217 #ifdef ID_S_DISTANCE
218 MyMessage msg_S_DISTANCE(ID_S_DISTANCE,V_DISTANCE);
219 #endif
220 
221 #ifdef ID_S_LIGHT_LEVEL
222 MyMessage msg_S_LIGHT_LEVEL(ID_S_LIGHT_LEVEL,V_LIGHT_LEVEL);
223 #endif
224 
225 #ifdef ID_S_LOCK
226 MyMessage msg_S_LOCK(ID_S_LOCK,V_LOCK_STATUS);
227 bool isLocked = 0;
228 #endif
229 
230 #ifdef ID_S_IR
231 MyMessage msg_S_IR_S(ID_S_IR,V_IR_SEND);
232 MyMessage msg_S_IR_R(ID_S_IR,V_IR_RECEIVE);
233 long irVal = 0;
234 #endif
235 
236 #ifdef ID_S_WATER
237 MyMessage msg_S_WATER_F(ID_S_WATER,V_FLOW);
238 MyMessage msg_S_WATER_V(ID_S_WATER,V_VOLUME);
239 #endif
240 
241 #ifdef ID_S_AIR_QUALITY
242 MyMessage msg_S_AIR_QUALITY(ID_S_AIR_QUALITY,V_LEVEL);
243 #endif
244 
245 #ifdef ID_S_DUST
246 MyMessage msg_S_DUST(ID_S_DUST,V_LEVEL);
247 #endif
248 
249 #ifdef ID_S_SCENE_CONTROLLER
250 MyMessage msg_S_SCENE_CONTROLLER_ON(ID_S_SCENE_CONTROLLER,V_SCENE_ON);
251 MyMessage msg_S_SCENE_CONTROLLER_OF(ID_S_SCENE_CONTROLLER,V_SCENE_OFF);
252 // not sure if scene controller sends int or chars
253 // betting on ints as Touch Display Scen by Hek // compiler warnings
254 char *scenes[] = {
255  (char *)"Good Morning",
256  (char *)"Clean Up!",
257  (char *)"All Lights Off",
258  (char *)"Music On/Off"
259 };
260 
261 int sceneVal=0;
262 int sceneValPrevious=0;
263 
264 #endif
265 
266 #ifdef ID_S_RGB_LIGHT
267 MyMessage msg_S_RGB_LIGHT_V_RGB(ID_S_RGB_LIGHT,V_RGB);
268 MyMessage msg_S_RGB_LIGHT_V_WATT(ID_S_RGB_LIGHT,V_WATT);
269 String rgbState="000000";
270 //RGB light V_RGB, V_WATT
271 //RGB value transmitted as ASCII hex string (I.e "ff0000" for red)
272 #endif
273 
274 #ifdef ID_S_RGBW_LIGHT
275 MyMessage msg_S_RGBW_LIGHT_V_RGBW(ID_S_RGBW_LIGHT,V_RGBW);
276 MyMessage msg_S_RGBW_LIGHT_V_WATT(ID_S_RGBW_LIGHT,V_WATT);
277 String rgbwState="00000000";
278 //RGBW light (with separate white component) V_RGBW, V_WATT
279 //RGBW value transmitted as ASCII hex string (I.e "ff0000ff" for red + full white) S_RGBW_LIGHT
280 #endif
281 
282 #ifdef ID_S_COLOR_SENSOR
283 MyMessage msg_S_COLOR_SENSOR_V_RGB(ID_S_COLOR_SENSOR,V_RGB);
284 //Color sensor V_RGB
285 //RGB value transmitted as ASCII hex string (I.e "ff0000" for red) S_RGB_LIGHT, S_COLOR_SENSOR
286 #endif
287 
288 #ifdef ID_S_HVAC
289 MyMessage msg_S_HVAC_V_HVAC_SETPOINT_HEAT(ID_S_HVAC,V_HVAC_SETPOINT_HEAT);
290 MyMessage msg_S_HVAC_V_HVAC_SETPOINT_COOL(ID_S_HVAC,V_HVAC_SETPOINT_COOL);
291 MyMessage msg_S_HVAC_V_HVAC_FLOW_STATET(ID_S_HVAC,V_HVAC_FLOW_STATE);
292 MyMessage msg_S_HVAC_V_HVAC_FLOW_MODE(ID_S_HVAC,V_HVAC_FLOW_MODE);
293 MyMessage msg_S_HVAC_V_HVAC_SPEED(ID_S_HVAC,V_HVAC_SPEED);
294 
295 float hvac_SetPointHeat = 16.5;
296 float hvac_SetPointCool = 25.5;
297 String hvac_FlowState = "AutoChangeOver";
298 String hvac_FlowMode = "Auto";
299 String hvac_Speed = "Normal";
300 
301 //Thermostat/HVAC device
302 //V_HVAC_SETPOINT_HEAT, // HVAC/Heater setpoint
303 //V_HVAC_SETPOINT_COOL, // HVAC cold setpoint
304 //V_HVAC_FLOW_STATE, // Mode of header. One of "Off", "HeatOn", "CoolOn", or "AutoChangeOver"
305 //V_HVAC_FLOW_MODE, // Flow mode for HVAC ("Auto", "ContinuousOn", "PeriodicOn")
306 //V_HVAC_SPEED // HVAC/Heater fan speed ("Min", "Normal", "Max", "Auto")
307 
308 // NOT IMPLEMENTED YET
309 //V_TEMP // Temperature
310 //V_STATUS // Binary status. 0=off 1=on
311 #endif
312 
313 #ifdef ID_S_MULTIMETER
314 MyMessage msg_S_MULTIMETER_V_IMPEDANCE(ID_S_MULTIMETER,V_IMPEDANCE);
315 MyMessage msg_S_MULTIMETER_V_VOLTAGE(ID_S_MULTIMETER,V_VOLTAGE);
316 MyMessage msg_S_MULTIMETER_V_CURRENT(ID_S_MULTIMETER,V_CURRENT);
317 
318 // Multimeter device V_VOLTAGE, V_CURRENT, V_IMPEDANCE
319 // V_IMPEDANCE 14 Impedance value
320 // V_VOLTAGE 38 Voltage level
321 // V_CURRENT 39 Current level
322 #endif
323 
324 #ifdef ID_S_SPRINKLER
325 // S_SPRINKLER 31 Sprinkler device V_STATUS (turn on/off), V_TRIPPED (if fire detecting device)
326 // V_STATUS 2 Binary status. 0=off 1=on
327 // V_ARMED 15 Armed status of a security sensor. 1=Armed, 0=Bypassed
328 // V_TRIPPED 16 Tripped status of a security sensor. 1=Tripped, 0=Untripped
329 #endif
330 
331 #ifdef ID_S_WATER_LEAK
332 #endif
333 #ifdef ID_S_SOUND
334 #endif
335 #ifdef ID_S_VIBRATION
336 #endif
337 #ifdef ID_S_MOISTURE
338 #endif
339 
340 #ifdef ID_S_MOISTURE
341 MyMessage msg_S_MOISTURE(ID_S_MOISTURE,V_LEVEL);
342 #endif
343 
344 #ifdef ID_S_CUSTOM
345 MyMessage msg_S_CUSTOM_1(ID_S_CUSTOM,V_VAR1);
346 MyMessage msg_S_CUSTOM_2(ID_S_CUSTOM,V_VAR2);
347 MyMessage msg_S_CUSTOM_3(ID_S_CUSTOM,V_VAR3);
348 MyMessage msg_S_CUSTOM_4(ID_S_CUSTOM,V_VAR4);
349 MyMessage msg_S_CUSTOM_5(ID_S_CUSTOM,V_VAR5);
350 #endif
351 
352 
353 
354 
355 void setup()
356 {
357  // Random SEED
358  randomSeed(analogRead(0));
359 
360  wait(LONG_WAIT);
361  Serial.println("GW Started");
362 }
363 
365 {
366  // Send the Sketch Version Information to the Gateway
367  Serial.print("Send Sketch Info: ");
368  sendSketchInfo(SKETCH_NAME, SKETCH_VERSION);
369  Serial.print(SKETCH_NAME);
370  Serial.println(SKETCH_VERSION);
371  wait(LONG_WAIT);
372 
373  // Get controller configuration
374  Serial.print("Get Config: ");
375  metric = getControllerConfig().isMetric;
376  Serial.println(metric ? "Metric":"Imperial");
377  wait(LONG_WAIT);
378 
379  // Init Armed
380 #ifdef ID_S_ARMED
381  isArmed = true;
382 #endif
383 
384  // Register all sensors to gw (they will be created as child devices)
385  Serial.println("Presenting Nodes");
386  Serial.println("________________");
387 
388 #ifdef ID_S_DOOR
389  Serial.println(" S_DOOR");
390  present(ID_S_DOOR,S_DOOR,"Outside Door");
391  wait(SHORT_WAIT);
392 #endif
393 
394 #ifdef ID_S_MOTION
395  Serial.println(" S_MOTION");
396  present(ID_S_MOTION,S_MOTION,"Outside Motion");
397  wait(SHORT_WAIT);
398 #endif
399 
400 #ifdef ID_S_SMOKE
401  Serial.println(" S_SMOKE");
402  present(ID_S_SMOKE,S_SMOKE,"Kitchen Smoke");
403  wait(SHORT_WAIT);
404 #endif
405 
406 #ifdef ID_S_LIGHT
407  Serial.println(" S_LIGHT");
408  present(ID_S_LIGHT,S_LIGHT,"Hall Light");
409  wait(SHORT_WAIT);
410 #endif
411 
412 #ifdef ID_S_DIMMER
413  Serial.println(" S_DIMMER");
414  present(ID_S_DIMMER,S_DIMMER,"Living room dimmer");
415  wait(SHORT_WAIT);
416 #endif
417 
418 #ifdef ID_S_COVER
419  Serial.println(" S_COVER");
420  present(ID_S_COVER,S_COVER,"Window cover");
421  wait(SHORT_WAIT);
422 #endif
423 
424 #ifdef ID_S_TEMP
425  Serial.println(" S_TEMP");
426  present(ID_S_TEMP,S_TEMP,"House Temperarue");
427  wait(SHORT_WAIT);
428 #endif
429 
430 #ifdef ID_S_HUM
431  Serial.println(" S_HUM");
432  present(ID_S_HUM,S_HUM,"Current Humidity");
433  wait(SHORT_WAIT);
434 #endif
435 
436 #ifdef ID_S_BARO
437  Serial.println(" S_BARO");
438  present(ID_S_BARO,S_BARO," Air pressure");
439  wait(SHORT_WAIT);
440 #endif
441 
442 #ifdef ID_S_WIND
443  Serial.println(" S_WIND");
444  present(ID_S_WIND,S_WIND,"Wind Station");
445  wait(SHORT_WAIT);
446 #endif
447 
448 #ifdef ID_S_RAIN
449  Serial.println(" S_RAIN");
450  present(ID_S_RAIN,S_RAIN,"Rain Station");
451  wait(SHORT_WAIT);
452 #endif
453 
454 #ifdef ID_S_UV
455  Serial.println(" S_UV");
456  present(ID_S_UV,S_UV,"Ultra Violet");
457  wait(SHORT_WAIT);
458 #endif
459 
460 #ifdef ID_S_WEIGHT
461  Serial.println(" S_WEIGHT");
462  present(ID_S_WEIGHT,S_WEIGHT,"Outdoor Scale");
463  wait(SHORT_WAIT);
464 #endif
465 
466 #ifdef ID_S_POWER
467  Serial.println(" S_POWER");
468  present(ID_S_POWER,S_POWER,"Power Metric");
469  wait(SHORT_WAIT);
470 #endif
471 
472 #ifdef ID_S_HEATER
473  Serial.println(" S_HEATER");
474  present(ID_S_HEATER,S_HEATER,"Garage Heater");
475  wait(SHORT_WAIT);
476 #endif
477 
478 #ifdef ID_S_DISTANCE
479  Serial.println(" S_DISTANCE");
480  present(ID_S_DISTANCE,S_DISTANCE,"Distance Measure");
481  wait(SHORT_WAIT);
482 #endif
483 
484 #ifdef ID_S_LIGHT_LEVEL
485  Serial.println(" S_LIGHT_LEVEL");
486  present(ID_S_LIGHT_LEVEL,S_LIGHT_LEVEL,"Outside Light Level");
487  wait(SHORT_WAIT);
488 #endif
489 
490 #ifdef ID_S_LOCK
491  Serial.println(" S_LOCK");
492  present(ID_S_LOCK,S_LOCK,"Front Door Lock");
493  wait(SHORT_WAIT);
494 #endif
495 
496 #ifdef ID_S_IR
497  Serial.println(" S_IR");
498  present(ID_S_IR,S_IR,"Univeral Command");
499  wait(SHORT_WAIT);
500 #endif
501 
502 #ifdef ID_S_WATER
503  Serial.println(" S_WATER");
504  present(ID_S_WATER,S_WATER,"Water Level");
505  wait(SHORT_WAIT);
506 #endif
507 
508 #ifdef ID_S_AIR_QUALITY
509  Serial.println(" S_AIR_QUALITY");
510  present(ID_S_AIR_QUALITY,S_AIR_QUALITY,"Air Station");
511  wait(SHORT_WAIT);
512 #endif
513 
514 #ifdef ID_S_DUST
515  Serial.println(" S_DUST");
516  present(ID_S_DUST,S_DUST,"Dust Level");
517  wait(SHORT_WAIT);
518 #endif
519 
520 #ifdef ID_S_SCENE_CONTROLLER
521  Serial.println(" S_SCENE_CONTROLLER");
522  present(ID_S_SCENE_CONTROLLER,S_SCENE_CONTROLLER,"Scene Controller");
523  wait(SHORT_WAIT);
524 #endif
525 
526 #ifdef ID_S_RGB_LIGHT
527  Serial.println(" RGB_LIGHT");
528  present(ID_S_RGB_LIGHT,S_RGB_LIGHT,"Mood Light");
529  wait(SHORT_WAIT);
530 #endif
531 
532 #ifdef ID_S_RGBW_LIGHT
533  Serial.println(" RGBW_LIGHT");
534  present(ID_S_RGBW_LIGHT,S_RGBW_LIGHT,"Mood Light 2");
535  wait(SHORT_WAIT);
536 #endif
537 
538 #ifdef ID_S_COLOR_SENSOR
539  Serial.println(" COLOR_SENSOR");
540  present(ID_S_COLOR_SENSOR,S_COLOR_SENSOR,"Hall Painting");
541  wait(SHORT_WAIT);
542 #endif
543 
544 #ifdef ID_S_HVAC
545  Serial.println(" HVAC");
546  present(ID_S_HVAC,S_HVAC,"HVAC");
547  wait(SHORT_WAIT);
548 #endif
549 
550 #ifdef ID_S_MULTIMETER
551  Serial.println(" MULTIMETER");
552  present(ID_S_MULTIMETER,S_MULTIMETER,"Electric Staion");
553  wait(SHORT_WAIT);
554 #endif
555 
556 #ifdef ID_S_SPRINKLER
557 #endif
558 #ifdef ID_S_WATER_LEAK
559 #endif
560 #ifdef ID_S_SOUND
561 #endif
562 #ifdef ID_S_VIBRATION
563 #endif
564 #ifdef ID_S_MOISTURE
565 #endif
566 
567 #ifdef ID_S_MOISTURE
568  Serial.println(" S_MOISTURE");
569  present(ID_S_MOISTURE,S_MOISTURE,"Basement Sensor");
570  wait(SHORT_WAIT);
571 #endif
572 
573 #ifdef ID_S_CUSTOM
574  Serial.println(" S_CUSTOM");
575  present(ID_S_CUSTOM,S_CUSTOM,"Other Stuff");
576  wait(SHORT_WAIT);
577 #endif
578 
579 
580 
581  Serial.println("________________");
582 
583 }
584 
585 void loop()
586 {
587  Serial.println("");
588  Serial.println("");
589  Serial.println("");
590  Serial.println("#########################");
591  randNumber=random(0,101);
592 
593  Serial.print("RandomNumber:");
594  Serial.println(randNumber);
595  // Send fake battery level
596  Serial.println("Send Battery Level");
597  sendBatteryLevel(randNumber);
598  wait(LONG_WAIT);
599 
600  // Request time
601  Serial.println("Request Time");
602  requestTime();
603  wait(LONG_WAIT);
604 
605  //Read Sensors
606 #ifdef ID_S_DOOR
607  door();
608 #endif
609 
610 #ifdef ID_S_MOTION
611  motion();
612 #endif
613 
614 #ifdef ID_S_SMOKE
615  smoke();
616 #endif
617 
618 #ifdef ID_S_LIGHT
619  light();
620 #endif
621 
622 #ifdef ID_S_DIMMER
623  dimmer();
624 #endif
625 
626 #ifdef ID_S_COVER
627  cover();
628 #endif
629 
630 #ifdef ID_S_TEMP
631  temp();
632 #endif
633 
634 #ifdef ID_S_HUM
635  hum();
636 #endif
637 
638 #ifdef ID_S_BARO
639  baro();
640 #endif
641 
642 #ifdef ID_S_WIND
643  wind();
644 #endif
645 
646 #ifdef ID_S_RAIN
647  rain();
648 #endif
649 
650 #ifdef ID_S_UV
651  uv();
652 #endif
653 
654 #ifdef ID_S_WEIGHT
655  weight();
656 #endif
657 
658 #ifdef ID_S_POWER
659  power();
660 #endif
661 
662 #ifdef ID_S_HEATER
663  heater();
664 #endif
665 
666 #ifdef ID_S_DISTANCE
667  distance();
668 #endif
669 
670 #ifdef ID_S_LIGHT_LEVEL
671  light_level();
672 #endif
673 
674 #ifdef ID_S_LOCK
675  lock();
676 #endif
677 
678 #ifdef ID_S_IR
679  ir();
680 #endif
681 
682 #ifdef ID_S_WATER
683  water();
684 #endif
685 
686 #ifdef ID_S_AIR_QUALITY
687  air();
688 #endif
689 
690 #ifdef ID_S_DUST
691  dust();
692 #endif
693 
694 #ifdef ID_S_SCENE_CONTROLLER
695  scene();
696 #endif
697 
698 #ifdef ID_S_RGB_LIGHT
699  rgbLight();
700 #endif
701 
702 #ifdef ID_S_RGBW_LIGHT
703  rgbwLight();
704 #endif
705 
706 #ifdef ID_S_COLOR_SENSOR
707  color();
708 #endif
709 
710 #ifdef ID_S_HVAC
711  hvac();
712 #endif
713 
714 #ifdef ID_S_MULTIMETER
715  multimeter();
716 #endif
717 
718 #ifdef ID_S_SPRINKLER
719 #endif
720 #ifdef ID_S_WATER_LEAK
721 #endif
722 #ifdef ID_S_SOUND
723 #endif
724 #ifdef ID_S_VIBRATION
725 #endif
726 #ifdef ID_S_MOISTURE
727 #endif
728 
729 #ifdef ID_S_MOISTURE
730  moisture();
731 #endif
732 
733 #ifdef ID_S_CUSTOM
734  custom();
735 #endif
736 
737  sendBatteryLevel(randNumber);
738  wait(SHORT_WAIT);
739  Serial.println("#########################");
740  wait(SLEEP_TIME); //sleep a bit
741 }
742 
743 // This is called when a new time value was received
744 void receiveTime(uint32_t controllerTime)
745 {
746 
747  Serial.print("Time value received: ");
748  Serial.println(controllerTime);
749 
750 }
751 
752 //void door(){}
753 
754 #ifdef ID_S_DOOR
755 void door()
756 {
757 
758  Serial.print("Door is: " );
759 
760  if (randNumber <= 50) {
761  Serial.println("Open");
762  send(msg_S_DOOR_T.set((int16_t)1));
763  } else {
764  Serial.println("Closed");
765  send(msg_S_DOOR_T.set((int16_t)0));
766  }
767 #ifdef ID_S_ARMED
768  Serial.print("System is: " );
769  Serial.println((isArmed ? "Armed":"Disarmed"));
770  send(msg_S_DOOR_A.set(isArmed));
771 #endif
772 }
773 #endif
774 
775 #ifdef ID_S_MOTION
776 void motion()
777 {
778 
779  Serial.print("Motion is: " );
780 
781  if (randNumber <= 50) {
782  Serial.println("Active");
783  send(msg_S_MOTION_T.set(1));
784  } else {
785  Serial.println("Quiet");
786  send(msg_S_MOTION_T.set(0));
787  }
788 
789 #ifdef ID_S_ARMED
790  Serial.print("System is: " );
791  Serial.println((isArmed ? "Armed":"Disarmed"));
792  send(msg_S_MOTION_A.set(isArmed));
793 #endif
794 }
795 #endif
796 
797 #ifdef ID_S_SMOKE
798 void smoke()
799 {
800 
801  Serial.print("Smoke is: " );
802 
803  if (randNumber <= 50) {
804  Serial.println("Active");
805  send(msg_S_SMOKE_T.set(1));
806  } else {
807  Serial.println("Quiet");
808  send(msg_S_SMOKE_T.set(0));
809  }
810 
811 #ifdef ID_S_ARMED
812  Serial.print("System is: " );
813  Serial.println((isArmed ? "Armed":"Disarmed"));
814  send(msg_S_SMOKE_A.set(isArmed));
815 #endif
816 
817 }
818 #endif
819 
820 #ifdef ID_S_LIGHT
821 void light()
822 {
823 
824  Serial.print("Light is: " );
825  Serial.println((isLightOn ? "On":"Off"));
826 
827  send(msg_S_LIGHT.set(isLightOn));
828 
829 }
830 #endif
831 
832 #ifdef ID_S_DIMMER
833 void dimmer()
834 {
835 
836  Serial.print("Dimmer is set to: " );
837  Serial.println(dimmerVal);
838 
839  send(msg_S_DIMMER.set(dimmerVal));
840 
841 }
842 #endif
843 
844 #ifdef ID_S_COVER
845 void cover()
846 {
847 
848  Serial.print("Cover is : " );
849 
850  if (coverState == 1) {
851  Serial.println("Opening");
852  send(msg_S_COVER_U.set(1));
853  } else if (coverState == -1) {
854  Serial.println("Closing");
855  send(msg_S_COVER_D.set(0));
856  } else {
857  Serial.println("Idle");
858  send(msg_S_COVER_S.set(-1));
859  }
860  send(msg_S_COVER_V.set(coverState));
861 }
862 #endif
863 
864 #ifdef ID_S_TEMP
865 void temp()
866 {
867 
868  Serial.print("Temperature is: " );
869  Serial.println(map(randNumber,1,100,0,45));
870 
871  send(msg_S_TEMP.set(map(randNumber,1,100,0,45)));
872 
873 }
874 #endif
875 
876 #ifdef ID_S_HUM
877 void hum()
878 {
879 
880  Serial.print("Humidity is: " );
881  Serial.println(randNumber);
882 
883  send(msg_S_HUM.set(randNumber));
884 
885 }
886 #endif
887 
888 #ifdef ID_S_BARO
889 void baro()
890 {
891 
892  const char *weather[] = {"stable","sunny","cloudy","unstable","thunderstorm","unknown"};
893  long pressure = map(randNumber,1,100,870,1086);// hPa?
894  int forecast = map(randNumber,1,100,0,5);
895 
896  Serial.print("Atmospheric Pressure is: " );
897  Serial.println(pressure);
898  send(msg_S_BARO_P.set(pressure));
899 
900  Serial.print("Weather forecast: " );
901  Serial.println(weather[forecast]);
902  send(msg_S_BARO_F.set(weather[forecast]));
903 
904 }
905 #endif
906 
907 #ifdef ID_S_WIND
908 void wind()
909 {
910 
911  Serial.print("Wind Speed is: " );
912  Serial.println(randNumber);
913  send(msg_S_WIND_S.set(randNumber));
914 
915  Serial.print("Wind Gust is: " );
916  Serial.println(randNumber+10);
917  send(msg_S_WIND_G.set(randNumber+10));
918 
919  Serial.print("Wind Direction is: " );
920  Serial.println(map(randNumber,1,100,0,360));
921  send(msg_S_WIND_D.set(map(randNumber,1,100,0,360)));
922 
923 }
924 #endif
925 
926 #ifdef ID_S_RAIN
927 void rain()
928 {
929 
930  Serial.print("Rain amount is: " );
931  Serial.println(randNumber);
932 
933  send(msg_S_RAIN_A.set(randNumber));
934 
935  Serial.print("Rain rate is: " );
936  Serial.println(randNumber/60);
937 
938  send(msg_S_RAIN_R.set(randNumber/60,1));
939 
940 }
941 #endif
942 
943 #ifdef ID_S_UV
944 void uv()
945 {
946 
947  Serial.print("Ultra Violet level is: " );
948  Serial.println(map(randNumber,1,100,0,15));
949 
950  send(msg_S_UV.set(map(randNumber,1,100,0,15)));
951 
952 }
953 #endif
954 
955 #ifdef ID_S_WEIGHT
956 void weight()
957 {
958 
959  Serial.print("Weight is: " );
960  Serial.println(map(randNumber,1,100,0,150));
961 
962  send(msg_S_WEIGHT.set(map(randNumber,1,100,0,150)));
963 
964 }
965 #endif
966 
967 #ifdef ID_S_POWER
968 void power()
969 {
970 
971  Serial.print("Watt is: " );
972  Serial.println(map(randNumber,1,100,0,150));
973  send(msg_S_POWER_W.set(map(randNumber,1,100,0,150)));
974 
975  Serial.print("KWH is: " );
976  Serial.println(map(randNumber,1,100,0,150));
977  send(msg_S_POWER_K.set(map(randNumber,1,100,0,150)));
978 
979 }
980 #endif
981 
982 #ifdef ID_S_HEATER
983 void heater()
984 {
985  // float heater_setpoint=21.5;
986  // float heater_temp=23.5;
987  // bool heater_status=false;
988  // String heatState="Off";
989 
990  Serial.print("Heater flow state is: " );
991  Serial.println(heater_flow_state);
992  send(msg_S_HEATER_FLOW_STATE.set(heater_flow_state.c_str()));
993 
994  // Serial.print("Heater on/off is: " );
995  // Serial.println((heater_status==true)?"On":"Off");
996  // send(msg_S_HEATER_STATUS.set(heater_status));
997 
998  // Serial.print("Heater Temperature is: " );
999  // Serial.println(heater_temp,1);
1000  // send(msg_S_HEATER_TEMP.set(heater_temp,1));
1001 
1002  Serial.print("Heater Setpoint: " );
1003  Serial.println(heater_setpoint,1);
1004  send(msg_S_HEATER_SET_POINT.set(heater_setpoint,1));
1005 }
1006 #endif
1007 
1008 #ifdef ID_S_DISTANCE
1009 void distance()
1010 {
1011 
1012  Serial.print("Distance is: " );
1013  Serial.println(map(randNumber,1,100,0,150));
1014 
1015  send(msg_S_DISTANCE.set(map(randNumber,1,100,0,150)));
1016 
1017 }
1018 #endif
1019 
1020 #ifdef ID_S_LIGHT_LEVEL
1021 void light_level()
1022 {
1023 
1024  Serial.print("Light is: " );
1025  Serial.println(map(randNumber,1,100,0,150));
1026 
1027  send(msg_S_LIGHT_LEVEL.set(map(randNumber,1,100,0,150)));
1028 
1029 }
1030 #endif
1031 
1032 #ifdef ID_S_LOCK
1033 void lock()
1034 {
1035 
1036  Serial.print("Lock is: " );
1037  Serial.println((isLocked ? "Locked":"Unlocked"));
1038  send(msg_S_LOCK.set(isLocked));
1039 
1040 }
1041 #endif
1042 
1043 #ifdef ID_S_IR
1044 void ir()
1045 {
1046 
1047  Serial.print("Infrared is: " );
1048  Serial.println(irVal);
1049 
1050  send(msg_S_IR_S.set(irVal));
1051  send(msg_S_IR_R.set(irVal));
1052 
1053 }
1054 #endif
1055 
1056 #ifdef ID_S_WATER
1057 void water()
1058 {
1059 
1060  Serial.print("Water flow is: " );
1061  Serial.println(map(randNumber,1,100,0,150));
1062 
1063  send(msg_S_WATER_F.set(map(randNumber,1,100,0,150)));
1064 
1065  Serial.print("Water volume is: " );
1066  Serial.println(map(randNumber,1,100,0,150));
1067 
1068  send(msg_S_WATER_V.set(map(randNumber,1,100,0,150)));
1069 
1070 }
1071 #endif
1072 
1073 #ifdef ID_S_AIR_QUALITY
1074 void air()
1075 {
1076 
1077  Serial.print("Air Quality is: " );
1078  Serial.println(randNumber);
1079 
1080  send(msg_S_AIR_QUALITY.set(randNumber));
1081 
1082 }
1083 #endif
1084 
1085 #ifdef ID_S_DUST
1086 void dust()
1087 {
1088 
1089  Serial.print("Dust level is: " );
1090  Serial.println(randNumber);
1091 
1092  send(msg_S_DUST.set(randNumber));
1093 
1094 }
1095 #endif
1096 
1097 #ifdef ID_S_SCENE_CONTROLLER
1098 void scene()
1099 {
1100 
1101  Serial.print("Scene is: " );
1102  Serial.println(scenes[sceneVal]);
1103 
1104  if(sceneValPrevious != sceneVal) {
1105  send(msg_S_SCENE_CONTROLLER_OF.set(sceneValPrevious));
1106  send(msg_S_SCENE_CONTROLLER_ON.set(sceneVal));
1107  sceneValPrevious=sceneVal;
1108  }
1109 
1110 }
1111 #endif
1112 
1113 #ifdef ID_S_RGB_LIGHT
1114 void rgbLight()
1115 {
1116 
1117  Serial.print("RGB Light state is: " );
1118  Serial.println(rgbState);
1119  send(msg_S_RGB_LIGHT_V_RGB.set(rgbState.c_str()));
1120 
1121  Serial.print("RGB Light Watt is: " );
1122  Serial.println(map(randNumber,1,100,0,150));
1123  send(msg_S_RGB_LIGHT_V_WATT.set(map(randNumber,1,100,0,150)));
1124 
1125 }
1126 #endif
1127 
1128 #ifdef ID_S_RGBW_LIGHT
1129 void rgbwLight()
1130 {
1131 
1132  Serial.print("RGBW Light state is: " );
1133  Serial.println(rgbwState);
1134  send(msg_S_RGBW_LIGHT_V_RGBW.set(rgbwState.c_str()));
1135 
1136  Serial.print("RGBW Light Watt is: " );
1137  Serial.println(map(randNumber,1,100,0,150));
1138  send(msg_S_RGBW_LIGHT_V_WATT.set(map(randNumber,1,100,0,150)));
1139 
1140 }
1141 #endif
1142 
1143 #ifdef ID_S_COLOR_SENSOR
1144 void color()
1145 {
1146  String colorState;
1147 
1148  String red = String(random(0,256),HEX);
1149  String green = String(random(0,256),HEX);
1150  String blue = String(random(0,256),HEX);
1151 
1152  colorState=String(red + green + blue);
1153 
1154  Serial.print("Color state is: " );
1155  Serial.println(colorState);
1156  send(msg_S_COLOR_SENSOR_V_RGB.set(colorState.c_str()));
1157 
1158 }
1159 #endif
1160 
1161 #ifdef ID_S_HVAC
1162 void hvac()
1163 {
1164 
1165  // float hvac_SetPointHeat = 16.5;
1166  // float hvac_SetPointCool = 25.5;
1167  // String hvac_FlowState = "AutoChangeOver";
1168  // String hvac_FlowMode = "Auto";
1169  // String hvac_Speed = "Normal";
1170 
1171  Serial.print("HVAC Set Point Heat is: " );
1172  Serial.println(hvac_SetPointHeat);
1173  send(msg_S_HVAC_V_HVAC_SETPOINT_HEAT.set(hvac_SetPointHeat,1));
1174 
1175  Serial.print("HVAC Set Point Cool is: " );
1176  Serial.println(hvac_SetPointCool);
1177  send(msg_S_HVAC_V_HVAC_SETPOINT_COOL.set(hvac_SetPointCool,1));
1178 
1179  Serial.print("HVAC Flow State is: " );
1180  Serial.println(hvac_FlowState);
1181  send(msg_S_HVAC_V_HVAC_FLOW_STATET.set(hvac_FlowState.c_str()));
1182 
1183  Serial.print("HVAC Flow Mode is: " );
1184  Serial.println(hvac_FlowMode);
1185  send(msg_S_HVAC_V_HVAC_FLOW_MODE.set(hvac_FlowMode.c_str()));
1186 
1187  Serial.print("HVAC Speed is: " );
1188  Serial.println(hvac_Speed);
1189  send(msg_S_HVAC_V_HVAC_SPEED.set(hvac_Speed.c_str()));
1190 
1191 }
1192 #endif
1193 
1194 #ifdef ID_S_MULTIMETER
1195 void multimeter()
1196 {
1197  int impedance=map(randNumber,1,100,0,15000);
1198  int volt=map(randNumber,1,100,0,380);
1199  int amps=map(randNumber,1,100,0,16);
1200 
1201  Serial.print("Impedance is: " );
1202  Serial.println(impedance);
1203  send(msg_S_MULTIMETER_V_IMPEDANCE.set(impedance));
1204 
1205  Serial.print("Voltage is: " );
1206  Serial.println(volt);
1207  send(msg_S_MULTIMETER_V_VOLTAGE.set(volt));
1208 
1209  Serial.print("Current is: " );
1210  Serial.println(amps);
1211  send(msg_S_MULTIMETER_V_CURRENT.set(amps));
1212 
1213 }
1214 #endif
1215 
1216 #ifdef ID_S_SPRINKLER
1217 #endif
1218 #ifdef ID_S_WATER_LEAK
1219 #endif
1220 #ifdef ID_S_SOUND
1221 #endif
1222 #ifdef ID_S_VIBRATION
1223 #endif
1224 #ifdef ID_S_MOISTURE
1225 #endif
1226 
1227 #ifdef ID_S_MOISTURE
1228 void moisture()
1229 {
1230 
1231  Serial.print("Moisture level is: " );
1232  Serial.println(randNumber);
1233 
1234  send(msg_S_MOISTURE.set(randNumber));
1235 }
1236 #endif
1237 
1238 #ifdef ID_S_CUSTOM
1239 void custom()
1240 {
1241 
1242  Serial.print("Custom value is: " );
1243  Serial.println(randNumber);
1244 
1245  send(msg_S_CUSTOM_1.set(randNumber));
1246  send(msg_S_CUSTOM_2.set(randNumber));
1247  send(msg_S_CUSTOM_3.set(randNumber));
1248  send(msg_S_CUSTOM_4.set(randNumber));
1249  send(msg_S_CUSTOM_5.set(randNumber));
1250 
1251 }
1252 #endif
1253 
1254 
1255 void receive(const MyMessage &message)
1256 {
1257  switch (message.getType()) {
1258 #ifdef ID_S_ARMED
1259  case V_ARMED:
1260  isArmed = message.getBool();
1261  Serial.print("Incoming change for ID_S_ARMED:");
1262  Serial.print(message.getSensor());
1263  Serial.print(", New status: ");
1264  Serial.println((isArmed ? "Armed":"Disarmed" ));
1265 #ifdef ID_S_DOOR
1266  door();//temp ack for door
1267 #endif
1268 #ifdef ID_S_MOTION
1269  motion();//temp ack
1270 #endif
1271 #ifdef ID_S_SMOKE
1272  smoke();//temp ack
1273 #endif
1274  break;
1275 #endif
1276 
1277 
1278  case V_STATUS: // V_LIGHT:
1279 #ifdef ID_S_LIGHT
1280  if(message.getSensor()==ID_S_LIGHT) {
1281  isLightOn = message.getBool();
1282  Serial.print("Incoming change for ID_S_LIGHT:");
1283  Serial.print(message.getSensor());
1284  Serial.print(", New status: ");
1285  Serial.println((isLightOn ? "On":"Off"));
1286  light(); // temp ack
1287  }
1288 #endif
1289  // #ifdef ID_S_HEATER
1290  // if(message.getSensor() == ID_S_HEATER){
1291  // heater_status = message.getBool();
1292  // Serial.print("Incoming change for ID_S_HEATER:");
1293  // Serial.print(message.getSensor());
1294  // Serial.print(", New status: ");
1295  // Serial.println(heater_status);
1296  // heater();//temp ack
1297  // }
1298  // #endif
1299  break;
1300 
1301 
1302 #ifdef ID_S_DIMMER
1303  case V_DIMMER:
1304  if ((message.getInt()<0)||(message.getInt()>100)) {
1305  Serial.println( "V_DIMMER data invalid (should be 0..100)" );
1306  break;
1307  }
1308  dimmerVal= message.getInt();
1309  Serial.print("Incoming change for ID_S_DIMMER:");
1310  Serial.print(message.getSensor());
1311  Serial.print(", New status: ");
1312  Serial.println(message.getInt());
1313  dimmer();// temp ack
1314  break;
1315 #endif
1316 
1317 #ifdef ID_S_COVER
1318  case V_UP:
1319  coverState=1;
1320  Serial.print("Incoming change for ID_S_COVER:");
1321  Serial.print(message.getSensor());
1322  Serial.print(", New status: ");
1323  Serial.println("V_UP");
1324  cover(); // temp ack
1325  break;
1326 
1327  case V_DOWN:
1328  coverState=-1;
1329  Serial.print("Incoming change for ID_S_COVER:");
1330  Serial.print(message.getSensor());
1331  Serial.print(", New status: ");
1332  Serial.println("V_DOWN");
1333  cover(); //temp ack
1334  break;
1335 
1336  case V_STOP:
1337  coverState=0;
1338  Serial.print("Incoming change for ID_S_COVER:");
1339  Serial.print(message.getSensor());
1340  Serial.print(", New status: ");
1341  Serial.println("V_STOP");
1342  cover(); //temp ack
1343  break;
1344 #endif
1345 
1346 
1347  case V_HVAC_SETPOINT_HEAT:
1348 
1349 #ifdef ID_S_HEATER
1350  if(message.getSensor() == ID_S_HEATER) {
1351  heater_setpoint=message.getFloat();
1352 
1353  Serial.print("Incoming set point for ID_S_HEATER:");
1354  Serial.print(message.getSensor());
1355  Serial.print(", New status: ");
1356  Serial.println(heater_setpoint,1);
1357  heater();//temp ack
1358  }
1359 #endif
1360 
1361 #ifdef ID_S_HVAC
1362  if(message.getSensor() == ID_S_HVAC) {
1363  hvac_SetPointHeat=message.getFloat();
1364  Serial.print("Incoming set point for ID_S_HVAC:");
1365  Serial.print(message.getSensor());
1366  Serial.print(", New status: ");
1367  Serial.println(hvac_SetPointHeat,1);
1368  hvac();//temp ack
1369  }
1370 #endif
1371  break;
1372 
1373  case V_HVAC_FLOW_STATE:
1374 #ifdef ID_S_HEATER
1375  if(message.getSensor() == ID_S_HEATER) {
1376  heater_flow_state=message.getString();
1377  Serial.print("Incoming flow state change for ID_S_HEATER:");
1378  Serial.print(message.getSensor());
1379  Serial.print(", New status: ");
1380  Serial.println(heater_flow_state);
1381  heater();//temp ack
1382  }
1383 #endif
1384 
1385 #ifdef ID_S_HVAC
1386  if(message.getSensor() == ID_S_HVAC) {
1387  hvac_FlowState=message.getString();
1388 
1389  Serial.print("Incoming set point for ID_S_HVAC:");
1390  Serial.print(message.getSensor());
1391  Serial.print(", New status: ");
1392  Serial.println(hvac_FlowState);
1393  hvac();//temp ack
1394  }
1395 #endif
1396  break;
1397 
1398 #ifdef ID_S_LOCK
1399  case V_LOCK_STATUS:
1400  isLocked = message.getBool();
1401  Serial.print("Incoming change for ID_S_LOCK:");
1402  Serial.print(message.getSensor());
1403  Serial.print(", New status: ");
1404  Serial.println(message.getBool()?"Locked":"Unlocked");
1405  lock(); //temp ack
1406  break;
1407 #endif
1408 
1409 #ifdef ID_S_IR
1410  case V_IR_SEND:
1411  irVal = message.getLong();
1412  Serial.print("Incoming change for ID_S_IR:");
1413  Serial.print(message.getSensor());
1414  Serial.print(", New status: ");
1415  Serial.println(irVal);
1416  ir(); // temp ack
1417  break;
1418  case V_IR_RECEIVE:
1419  irVal = message.getLong();
1420  Serial.print("Incoming change for ID_S_IR:");
1421  Serial.print(message.getSensor());
1422  Serial.print(", New status: ");
1423  Serial.println(irVal);
1424  ir(); // temp ack
1425  break;
1426 #endif
1427 
1428 #ifdef ID_S_SCENE_CONTROLLER
1429  case V_SCENE_ON:
1430  sceneVal = message.getInt();
1431  Serial.print("Incoming change for ID_S_SCENE_CONTROLLER:");
1432  Serial.print(message.getSensor());
1433  Serial.print(", New status: ");
1434  Serial.print(scenes[sceneVal]);
1435  Serial.println(" On");
1436  scene();// temp ack
1437  break;
1438  case V_SCENE_OFF:
1439  sceneVal = message.getInt();
1440  Serial.print("Incoming change for ID_S_SCENE_CONTROLLER:");
1441  Serial.print(message.getSensor());
1442  Serial.print(", New status: ");
1443  Serial.print(scenes[sceneVal]);
1444  Serial.println(" Off");
1445  scene();// temp ack
1446  break;
1447 #endif
1448 
1449 #ifdef ID_S_RGB_LIGHT
1450  case V_RGB:
1451  rgbState=message.getString();
1452  Serial.print("Incoming flow state change for ID_S_RGB_LIGHT:");
1453  Serial.print(message.getSensor());
1454  Serial.print(", New status: ");
1455  Serial.println(rgbState);
1456  rgbLight(); // temp ack
1457 
1458  break;
1459 #endif
1460 
1461 #ifdef ID_S_RGBW_LIGHT
1462  case V_RGBW:
1463  rgbwState=message.getString();
1464  Serial.print("Incoming flow state change for ID_S_RGBW_LIGHT:");
1465  Serial.print(message.getSensor());
1466  Serial.print(", New status: ");
1467  Serial.println(rgbwState);
1468  rgbwLight();
1469  break;
1470 #endif
1471 
1472 #ifdef ID_S_HVAC
1473  // hvac_SetPointHeat
1474  // hvac_SetPointCool
1475  // hvac_FlowState
1476  // hvac_FlowMode
1477  // hvac_Speed
1478 
1479  case V_HVAC_SETPOINT_COOL:
1480  hvac_SetPointCool=message.getFloat();
1481 
1482  Serial.print("Incoming set point for ID_S_HVAC:");
1483  Serial.print(message.getSensor());
1484  Serial.print(", New status: ");
1485  Serial.println(hvac_SetPointCool,1);
1486  hvac();//temp ack
1487  break;
1488 
1489  case V_HVAC_FLOW_MODE:
1490  hvac_Speed=message.getString();
1491 
1492  Serial.print("Incoming set point for ID_S_HVAC:");
1493  Serial.print(message.getSensor());
1494  Serial.print(", New status: ");
1495  Serial.println(hvac_Speed);
1496  hvac();//temp ack
1497  break;
1498 
1499  case V_HVAC_SPEED:
1500  hvac_FlowMode=message.getString();
1501 
1502  Serial.print("Incoming set point for ID_S_HVAC:");
1503  Serial.print(message.getSensor());
1504  Serial.print(", New status: ");
1505  Serial.println(hvac_FlowMode);
1506  hvac();//temp ack
1507  break;
1508 #endif
1509 
1510  default:
1511  Serial.print("Unknown/Unimplemented message type: ");
1512  Serial.println(message.getType());
1513  }
1514 
1515 }
int16_t getInt(void) const
Get signed 16-bit integer payload.
MyMessage is used to create, manipulate, send and read MySensors messages.
Definition: MyMessage.h:289
bool sendSketchInfo(const char *name, const char *version, const bool requestEcho=false)
API declaration for MySensors.
uint8_t getSensor(void) const
Get sensor ID of message.
controllerConfig_t getControllerConfig(void)
char * getString(char *buffer) const
Copy the payload into the supplied buffer.
bool getBool(void) const
Get bool payload.
bool requestTime(const bool requestEcho=false)
int32_t getLong(void) const
Get signed 32-bit integer payload.
uint8_t isMetric
Flag indicating if metric or imperial measurements are used.
Definition: MySensorsCore.h:95
bool send(MyMessage &msg, const bool requestEcho=false)
void receiveTime(uint32_t controllerTime)
Callback for incoming time messages.
bool present(const uint8_t sensorId, const mysensors_sensor_t sensorType, const char *description="", const bool requestEcho=false)
bool sendBatteryLevel(const uint8_t level, const bool requestEcho=false)
void setup()
Called after node initialises but before main loop.
float getFloat(void) const
Get float payload.
void receive(const MyMessage &message)
Callback for incoming messages.
void presentation()
Node presentation.
uint8_t getType(void) const
Get message type.
MyMessage & set(const void *payload, const size_t length)
Set entire payload.
void loop()
Main loop.
void wait(const uint32_t waitingMS)