Relay Actuator - send periodic status as heart beat.

  • Hi,
    i successfully added heartbeat sending to RelayActuator.ino and relay sensor is sending data every one minute - but domoticz don't update last seen - this is only visible on gateway log. So i decided to send relay status as heartbeat - i have relay with two relay switches.

    Source code:

    #define MY_RADIO_RFM69
    #define MY_RFM69_NEW_DRIVER
    #define MY_NODE_ID 3
    // Enable repeater functionality for this node
    #include <SPI.h>
    #include <MySensors.h>
    #define RELAY_1  3  // Arduino Digital I/O pin number for first relay (second on pin+1 etc)
    #define RELAY_2  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 1  // GPIO value to write to turn on attached relay
    #define RELAY_OFF 0 // GPIO value to write to turn off attached relay
    #define MY_DEBUG_VERBOSE
    long double last_heartbeat_time = millis();
    long double HEARTBEAT_TIME = 30000;
    int oldValue=0;
    bool state;
    MyMessage msg(2,V_LIGHT);
    MyMessage msg2;
    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);
    void setup() {
    void presentation()  
      // Send the sketch version information to the gateway and Controller
      sendSketchInfo("Relay", "1.0");
      for (int sensor=1, pin=RELAY_1; sensor<=NUMBER_OF_RELAYS;sensor++, pin++) {
        // Register all sensors to gw (they will be created as child devices)
        present(sensor, S_LIGHT);
    void loop() 
       long double temp = (millis() - last_heartbeat_time);
      if (temp > HEARTBEAT_TIME) {
      // If it exceeds the heartbeat time then send a heartbeat
      last_heartbeat_time = millis();
      Serial.println("Sent heartbeat" );
    void receive(const MyMessage &message) {
      // We only expect one type of message from controller. But we better check anyway.
      if (message.type==V_LIGHT) {
         // 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(", New status: ");
         msg2 = message;

    but state is send only for one switch (second) and when i try to change switch 1 - this change is send aslo as relay 2. I added msg2 for export message from recieve to loop.

    How to send status for both relays as heartbeat?

  • Hardware Contributor

    @seal - sorry to say, this is a known problem in Domoticz. Is it a feature or is it a bug - depends on who you ask.
    This was just up:

    This is me asking in DOmoticz forum: