domoticz.ino 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. //sample domoticz/out payload:
  2. //{
  3. // "Battery" : 255,
  4. // "RSSI" : 12,
  5. // "description" : "Deckenleuchte Arbeitszimmer\nSonoff-Touch-01",
  6. // "dtype" : "Light/Switch",
  7. // "id" : "00014121",
  8. // "idx" : 209,
  9. // "name" : "Arbeitszimmer Licht",
  10. // "nvalue" : 1,
  11. // "stype" : "Switch",
  12. // "switchType" : "On/Off",
  13. // "unit" : 1
  14. //}
  15. // -> we need idx and nvalue
  16. void parseDomoticzOut() {
  17. domoticzOutParseData = false;
  18. domoticzOutParserBusy = true;
  19. unsigned long idx = 0;
  20. int16_t nvalue;
  21. int16_t found = 0;
  22. StaticJsonBuffer<400> jsonBuf;
  23. JsonObject& domoticz = jsonBuf.parseObject(domoticzOutPayload);
  24. idx = domoticz["idx"];
  25. nvalue = domoticz["nvalue"];
  26. for (int i = 0; i < sizeof(domoticzIdx); i++) {
  27. if ( idx == domoticzIdx[i] && idx != 0 ) {
  28. if ( dismissUpdateFromDomoticzTimeout == 0 || (lastSwitchSource[i] == 3 || (lastSwitchSource[i] < 3 && (millis() - lastSwitchTime[i]) > dismissUpdateFromDomoticzTimeout)) ) {
  29. // -> only perform operation if last switch command came from domoticz (lastSwitchSource==3) or is older than dismissUpdateFromDomoticzTimeout
  30. // disable this filtering if dismissUpdateFromDomoticzTimeout is set to 0
  31. Serial.print(domoticz_out_topic);
  32. Serial.print(" received: ");
  33. Serial.print(" idx=");
  34. Serial.print(idx);
  35. Serial.print(", nvalue=");
  36. Serial.println(nvalue);
  37. if (nvalue == 1) {
  38. updateDomoticz[i] = false; // prevent loop - when update came from domoticz, do not update domoticz state
  39. lastSwitchSource[i] = 3;
  40. relaisOn(i);
  41. updateDomoticz[i] = true; // enable domoticz updates again
  42. }
  43. else if (nvalue == 0) {
  44. updateDomoticz[i] = false; // prevent loop - when update came from domoticz, do not update domoticz state
  45. lastSwitchSource[i] = 3;
  46. relaisOff(i);
  47. updateDomoticz[i] = true; // enable domoticz updates again
  48. }
  49. }
  50. }
  51. }
  52. domoticzOutParserBusy = false;
  53. }
  54. void checkUseDomoticz() {
  55. if (domoticzIdx[0] != 0 || domoticzIdx[1] != 0 || domoticzIdx[2] != 0) {
  56. useDomoticz = true;
  57. }
  58. else {
  59. useDomoticz = false;
  60. }
  61. }