domoticz.ino 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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<500> jsonBuf;
  23. JsonObject& domoticz = jsonBuf.parseObject(domoticzOutPayload);
  24. idx = domoticz["idx"];
  25. nvalue = domoticz["nvalue"];
  26. yield();
  27. for (int i = 0; i < sizeof(domoticzIdx); i++) {
  28. if ( idx == domoticzIdx[i] && idx != 0 ) {
  29. if ( dismissUpdateFromDomoticzTimeout == 0 || (lastSwitchSource[i] == 3 || (lastSwitchSource[i] < 3 && (millis() - lastSwitchTime[i]) > dismissUpdateFromDomoticzTimeout)) ) {
  30. // -> only perform operation if last switch command came from domoticz (lastSwitchSource==3) or is older than dismissUpdateFromDomoticzTimeout
  31. // disable this filtering if dismissUpdateFromDomoticzTimeout is set to 0
  32. Serial.print(domoticz_out_topic);
  33. Serial.print(" received: ");
  34. Serial.print(" idx=");
  35. Serial.print(idx);
  36. Serial.print(", nvalue=");
  37. Serial.println(nvalue);
  38. yield();
  39. if (nvalue == 1) {
  40. updateDomoticz[i] = false; // prevent loop - when update came from domoticz, do not update domoticz state
  41. lastSwitchSource[i] = 3;
  42. relaisOn(i);
  43. updateDomoticz[i] = true; // enable domoticz updates again
  44. }
  45. else if (nvalue == 0) {
  46. updateDomoticz[i] = false; // prevent loop - when update came from domoticz, do not update domoticz state
  47. lastSwitchSource[i] = 3;
  48. relaisOff(i);
  49. updateDomoticz[i] = true; // enable domoticz updates again
  50. }
  51. }
  52. }
  53. }
  54. domoticzOutParserBusy = false;
  55. }
  56. void checkUseDomoticz() {
  57. if (domoticzIdx[0] != 0 || domoticzIdx[1] != 0 || domoticzIdx[2] != 0) {
  58. useDomoticz = true;
  59. }
  60. else {
  61. useDomoticz = false;
  62. }
  63. }