<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Energy Monitoring]]></title><description><![CDATA[<p dir="auto">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.</p>
<p dir="auto">This is the sketch:</p>
<pre><code>/**
 * 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 &lt;henrik.ekblad@mysensors.org&gt;
 * 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 &lt;SPI.h&gt;
#include &lt;MySensor.h&gt;  
#include &lt;MyTransportRFM69.h&gt;
#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);
}


</code></pre>
]]></description><link>https://forum.mysensors.org/topic/2120/energy-monitoring</link><generator>RSS for Node</generator><lastBuildDate>Wed, 20 May 2026 23:07:25 GMT</lastBuildDate><atom:link href="https://forum.mysensors.org/topic/2120.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 06 Oct 2015 15:59:43 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Energy Monitoring on Fri, 09 Oct 2015 11:57:40 GMT]]></title><description><![CDATA[<p dir="auto">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.</p>
]]></description><link>https://forum.mysensors.org/post/22505</link><guid isPermaLink="true">https://forum.mysensors.org/post/22505</guid><dc:creator><![CDATA[Cliff Karlsson]]></dc:creator><pubDate>Fri, 09 Oct 2015 11:57:40 GMT</pubDate></item><item><title><![CDATA[Reply to Energy Monitoring on Wed, 07 Oct 2015 19:09:30 GMT]]></title><description><![CDATA[<p dir="auto">I found a post at the domoticz forum where the same problem was described. He managed to solve it by doing this:</p>
<pre><code>"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?"

</code></pre>
<p dir="auto">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.</p>
<p dir="auto">When running the "stock" sketch from <a href="http://mysensors.org" rel="nofollow ugc">mysensors.org</a> I get this in my domotic log:</p>
<pre><code>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)
</code></pre>
<p dir="auto">It looks a little bit weird that it presents itself three times in a row.</p>
]]></description><link>https://forum.mysensors.org/post/22389</link><guid isPermaLink="true">https://forum.mysensors.org/post/22389</guid><dc:creator><![CDATA[Cliff Karlsson]]></dc:creator><pubDate>Wed, 07 Oct 2015 19:09:30 GMT</pubDate></item><item><title><![CDATA[Reply to Energy Monitoring on Wed, 07 Oct 2015 11:24:21 GMT]]></title><description><![CDATA[<p dir="auto">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.</p>
<pre><code>/**
 * 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 &lt;henrik.ekblad@mysensors.org&gt;
 * 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 &lt;SPI.h&gt;
#include &lt;MySensor.h&gt;  

#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 &gt; SEND_FREQUENCY;
  if (pcReceived &amp;&amp; (SLEEP_MODE || sendTime)) {
    // New watt value has been calculated  
    if (!SLEEP_MODE &amp;&amp; watt != oldWatt) {
      // Check that we dont get unresonable large watt value. 
      // could hapen when long wraps or false interrupt triggered
      if (watt&lt;((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 &amp;&amp; !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 &amp;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&lt;10000L) { // Sometimes we get interrupt on RISING
      return;
    }
    watt = (3600000000.0 /interval) / ppwh;
    lastBlink = newBlink;
  } 
  pulseCount++;
}


</code></pre>
]]></description><link>https://forum.mysensors.org/post/22368</link><guid isPermaLink="true">https://forum.mysensors.org/post/22368</guid><dc:creator><![CDATA[Cliff Karlsson]]></dc:creator><pubDate>Wed, 07 Oct 2015 11:24:21 GMT</pubDate></item><item><title><![CDATA[Reply to Energy Monitoring on Tue, 06 Oct 2015 16:20:50 GMT]]></title><description><![CDATA[<p dir="auto">Ah, don't know how I could have missed it.</p>
<p dir="auto">[<a href="http://www.mysensors.org/build/pulse_power" rel="nofollow ugc">http://www.mysensors.org/build/pulse_power</a>](Power meter pulse sensor)</p>
]]></description><link>https://forum.mysensors.org/post/22336</link><guid isPermaLink="true">https://forum.mysensors.org/post/22336</guid><dc:creator><![CDATA[Cliff Karlsson]]></dc:creator><pubDate>Tue, 06 Oct 2015 16:20:50 GMT</pubDate></item></channel></rss>