Skip to content
  • MySensors
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo
  1. Home
  2. Development
  3. Relay Actuator - send periodic status as heart beat.

Relay Actuator - send periodic status as heart beat.

Scheduled Pinned Locked Moved Development
3 Posts 3 Posters 2.6k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • sealS Offline
    sealS Offline
    seal
    wrote on last edited by seal
    #1

    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
    //#define MY_REPEATER_FEATURE
    
    #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
      sendHeartbeat();
      send(msg.set(msg2.getBool()?1:0)); 
      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(message.sensor);
         Serial.print(", New status: ");
         Serial.println(message.getBool());
         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?

    sundberg84S 1 Reply Last reply
    0
    • sealS seal

      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
      //#define MY_REPEATER_FEATURE
      
      #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
        sendHeartbeat();
        send(msg.set(msg2.getBool()?1:0)); 
        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(message.sensor);
           Serial.print(", New status: ");
           Serial.println(message.getBool());
           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?

      sundberg84S Offline
      sundberg84S Offline
      sundberg84
      Hardware Contributor
      wrote on last edited by sundberg84
      #2

      @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: https://forum.mysensors.org/topic/7806/error-customercounter-hardware-12-nothing-received-for-more-than-5-minutes.

      This is me asking in DOmoticz forum: https://www.domoticz.com/forum/viewtopic.php?f=42&t=9775

      Controller: Proxmox VM - Home Assistant
      MySensors GW: Arduino Uno - W5100 Ethernet, Gw Shield Nrf24l01+ 2,4Ghz
      MySensors GW: Arduino Uno - Gw Shield RFM69, 433mhz
      RFLink GW - Arduino Mega + RFLink Shield, 433mhz

      1 Reply Last reply
      0
      • D Offline
        D Offline
        Denis Renaud
        wrote on last edited by
        #3

        Hi, yout post is quit old but I changed your code a bit. Now it sends the status of both relays:

        long double last_heartbeat_time = millis();
        long double HEARTBEAT_TIME = 30000;
        
        int oldValue = 0;
        bool state;
        
        MyMessage msg1a(1, V_STATUS);
        MyMessage msg1b;
        
        MyMessage msg2a(2, V_STATUS);
        MyMessage msg2b;
        
        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_BINARY);
          }
        }
        
        
        void loop()
        {
          long double temp = (millis() - last_heartbeat_time);
          if (temp > HEARTBEAT_TIME) {
            // If it exceeds the heartbeat time then send a heartbeat
            sendHeartbeat();
            send(msg1a.set(msg1b.getBool() ? 1 : 0));
            send(msg2a.set(msg2b.getBool() ? 1 : 0));
            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_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());
        
            if (message.sensor == 1) {
              msg1b = message;
            }
        
            if (message.sensor == 2) {
              msg2b = message;
            }
        
          }
        }
        

        rg Denis

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        14

        Online

        11.7k

        Users

        11.2k

        Topics

        113.0k

        Posts


        Copyright 2019 TBD   |   Forum Guidelines   |   Privacy Policy   |   Terms of Service
        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • MySensors
        • OpenHardware.io
        • Categories
        • Recent
        • Tags
        • Popular