w arduino mam skrypt który działa bez problemu w Domoticzu, po przejsciu na HA działa tylko częsciowo.
Co trzeba by zmienić aby były widoczne przekazniki?
Temperatura jak i kontaktrony dzialaja prawidlowo.
// Enable debug prints to serial monitor #define MY_DEBUG // Enable and select radio type attached //#define MY_RADIO_RF24 //#define MY_RADIO_NRF5_ESB //#define MY_RADIO_RFM69 //#define MY_RADIO_RFM95 // Set LOW transmit power level as default, if you have an amplified NRF-module and // power your radio separately with a good regulator you can turn up PA level. //#define MY_RF24_PA_LEVEL RF24_PA_LOW // Enable serial gateway #define MY_GATEWAY_SERIAL // Define a lower baud rate for Arduinos running on 8 MHz (Arduino Pro Mini 3.3V & SenseBender) #if F_CPU == 8000000L #define MY_BAUD_RATE 38400 #endif // Enable inclusion mode #define MY_INCLUSION_MODE_FEATURE // Enable Inclusion mode button on gateway //#define MY_INCLUSION_BUTTON_FEATURE // Inverses behavior of inclusion button (if using external pullup) //#define MY_INCLUSION_BUTTON_EXTERNAL_PULLUP // Set inclusion mode duration (in seconds) #define MY_INCLUSION_MODE_DURATION 60 // Digital pin used for inclusion mode button //#define MY_INCLUSION_MODE_BUTTON_PIN 3 // Set blinking period #define MY_DEFAULT_LED_BLINK_PERIOD 300 // Inverses the behavior of leds //#define MY_WITH_LEDS_BLINKING_INVERSE // Flash leds on rx/tx/err // Uncomment to override default HW configurations //#define MY_DEFAULT_ERR_LED_PIN 4 // Error led pin //#define MY_DEFAULT_RX_LED_PIN 6 // Receive led pin //#define MY_DEFAULT_TX_LED_PIN 5 // the PCB, on board LED #include <SPI.h> #include <MySensors.h> #include <DallasTemperature.h> #include <OneWire.h> #include <Bounce2.h> #define RELAY_1 24 // pompa cyrkulacji #define RELAY_2 25 #define RELAY_3 26 #define RELAY_4 27 #define RELAY_5 28 #define RELAY_6 29 #define RELAY_7 30 #define RELAY_8 31 #define RELAY_9 32 #define RELAY_10 33 #define RELAY_11 34 #define RELAY_12 35 #define RELAY_13 36 #define RELAY_14 37 #define RELAY_15 38 #define RELAY_16 39 #define NUMBER_OF_RELAYS 21 // Total number of attached relays #define RELAY_ON 0 // GPIO value to write to turn on attached relay #define RELAY_OFF 1 // GPIO value to write to turn off attached relay #define BUTTON_PIN 3 //wlacznik cyrkulacji #define BUTTON2_PIN 4 #define BUTTON3_PIN 5 #define BUTTON4_PIN 6 #define BUTTON5_PIN 7 #define BUTTON6_PIN 8 #define BUTTON7_PIN 9 #define BUTTON8_PIN A7 #define BUTTON9_PIN A8 #define BUTTON10_PIN A9 #define BUTTON11_PIN A10 #define BUTTON12_PIN A11 #define BUTTON13_PIN A12 #define BUTTON14_PIN A13 #define BUTTON15_PIN A14 //#define BUTTON16_PIN 2 #define CHILD_ID_1 46 //Kontaktron #define BUTTON_PIN_1 46 // Arduino Digital I/O pin for button/reed switch #define CHILD_ID_2 47 #define BUTTON_PIN_2 47 // Arduino Digital I/O pin for button/reed switch #define COMPARE_TEMP 0 // Send temperature only if changed? 1 = Yes 0 = No #define ONE_WIRE_BUS 2 // Pin z podpietymi czujnikami #define ATTACHED_DS18B20 29 unsigned long SLEEP_TIME = 30000; // Sleep time between reads (in milliseconds) // Generally, you should use "unsigned long" for variables that hold time // The value will quickly become too large for an int to store unsigned long previousMillis = 0; // will store last time LED was updated OneWire oneWire(ONE_WIRE_BUS); // Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs) DallasTemperature sensors(&oneWire); // Pass the oneWire reference to Dallas Temperature. byte D[ATTACHED_DS18B20][8] = { { 0x28, 0x90, 0x5, 0x56, 0xB5, 0x1, 0x3C, 0xFC }, //1 22 cz sprzegla gorny { 0x28, 0xEA, 0x8A, 0x56, 0xB5, 0x1, 0x3C, 0xF }, //2 23 cz CWU /* {0x28, 0x4B, 0xD9, 0x16, 0xA8, 0x1, 0x3C, 0x5}, //3 24 cz powrot cyrkulacji {0x28, 0x44, 0x9E, 0x16, 0xA8, 0x1, 0x3C, 0x99}, //4 25 cz pompa CWU {0x28, 0x6C, 0x18, 0x16, 0xA8, 0x1, 0x3C, 0xD9}, //5 26 cz podlogowka gora {0x28, 0xA6, 0xB8, 0x56, 0xB5, 0x1, 0x3C, 0x0}, //6 27 cz temp pieca {0x28, 0xDB, 0xB2, 0x56, 0xB5, 0x1, 0x3C, 0x6F}, //7 28 cz powrot podlogowki garaz {0x28, 0x6, 0xC1, 0x16, 0xA8, 0x1, 0x3C, 0x78}, //8 29 cz sterownik pieca {0x28, 0xD, 0x6B, 0x4, 0x0, 0x0, 0x0, 0x3B}, //9 30 cz pokoj 2 {0x28, 0x1F, 0x3D, 0x5, 0x0, 0x0, 0x0, 0x88}, //10 31 cz pokoj 1 {0x28, 0x50, 0xC3, 0x4, 0x0, 0x0, 0x0, 0x52}, //11 32 cz pokoj 4 {0x28, 0xCB, 0x8A, 0x4, 0x0, 0x0, 0x0, 0x1}, //12 33 cz pokoj 3 {0x28, 0x2B, 0xC0, 0x4, 0x0, 0x0, 0x0, 0x7C}, //13 34 cz gniazdo wzmacniacza wifi {0x28, 0x42, 0x81, 0x4, 0x0, 0x0, 0x0, 0xD}, //14 35 cz woda uzytkowa na dom {0x28, 0x30, 0x47, 0x5, 0x0, 0x0, 0x0, 0xCA}, //15 36 cz powrot podlogowki parter {0x28, 0x5, 0xD7, 0x4, 0x0, 0x0, 0x0, 0xF4}, //16 37 cz podlogowka garaz {0x28, 0x47, 0x19, 0x5, 0x0, 0x0, 0x0, 0xE0}, //17 38 cz powrot podlogowka gora {0x28, 0xF5, 0x36, 0x5, 0x0, 0x0, 0x0, 0x1E}, //18 39 cz wody na grzejniki {0x28, 0x86, 0xB7, 0x16, 0xA8, 0x1, 0x3C, 0x63}, //19 40 cz temp wody podlogowka parter {0x28, 0xA1, 0x3B, 0x5, 0x0, 0x0, 0x0, 0x0}, //20 41 cz powrot wody grzejniki {0x28, 0x98, 0x91, 0x4, 0x0, 0x0, 0x0, 0x7A}, //21 42 cz na powrocie pieca {0x28, 0xD5, 0x10, 0x5, 0x0, 0x0, 0x0, 0xCC}, //22 43 cz obok palnika przy piecu {0x28, 0x4B, 0xDE, 0x79, 0xA2, 0x1, 0x3, 0xCB}, //23 44 cz w rozdzielni elektrycznej {0x28, 0xF9, 0x14, 0x5, 0x0, 0x0, 0x0, 0x18}, //24 45 cz w kanciapie {0x28, 0x91, 0x7C, 0x5, 0x0, 0x0, 0x0, 0x55} //25 46 cz w wiatrolapie glownym */ }; //{0x28, 0x72, 0xD7, 0x4, 0x0, 0x0, 0x0, 0xE9}, //9 -30 cz okno przesowne prawa strona //{0x28, 0xA4, 0x68, 0x4, 0x0, 0x0, 0x0, 0xBF}, //25 -46 cz na zewnatrz wschod //{0x28, 0xD, 0x9D, 0x56, 0xB5, 0x1, 0x3C, 0x8E}, //27 -48 cz w lazience na gorze float lastTemperature[ATTACHED_DS18B20]; int numSensors = 0; bool receivedConfig = false; bool metric = true; // Initialize temperature message MyMessage msg(0, V_TEMP); MyMessage msg2(1, V_LIGHT); MyMessage msg3(2, V_LIGHT); MyMessage msg4(3, V_LIGHT); MyMessage msg5(4, V_LIGHT); MyMessage msg6(5, V_LIGHT); MyMessage msg7(6, V_LIGHT); MyMessage msg8(7, V_LIGHT); MyMessage msg9(8, V_LIGHT); MyMessage msg10(9, V_LIGHT); MyMessage msg11(10, V_LIGHT); MyMessage msg12(11, V_LIGHT); MyMessage msg13(12, V_LIGHT); MyMessage msg14(13, V_LIGHT); MyMessage msg15(14, V_LIGHT); MyMessage msg16(15, V_LIGHT); MyMessage msg17(16, V_LIGHT); MyMessage msg18(CHILD_ID_1, V_TRIPPED); MyMessage msg19(CHILD_ID_2, V_TRIPPED); void before() { for (int sensor = 1, pin = RELAY_1; sensor <= NUMBER_OF_RELAYS; sensor++, pin++) { // Then set relay pins in output mode pinMode(pin, OUTPUT); // Set relay to last known state (using eeprom storage) digitalWrite(pin, loadState(sensor) ? RELAY_ON : RELAY_OFF); } // Startup up the OneWire library sensors.begin(); } Bounce debouncer = Bounce(); Bounce debouncer2 = Bounce(); Bounce debouncer3 = Bounce(); Bounce debouncer4 = Bounce(); Bounce debouncer5 = Bounce(); Bounce debouncer6 = Bounce(); Bounce debouncer7 = Bounce(); Bounce debouncer8 = Bounce(); Bounce debouncer9 = Bounce(); Bounce debouncer10 = Bounce(); Bounce debouncer11 = Bounce(); Bounce debouncer12 = Bounce(); Bounce debouncer13 = Bounce(); Bounce debouncer14 = Bounce(); Bounce debouncer15 = Bounce(); Bounce debouncer16 = Bounce(); Bounce debouncer17 = Bounce(); Bounce debouncer18 = Bounce(); int oldValue17 = -1; //kontaktron int oldValue18 = -1; void setup() { { // Setup locally attached sensors delay(11000); // Setup the button. pinMode(BUTTON_PIN_1, INPUT); pinMode(BUTTON_PIN_2, INPUT); // Activate internal pull-up digitalWrite(BUTTON_PIN_1, HIGH); digitalWrite(BUTTON_PIN_2, HIGH); pinMode(BUTTON_PIN, INPUT_PULLUP); //pompa cyrkulacji debouncer.attach(BUTTON_PIN); debouncer.interval(5); pinMode(BUTTON2_PIN, INPUT_PULLUP); debouncer2.attach(BUTTON2_PIN); debouncer2.interval(5); pinMode(BUTTON3_PIN, INPUT_PULLUP); debouncer3.attach(BUTTON3_PIN); debouncer3.interval(5); pinMode(BUTTON4_PIN, INPUT_PULLUP); debouncer4.attach(BUTTON4_PIN); debouncer4.interval(5); pinMode(BUTTON5_PIN, INPUT_PULLUP); debouncer5.attach(BUTTON5_PIN); debouncer5.interval(5); pinMode(BUTTON6_PIN, INPUT_PULLUP); debouncer6.attach(BUTTON6_PIN); debouncer6.interval(5); pinMode(BUTTON7_PIN, INPUT_PULLUP); debouncer7.attach(BUTTON7_PIN); debouncer7.interval(5); pinMode(BUTTON8_PIN, INPUT_PULLUP); debouncer8.attach(BUTTON8_PIN); debouncer8.interval(5); pinMode(BUTTON9_PIN, INPUT_PULLUP); debouncer9.attach(BUTTON9_PIN); debouncer9.interval(5); pinMode(BUTTON10_PIN, INPUT_PULLUP); debouncer10.attach(BUTTON10_PIN); debouncer10.interval(5); pinMode(BUTTON11_PIN, INPUT_PULLUP); debouncer11.attach(BUTTON11_PIN); debouncer11.interval(5); pinMode(BUTTON12_PIN, INPUT_PULLUP); debouncer12.attach(BUTTON12_PIN); debouncer12.interval(5); pinMode(BUTTON13_PIN, INPUT_PULLUP); debouncer13.attach(BUTTON13_PIN); debouncer13.interval(5); pinMode(BUTTON14_PIN, INPUT_PULLUP); debouncer14.attach(BUTTON14_PIN); debouncer14.interval(5); pinMode(BUTTON15_PIN, INPUT_PULLUP); debouncer15.attach(BUTTON15_PIN); debouncer15.interval(5); // pinMode(BUTTON16_PIN, INPUT_PULLUP); // debouncer16.attach(BUTTON16_PIN); // debouncer16.interval(5); debouncer17.attach(BUTTON_PIN_1); //kontrakton debouncer17.interval(5); debouncer18.attach(BUTTON_PIN_2); debouncer18.interval(5); } // requestTemperatures() will not block current thread sensors.setWaitForConversion(false); } void presentation() { // Send the sketch version information to the gateway and Controller sendSketchInfo("Relay and Temp", "1.0"); for (int sensor = 1; sensor <= NUMBER_OF_RELAYS + ATTACHED_DS18B20; sensor++) { // Register all sensors to gw (they will be created as child devices) if (sensor <= NUMBER_OF_RELAYS) { present(sensor, S_BINARY); } else { present(sensor, S_TEMP); } } { // Register binary input sensor to gw (they will be created as child devices) // You can use S_DOOR, S_MOTION or S_LIGHT here depending on your usage. // If S_LIGHT is used, remember to update variable type you send in. See "msg" above. present(CHILD_ID_1, S_DOOR); present(CHILD_ID_2, S_DOOR); } } void loop() { { unsigned long currentMillis = millis(); if (currentMillis - previousMillis >= SLEEP_TIME) { // save the last time you blinked the LED previousMillis = currentMillis; // Fetch temperatures from Dallas sensors sensors.requestTemperatures(); // query conversion time and sleep until conversion completed int16_t conversionTime = sensors.millisToWaitForConversion(sensors.getResolution()); // sleep() call can be replaced by wait() call if node need to process incoming messages (or if node is repeater) sleep(conversionTime); // Read temperatures and send them to controller for (int i = 0; i < ATTACHED_DS18B20; i++) { // Fetch and round temperature to one decimal // float temperature = static_cast<float>(static_cast<int>((getConfig().isMetric?sensors.getTempCByIndex(i):sensors.getTempFByIndex(i)) * 10.)) / 10.; float temperature = sensors.getTempC(D[i]); // Only send data if temperature has changed and no error if (COMPARE_TEMP == 1) { if (lastTemperature[i] != temperature && temperature != -127.00 && temperature != 85.00) { // Send in the new temperature send(msg.setSensor(i + NUMBER_OF_RELAYS + 1).set(temperature, 1)); // Save new temperatures for next compare lastTemperature[i] = temperature; } } else { if (temperature != -127.00 && temperature != 85.00) { // Send in the new temperature send(msg.setSensor(i + NUMBER_OF_RELAYS + 1).set(temperature, 1)); // Save new temperatures for next compare lastTemperature[i] = temperature; } } } } } { // Send locally attached sensor data here if (debouncer.update()) { //1 // Get the update value. int value = debouncer.read(); // Send in the new value. if (value == LOW) { saveState(1, !loadState(1)); digitalWrite(RELAY_1, loadState(1) ? RELAY_ON : RELAY_OFF); send(msg2.set(loadState(1))); } } if (debouncer2.update()) { //2 int value2 = debouncer2.read(); if (value2 == LOW) { saveState(2, !loadState(2)); digitalWrite(RELAY_2, loadState(2) ? RELAY_ON : RELAY_OFF); send(msg3.set(loadState(2))); } } if (debouncer3.update()) { //3 int value3 = debouncer3.read(); if (value3 == LOW) { saveState(3, !loadState(3)); digitalWrite(RELAY_3, loadState(3) ? RELAY_ON : RELAY_OFF); send(msg4.set(loadState(3))); } } if (debouncer4.update()) { //4 int value4 = debouncer4.read(); if (value4 == LOW) { saveState(4, !loadState(4)); digitalWrite(RELAY_4, loadState(4) ? RELAY_ON : RELAY_OFF); send(msg5.set(loadState(4))); } } if (debouncer5.update()) { //5 int value5 = debouncer5.read(); if (value5 == LOW) { saveState(5, !loadState(5)); digitalWrite(RELAY_5, loadState(5) ? RELAY_ON : RELAY_OFF); send(msg6.set(loadState(5))); } } if (debouncer6.update()) { //6 int value6 = debouncer6.read(); if (value6 == LOW) { saveState(6, !loadState(6)); digitalWrite(RELAY_6, loadState(6) ? RELAY_ON : RELAY_OFF); send(msg7.set(loadState(6))); } } if (debouncer7.update()) { //7 int value7 = debouncer7.read(); if (value7 == LOW) { saveState(7, !loadState(7)); digitalWrite(RELAY_7, loadState(7) ? RELAY_ON : RELAY_OFF); send(msg8.set(loadState(7))); } } if (debouncer8.update()) { //8 int value8 = debouncer8.read(); if (value8 == LOW) { saveState(8, !loadState(8)); digitalWrite(RELAY_8, loadState(8) ? RELAY_ON : RELAY_OFF); send(msg9.set(loadState(8))); } } if (debouncer9.update()) { //9 int value9 = debouncer9.read(); if (value9 == LOW) { saveState(9, !loadState(9)); digitalWrite(RELAY_9, loadState(9) ? RELAY_ON : RELAY_OFF); send(msg10.set(loadState(9))); } } if (debouncer10.update()) { //10 int value10 = debouncer10.read(); if (value10 == LOW) { saveState(10, !loadState(10)); digitalWrite(RELAY_10, loadState(10) ? RELAY_ON : RELAY_OFF); send(msg11.set(loadState(10))); } } if (debouncer11.update()) { //11 int value11 = debouncer11.read(); if (value11 == LOW) { saveState(11, !loadState(11)); digitalWrite(RELAY_11, loadState(11) ? RELAY_ON : RELAY_OFF); send(msg12.set(loadState(11))); } } if (debouncer12.update()) { //12 int value12 = debouncer12.read(); if (value12 == LOW) { saveState(12, !loadState(12)); digitalWrite(RELAY_12, loadState(12) ? RELAY_ON : RELAY_OFF); send(msg13.set(loadState(12))); } } if (debouncer13.update()) { //13 int value13 = debouncer13.read(); if (value13 == LOW) { saveState(13, !loadState(13)); digitalWrite(RELAY_13, loadState(13) ? RELAY_ON : RELAY_OFF); send(msg14.set(loadState(13))); } } if (debouncer14.update()) { //14 int value14 = debouncer14.read(); if (value14 == LOW) { saveState(14, !loadState(14)); digitalWrite(RELAY_14, loadState(14) ? RELAY_ON : RELAY_OFF); send(msg15.set(loadState(14))); } } if (debouncer15.update()) { //15 int value15 = debouncer15.read(); if (value15 == LOW) { saveState(15, !loadState(15)); digitalWrite(RELAY_15, loadState(15) ? RELAY_ON : RELAY_OFF); send(msg16.set(loadState(15))); } } if (debouncer16.update()) { //16 int value16 = debouncer16.read(); if (value16 == LOW) { saveState(16, !loadState(16)); digitalWrite(RELAY_16, loadState(16) ? RELAY_ON : RELAY_OFF); send(msg17.set(loadState(16))); } } debouncer17.update(); // Get the update value int value17 = debouncer17.read(); if (value17 != oldValue17) { // Send in the new value send(msg18.set(value17 == HIGH ? 1 : 0)); oldValue17 = value17; } debouncer18.update(); // Get the update value int value18 = debouncer18.read(); if (value18 != oldValue18) { // Send in the new value send(msg19.set(value18 == HIGH ? 1 : 0)); oldValue18 = value18; } } } void receive(const MyMessage &message) { // We only expect one type of message from controller. But we better check anyway. if (message.type == V_STATUS) { // Change relay state digitalWrite(message.sensor - 1 + RELAY_1, message.getBool() ? RELAY_ON : RELAY_OFF); // Store state in eeprom saveState(message.sensor, message.getBool()); // Write some debug info Serial.print("Incoming change for sensor:"); Serial.print(message.sensor); Serial.print(", New status: "); Serial.println(message.getBool()); } }
Witam,
udalo Ci sie rozwiązać problem, bo w sumie wisze w tym samym miejscu ?
Hej,
Wywaliłem arduino, zakupiłem ESP32. dużo prostsze i więcej możiwości do konfiguracji. Tasmota, ESPeasy, ESPHOME, działa to dużo lepiej.
Teoretycznie tak . Praktycznie chciałbym to zostawić niezależne.