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. Troubleshooting
  3. Energy Monitoring

Energy Monitoring

Scheduled Pinned Locked Moved Troubleshooting
5 Posts 1 Posters 2.6k Views 1 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.
  • Cliff KarlssonC Offline
    Cliff KarlssonC Offline
    Cliff Karlsson
    wrote on last edited by
    #1

    I want to use the LM393 sketch to monitor the pulses of my Power meter. But how do I make it register every blink? I still have not figured out how to make a sensor wake up instead of just using sleep.

    This is the sketch:

    /**
     * The MySensors Arduino library handles the wireless radio link and protocol
     * between your home built sensors/actuators and HA controller of choice.
     * The sensors forms a self healing radio network with optional repeaters. Each
     * repeater and gateway builds a routing tables in EEPROM which keeps track of the
     * network topology allowing messages to be routed to nodes.
     *
     * Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
     * Copyright (C) 2013-2015 Sensnology AB
     * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
     *
     * Documentation: http://www.mysensors.org
     * Support Forum: http://forum.mysensors.org
     *
     * This program is free software; you can redistribute it and/or
     * modify it under the terms of the GNU General Public License
     * version 2 as published by the Free Software Foundation.
     *
     *******************************
     *
     * REVISION HISTORY
     * Version 1.0 - Henrik EKblad
     * 
     * DESCRIPTION
     * Example sketch showing how to measue light level using a LM393 photo-resistor 
     * http://www.mysensors.org/build/light
     */
    
    #include <SPI.h>
    #include <MySensor.h>  
    #include <MyTransportRFM69.h>
    #define CHILD_ID_LIGHT 0
    #define LIGHT_SENSOR_ANALOG_PIN 0
    
    unsigned long SLEEP_TIME = 30000; // Sleep time between reads (in milliseconds)
    MyTransportRFM69 transport(RFM69_FREQUENCY, RFM69_NETWORKID, RF69_SPI_CS, RF69_IRQ_PIN, false, RF69_IRQ_NUM);
    MySensor gw(transport);
    MyMessage msg(CHILD_ID_LIGHT, V_LIGHT_LEVEL);
    int lastLightLevel;
    
    void setup()  
    { 
      gw.begin();
    
      // Send the sketch version information to the gateway and Controller
      gw.sendSketchInfo("Light Sensor", "1.0");
    
      // Register all sensors to gateway (they will be created as child devices)
      gw.present(CHILD_ID_LIGHT, S_LIGHT_LEVEL);
    }
    
    void loop()      
    {     
      int lightLevel = (1023-analogRead(LIGHT_SENSOR_ANALOG_PIN))/10.23; 
      Serial.println(lightLevel);
      if (lightLevel != lastLightLevel) {
          gw.send(msg.set(lightLevel));
          lastLightLevel = lightLevel;
      }
      gw.sleep(SLEEP_TIME);
    }
    
    
    
    1 Reply Last reply
    0
    • Cliff KarlssonC Offline
      Cliff KarlssonC Offline
      Cliff Karlsson
      wrote on last edited by
      #2

      Ah, don't know how I could have missed it.

      [http://www.mysensors.org/build/pulse_power](Power meter pulse sensor)

      1 Reply Last reply
      0
      • Cliff KarlssonC Offline
        Cliff KarlssonC Offline
        Cliff Karlsson
        wrote on last edited by Cliff Karlsson
        #3

        Can't get it to work. The sensor detects the power meter blinks and is presented as Energy monitor in the domoticz log. But it does not show under devices.

        /**
         * The MySensors Arduino library handles the wireless radio link and protocol
         * between your home built sensors/actuators and HA controller of choice.
         * The sensors forms a self healing radio network with optional repeaters. Each
         * repeater and gateway builds a routing tables in EEPROM which keeps track of the
         * network topology allowing messages to be routed to nodes.
         *
         * Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
         * Copyright (C) 2013-2015 Sensnology AB
         * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
         *
         * Documentation: http://www.mysensors.org
         * Support Forum: http://forum.mysensors.org
         *
         * This program is free software; you can redistribute it and/or
         * modify it under the terms of the GNU General Public License
         * version 2 as published by the Free Software Foundation.
         *
         *******************************
         *
         * REVISION HISTORY
         * Version 1.0 - Henrik EKblad
         * 
         * DESCRIPTION
         * This sketch provides an example how to implement a distance sensor using HC-SR04 
         * Use this sensor to measure KWH and Watt of your house meeter
         * You need to set the correct pulsefactor of your meeter (blinks per KWH).
         * The sensor starts by fetching current KWH value from gateway.
         * Reports both KWH and Watt back to gateway.
         *
         * Unfortunately millis() won't increment when the Arduino is in 
         * sleepmode. So we cannot make this sensor sleep if we also want 
         * to calculate/report watt-number.
         * http://www.mysensors.org/build/pulse_power
         */
        
        #include <SPI.h>
        #include <MySensor.h>  
        
        #define DIGITAL_INPUT_SENSOR 3  // The digital input you attached your light sensor.  (Only 2 and 3 generates interrupt!)
        #define PULSE_FACTOR 1000       // Nummber of blinks per KWH of your meeter
        #define SLEEP_MODE false        // Watt-value can only be reported when sleep mode is false.
        #define MAX_WATT 10000          // Max watt value to report. This filetrs outliers.
        #define INTERRUPT DIGITAL_INPUT_SENSOR-2 // Usually the interrupt = pin -2 (on uno/nano anyway)
        #define CHILD_ID 1              // Id of the sensor child
        unsigned long SEND_FREQUENCY = 20000; // Minimum time between send (in milliseconds). We don't wnat to spam the gateway.
        MySensor gw;
        double ppwh = ((double)PULSE_FACTOR)/1000; // Pulses per watt hour
        boolean pcReceived = false;
        volatile unsigned long pulseCount = 0;   
        volatile unsigned long lastBlink = 0;
        volatile unsigned long watt = 0;
        unsigned long oldPulseCount = 0;   
        unsigned long oldWatt = 0;
        double oldKwh;
        unsigned long lastSend;
        MyMessage wattMsg(CHILD_ID,V_WATT);
        MyMessage kwhMsg(CHILD_ID,V_KWH);
        MyMessage pcMsg(CHILD_ID,V_VAR1);
        
        
        void setup()  
        {  
          gw.begin(incomingMessage);
        
          // Send the sketch version information to the gateway and Controller
          gw.sendSketchInfo("Energy Meter", "1.0");
        
          // Register this device as power sensor
          gw.present(CHILD_ID, S_POWER);
        
          // Fetch last known pulse count value from gw
          gw.request(CHILD_ID, V_VAR1);
          
          attachInterrupt(INTERRUPT, onPulse, RISING);
          lastSend=millis();
        }
        
        
        void loop()     
        { 
          gw.process();
          unsigned long now = millis();
          // Only send values at a maximum frequency or woken up from sleep
          bool sendTime = now - lastSend > SEND_FREQUENCY;
          if (pcReceived && (SLEEP_MODE || sendTime)) {
            // New watt value has been calculated  
            if (!SLEEP_MODE && watt != oldWatt) {
              // Check that we dont get unresonable large watt value. 
              // could hapen when long wraps or false interrupt triggered
              if (watt<((unsigned long)MAX_WATT)) {
                gw.send(wattMsg.set(watt));  // Send watt value to gw 
              }  
              Serial.print("Watt:");
              Serial.println(watt);
              oldWatt = watt;
            }
          
            // Pulse cout has changed
            if (pulseCount != oldPulseCount) {
              gw.send(pcMsg.set(pulseCount));  // Send pulse count value to gw 
              double kwh = ((double)pulseCount/((double)PULSE_FACTOR));     
              oldPulseCount = pulseCount;
              if (kwh != oldKwh) {
                gw.send(kwhMsg.set(kwh, 4));  // Send kwh value to gw 
                oldKwh = kwh;
              }
            }    
            lastSend = now;
          } else if (sendTime && !pcReceived) {
            // No count received. Try requesting it again
            gw.request(CHILD_ID, V_VAR1);
            lastSend=now;
          }
          
          if (SLEEP_MODE) {
            gw.sleep(SEND_FREQUENCY);
          }
        }
        
        void incomingMessage(const MyMessage &message) {
          if (message.type==V_VAR1) {  
            pulseCount = oldPulseCount = message.getLong();
            Serial.print("Received last pulse count from gw:");
            Serial.println(pulseCount);
            pcReceived = true;
          }
        }
        
        void onPulse()     
        { 
          if (!SLEEP_MODE) {
            unsigned long newBlink = micros();  
            unsigned long interval = newBlink-lastBlink;
            if (interval<10000L) { // Sometimes we get interrupt on RISING
              return;
            }
            watt = (3600000000.0 /interval) / ppwh;
            lastBlink = newBlink;
          } 
          pulseCount++;
        }
        
        
        
        1 Reply Last reply
        0
        • Cliff KarlssonC Offline
          Cliff KarlssonC Offline
          Cliff Karlsson
          wrote on last edited by Cliff Karlsson
          #4

          I found a post at the domoticz forum where the same problem was described. He managed to solve it by doing this:

          "To have my software send something I removed those parts which check for sending frequency and also identity of values.
          I now send whenever a pulse occurs (which is every 20 to 120 seconds, depending). My network is rather small so far and
          my energy meter is using a power adapter so that should be no problem. How often do others update their Watt values?"
          
          

          But what parts do I need to delete? I tried to remove most stuff regarding to frequenzy but could not get it to complie after my tests.

          When running the "stock" sketch from mysensors.org I get this in my domotic log:

          2015-10-07 20:47:26.030 Hardware Monitor: Fetching data (System sensors)
          2015-10-07 20:47:56.166 Hardware Monitor: Fetching data (System sensors)
          2015-10-07 20:48:26.302 Hardware Monitor: Fetching data (System sensors)
          2015-10-07 20:48:56.437 Hardware Monitor: Fetching data (System sensors)
          2015-10-07 20:49:26.571 Hardware Monitor: Fetching data (System sensors)
          2015-10-07 20:49:48.781 MySensors: Node: 7, Sketch Name: Energy Meter
          2015-10-07 20:49:48.825 MySensors: Node: 7, Sketch Name: Energy Meter
          2015-10-07 20:49:48.870 MySensors: Node: 7, Sketch Name: Energy Meter
          2015-10-07 20:49:48.919 MySensors: Node: 7, Sketch Version: 1.0
          2015-10-07 20:49:48.963 MySensors: Node: 7, Sketch Version: 1.0
          2015-10-07 20:49:49.007 MySensors: Node: 7, Sketch Version: 1.0
          2015-10-07 20:49:56.783 Hardware Monitor: Fetching data (System sensors)
          2015-10-07 20:50:26.917 Hardware Monitor: Fetching data (System sensors)
          

          It looks a little bit weird that it presents itself three times in a row.

          1 Reply Last reply
          0
          • Cliff KarlssonC Offline
            Cliff KarlssonC Offline
            Cliff Karlsson
            wrote on last edited by
            #5

            Sorry for spamming but I solved the problem. The Original sketch was fine. I removed the radio and resoldered it (RFM69W) And then everything was Ok. There must have been some bad connecton as the sketch sent 3x greeting message.

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


            20

            Online

            11.7k

            Users

            11.2k

            Topics

            113.1k

            Posts


            Copyright 2025 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