Mysensors - problem z przekaźnikami

Witam!

Mam problem z dwoma przekaźnikami, których nie widać w GUI, a widać w konfigu.
Oprócz tego są 3 włączniki 2 czujki ruchu i czujnik otwarcia drzwi, które działają bez problemu.

Oto skrypt:


// 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

// Enable repeater functionality for this node
#define MY_REPEATER_FEATURE
#define MY_NODE_ID 10

#include <MySensors.h>
#include <Bounce2.h>

#define RELAY_PIN 4  // Arduino Digital I/O pin number for first relay (second on pin+1 etc)
#define NUMBER_OF_RELAYS 2 // 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 PRIMARY_CHILD_ID 11
#define PRIMARY_BUTTON_PIN  A0
#define SECONDARY_CHILD_ID 22
#define SECONDARY_BUTTON_PIN A1
#define TERTIARY_CHILD_ID 33
#define TERTIARY_BUTTON_PIN A2
#define QUATERNARY_CHILD_ID 44
#define QUATERNARY_BUTTON_PIN A3
#define QUINARY_CHILD_ID 55
#define QUINARY_BUTTON_PIN A4
#define SENARY_CHILD_ID 66
#define SENARY_BUTTON_PIN A5

Bounce debouncer = Bounce();
int oldValue = -1;

// Change to V_LIGHT if you use S_LIGHT in presentation below
MyMessage msg(PRIMARY_CHILD_ID, V_TRIPPED);
MyMessage msg2(SECONDARY_CHILD_ID, V_TRIPPED);
MyMessage msg3(TERTIARY_CHILD_ID, V_TRIPPED);
MyMessage msg4(QUATERNARY_CHILD_ID, V_LIGHT);
MyMessage msg5(QUINARY_CHILD_ID, V_LIGHT);
MyMessage msg6(SENARY_CHILD_ID, V_LIGHT);

void before()
{
  for (int sensor = 1, pin = RELAY_PIN; 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);
  }
}

void setup()
{
  // Setup the button
  pinMode(PRIMARY_BUTTON_PIN, INPUT);
  pinMode(SECONDARY_BUTTON_PIN, INPUT);
  pinMode(TERTIARY_BUTTON_PIN, INPUT);
  pinMode(QUATERNARY_BUTTON_PIN, INPUT);
  pinMode(QUINARY_BUTTON_PIN, INPUT);
  pinMode(SENARY_BUTTON_PIN, INPUT);
  // Activate internal pull-up
  digitalWrite(PRIMARY_BUTTON_PIN, HIGH);
  digitalWrite(SECONDARY_BUTTON_PIN, HIGH);
  digitalWrite(TERTIARY_BUTTON_PIN, HIGH);
  digitalWrite(QUATERNARY_BUTTON_PIN, HIGH);
  digitalWrite(QUINARY_BUTTON_PIN, HIGH);
  digitalWrite(SENARY_BUTTON_PIN, HIGH);

  debouncer.attach(PRIMARY_BUTTON_PIN);
  debouncer.attach(SECONDARY_BUTTON_PIN);
  debouncer.attach(TERTIARY_BUTTON_PIN);
  debouncer.attach(QUATERNARY_BUTTON_PIN);
  debouncer.attach(QUINARY_BUTTON_PIN);
  debouncer.attach(SENARY_BUTTON_PIN);
  debouncer.interval(10);
}

void presentation()
{
  // Send the sketch version information to the gateway and Controller
  sendSketchInfo("Relay", "1.0");

  for (int sensor = 1, pin = RELAY_PIN; sensor <= NUMBER_OF_RELAYS; sensor++, pin++) {
    // Register all sensors to gw (they will be created as child devices)
    present(sensor, S_BINARY);
    wait( 50 );
  }

  present(PRIMARY_CHILD_ID, S_MOTION);
  present(SECONDARY_CHILD_ID, S_MOTION);
  present(TERTIARY_CHILD_ID, S_DOOR);
  present(QUATERNARY_CHILD_ID, S_LIGHT);
  present(QUINARY_CHILD_ID, S_LIGHT);
  present(SENARY_CHILD_ID, S_LIGHT);
  
}


void loop()
{
  uint8_t value;
  static uint8_t sentValue = 2;
  static uint8_t sentValue2 = 2;
  static uint8_t sentValue3 = 2;
  static uint8_t sentValue4 = 2;
  static uint8_t sentValue5 = 2;
  static uint8_t sentValue6 = 2;

  // Short delay to allow buttons to properly settle

  value = digitalRead(PRIMARY_BUTTON_PIN);

  if (value != sentValue) {
    // Value has changed from last transmission, send the updated value
    send(msg.set(value == HIGH ? 1 : 0));
    sentValue = value;
  }

  value = digitalRead(SECONDARY_BUTTON_PIN);

  if (value != sentValue2) {
    // Value has changed from last transmission, send the updated value
    send(msg2.set(value == HIGH ? 1 : 0));
    sentValue2 = value;
  }

  value = digitalRead(TERTIARY_BUTTON_PIN);

  if (value != sentValue3) {
    // Value has changed from last transmission, send the updated value
    send(msg3.set(value == HIGH ? 1 : 0));
    sentValue3 = value;
  }

  value = digitalRead(QUATERNARY_BUTTON_PIN);

  if (value != sentValue4) {
    // Value has changed from last transmission, send the updated value
    send(msg4.set(value == LOW ? 1 : 0));
    sentValue4 = value;
  }

  value = digitalRead(QUINARY_BUTTON_PIN);

  if (value != sentValue5) {
    // Value has changed from last transmission, send the updated value
    send(msg5.set(value == LOW ? 1 : 0));
    sentValue5 = value;
  }

  value = digitalRead(SENARY_BUTTON_PIN);

  if (value != sentValue6) {
    // Value has changed from last transmission, send the updated value
    send(msg6.set(value == LOW ? 1 : 0));
    sentValue6 = value;
  }
}

void receive(const MyMessage &message)
{
  // We only expect one type of message from controller. But we better check anyway.
  if (message.getType() == V_STATUS) {
    // Change relay state
    digitalWrite(message.getSensor() - 1 + RELAY_PIN, message.getBool() ? RELAY_ON : RELAY_OFF);
    // Store state in eeprom
    saveState(message.getSensor(), message.getBool());
    // Write some debug info
    Serial.print("Incoming change for sensor:");
    Serial.print(message.getSensor());
    Serial.print(", New status: ");
    Serial.println(message.getBool());
  }
}

I config mysensors:

{
    "0": {
        "sensor_id": 0,
        "children": {},
        "type": 18,
        "sketch_name": null,
        "sketch_version": null,
        "battery_level": 0,
        "protocol_version": "2.3.2",
        "heartbeat": 0
    },
    "10": {
        "sensor_id": 10,
        "children": {
            "1": {
                "id": 1,
                "type": 3,
                "description": "",
                "values": {}
            },
            "2": {
                "id": 2,
                "type": 3,
                "description": "",
                "values": {}
            },
            "11": {
                "id": 11,
                "type": 1,
                "description": "",
                "values": {
                    "16": "0"
                }
            },
            "22": {
                "id": 22,
                "type": 1,
                "description": "",
                "values": {
                    "16": "0"
                }
            },
            "33": {
                "id": 33,
                "type": 0,
                "description": "",
                "values": {
                    "16": "0"
                }
            },
            "44": {
                "id": 44,
                "type": 3,
                "description": "",
                "values": {
                    "16": "0",
                    "2": "0"
                }
            },
            "55": {
                "id": 55,
                "type": 3,
                "description": "",
                "values": {
                    "16": "0",
                    "2": "0"
                }
            },
            "66": {
                "id": 66,
                "type": 3,
                "description": "",
                "values": {
                    "16": "0",
                    "2": "0"
                }
            }
        },
        "type": 18,
        "sketch_name": "Relay",
        "sketch_version": "1.0",
        "battery_level": 0,
        "protocol_version": "2.3.2",
        "heartbeat": 0
    }
}

Obstawiam że ID 1 oraz 2 to te nieszczęsne przekaźniki.
Czy ktoś wie gdzie popełniłem błąd?

Polecam użyć dość znany sketch kolegi Kankowskiego szukaj na Facebooku. Posiadam go od kilku lat do oświetlenia bezawaryjny.

Witam, używam sketchu od kolegi Kankowskiego :slight_smile: działa świetnie jednak napotkałem się na pewnie problem. Działam na płytkach arduino mega, po aktualizacji sketcha (dodaniu kilku nowych przekaźników) nie aktualizują się encje, wgrałem sketch na inną płytkę i zero problemów :slight_smile: moje pytanie brzmi czy w pamięci HA pozostaje jakiś ślad po identyfikatorze arduino który może przeszkadzać w dodawaniu nowych encji ?

Tak, persistence file, proponuje przeczytać dokumentację integracji MySensors - Home Assistant.