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. Announcements
  3. 💬 Power Meter Pulse Sensor

💬 Power Meter Pulse Sensor

Scheduled Pinned Locked Moved Announcements
183 Posts 40 Posters 45.0k Views 37 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.
  • gohanG Offline
    gohanG Offline
    gohan
    Mod
    wrote on last edited by
    #115

    Here is the log I get from node

    7230 TSF:MSG:READ,0-0-250,s=1,c=2,t=24,pt=0,l=7,sg=0:1682675
    rece
    
    Received last pulse count from gw:1682675
    
    11817 TSF:MSG:SEND,250-250-0-0,s=1,c=1,t=17,pt=5,l=4,sg=0,ft=0,st=OK:528
    Watt:528
    
    Watt:197065
    
    21820 TSF:MSG:SEND,250-250-0-0,s=1,c=1,t=24,pt=5,l=4,sg=0,ft=0,st=OK:1682677
    21913 TSF:MSG:SEND,250-250-0-0,s=1,c=1,t=18,pt=7,l=5,sg=0,ft=0,st=OK:1682.6770
    Watt:196807
    
    36824 TSF:MSG:SEND,250-250-0-0,s=1,c=1,t=24,pt=5,l=4,sg=0,ft=0,st=OK:1682679
    36917 TSF:MSG:SEND,250-250-0-0,s=1,c=1,t=18,pt=7,l=5,sg=0,ft=0,st=OK:1682.6790
    Watt:197368
    
    51827 TSF:MSG:SEND,250-250-0-0,s=1,c=1,t=24,pt=5,l=4,sg=0,ft=0,st=OK:1682681
    51920 TSF:MSG:SEND,250-250-0-0,s=1,c=1,t=18,pt=7,l=5,sg=0,ft=0,st=OK:1682.6810
    Watt:196850
    

    Am I the only one using this sketch?

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mickecarlsson
      wrote on last edited by
      #116

      Please post you sketch.

      1 Reply Last reply
      0
      • gohanG Offline
        gohanG Offline
        gohan
        Mod
        wrote on last edited by
        #117

        it is the one in https://www.mysensors.org/build/pulse_power

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mickecarlsson
          wrote on last edited by mickecarlsson
          #118

          How is the pulse counter set up? Is it connected to the S0 port?
          Edit:
          If you are using S0 it is vital that you use a pull down resistor, if you dont’t have that you get false pulses.
          pulse connection

          1 Reply Last reply
          0
          • gohanG Offline
            gohanG Offline
            gohan
            Mod
            wrote on last edited by
            #119

            I'm using the lm393 light detector. Domoticz is able to do a calculation from the pulses to give a Watt value and it is correct but it does it every 5 minutes and it is too slow for me

            sundberg84S 1 Reply Last reply
            0
            • gohanG gohan

              I'm using the lm393 light detector. Domoticz is able to do a calculation from the pulses to give a Watt value and it is correct but it does it every 5 minutes and it is too slow for me

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

              @gohan - is Domoticz updating anything (except switches) faster than 5 min? I dont think so...

              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

              S 1 Reply Last reply
              2
              • gohanG Offline
                gohanG Offline
                gohan
                Mod
                wrote on last edited by
                #121

                If you send the watt reading faster it updates like the switch, anyway I need the watt values for node-red also

                1 Reply Last reply
                0
                • gohanG Offline
                  gohanG Offline
                  gohan
                  Mod
                  wrote on last edited by
                  #122

                  Could it be the Light sensor is triggering more interrupts from each pulse?

                  1 Reply Last reply
                  0
                  • NiklasON NiklasO

                    Just changed from 1-wire counter to MySensors for logging my power consumption. Using the same LED detector as I did when using 1-wire. Also changed watt limit to 20 000 (my heat pump likes to use 9-10kW sometimes). The wires from the old 1-wire net now provide power for the new MySensors-sensor. I have 10 000 led blinks per kWh. Had som crazy counter values with 1-wire that totally messed up the graphs and haven't seen anything like that with this sketch. Let's hope it stays that way. ;) Dumping data to Domoticz. This sensor gives me higher resolution as a bonus. The 1-wire counter was read every minute, this every 20-sec. ;-)

                    0_1490286464866_Domoticz_-_Google_Chrome_2017-03-23_17-27-32_78641890.png

                    0_1490286540285_Domoticz_-_Google_Chrome_2017-03-23_17-28-46_94994234.png

                    My old 1-wire counter with one crazy value messing upp all the graphs:
                    0_1490286637201_Domoticz_-_Google_Chrome_2017-03-23_17-30-09_29365468.png
                    I know that you can hold shift and click the value that is crazy to make the graphs show up good but you loose the data for the full day. That's not good. ;-)

                    henninneH Offline
                    henninneH Offline
                    henninne
                    wrote on last edited by
                    #123

                    @niklaso

                    Hi Niklas,

                    I know this is a very old post, but its worth a try. How did you get out the daily Kwh usage? As default my sensor only gives Watts and Kwh (accumulated from start), I have tried to run a Scene in Vera UI7 where there are a function in the sensor called resetKWh(), but it looks like it doesn't do anything. Any tips would be great, thanks.

                    Henning

                    1 Reply Last reply
                    0
                    • sundberg84S sundberg84

                      @gohan - is Domoticz updating anything (except switches) faster than 5 min? I dont think so...

                      S Offline
                      S Offline
                      smilvert
                      wrote on last edited by
                      #124

                      @gohan I think it is a little tricky to update domoticz every minute but try update the sql-file, see the domoticz forum
                      https://www.domoticz.com/forum/viewtopic.php?t=10183

                      1 Reply Last reply
                      0
                      • gohanG Offline
                        gohanG Offline
                        gohan
                        Mod
                        wrote on last edited by
                        #125

                        The main issue is the fact that the sensor is not calculating the instant power correctly

                        xydixX 1 Reply Last reply
                        0
                        • D Offline
                          D Offline
                          DaTim69
                          wrote on last edited by
                          #126

                          I created this kWh sensor with the TCRT5000 IR Barrier Line Track Sensor.
                          My powermeter is a ferarrismeter with 375 rotations per kWh.
                          I also had the problem with spikes in the power usage. But after long...too long investigation I solved the problem.
                          At my config it was a double issue.

                          Issue 1.
                          The problem is the pulse width of the rotation.
                          The pulse are at night ( low power) much wider that during the day when more power is consumed. At night the spikes in power usage where huge.

                          Issue 2.
                          Switching on/off the halogen light causes spikes and related to also strange power measurement.

                          Solution:
                          I added a second arduino mini pro as a pulse regulator between the TCRT5000 and the power meter arduino.
                          this arduino triggers on Rising and will always give a 100ms puls. Als debounce is handled (spikes).
                          I don't upload the sketch here, I'm a beginning programmer on arduino. It's made on " trail and error" but it functions as it supposed to do.
                          If someone wants a copy feel free to contact mee

                          1 Reply Last reply
                          1
                          • gohanG gohan

                            The main issue is the fact that the sensor is not calculating the instant power correctly

                            xydixX Offline
                            xydixX Offline
                            xydix
                            wrote on last edited by
                            #127

                            @gohan Did you solve this?
                            I get very high watt usage as well. Sometimes like 40 000 - 130 000 watt if I check the serial monitor.
                            Of course, those values will never be sent to the controler.

                            1 Reply Last reply
                            0
                            • gohanG Offline
                              gohanG Offline
                              gohan
                              Mod
                              wrote on last edited by
                              #128

                              Nope, I am looking at other things now. Very little time available for too many things. I'm looking at buying CT clamp and do a more direct measurement.

                              1 Reply Last reply
                              0
                              • xydixX Offline
                                xydixX Offline
                                xydix
                                wrote on last edited by xydix
                                #129

                                Okay. Really annoying. Check this.

                                Received last pulse count from gw:2527
                                Watt:121065
                                22235 TSF:MSG:SEND,78-78-0-0,s=3,c=1,t=24,pt=5,l=4,sg=0,ft=0,st=OK:2539
                                22246 TSF:MSG:SEND,78-78-0-0,s=2,c=1,t=18,pt=7,l=5,sg=0,ft=0,st=OK:2.5390
                                Watt:121621
                                42238 TSF:MSG:SEND,78-78-0-0,s=3,c=1,t=24,pt=5,l=4,sg=0,ft=0,st=OK:2551
                                42250 TSF:MSG:SEND,78-78-0-0,s=2,c=1,t=18,pt=7,l=5,sg=0,ft=0,st=OK:2.5510
                                Watt:121342
                                62239 TSF:MSG:SEND,78-78-0-0,s=3,c=1,t=24,pt=5,l=4,sg=0,ft=0,st=OK:2563
                                62251 TSF:MSG:SEND,78-78-0-0,s=2,c=1,t=18,pt=7,l=5,sg=0,ft=0,st=OK:2.5630
                                Watt:121539
                                82240 TSF:MSG:SEND,78-78-0-0,s=3,c=1,t=24,pt=5,l=4,sg=0,ft=0,st=OK:2575
                                82251 TSF:MSG:SEND,78-78-0-0,s=2,c=1,t=18,pt=7,l=5,sg=0,ft=0,st=OK:2.5750
                                Watt:121951
                                102239 TSF:MSG:SEND,78-78-0-0,s=3,c=1,t=24,pt=5,l=4,sg=0,ft=0,st=OK:2589
                                102250 TSF:MSG:SEND,78-78-0-0,s=2,c=1,t=18,pt=7,l=5,sg=0,ft=0,st=OK:2.5890
                                Watt:122067
                                122243 TSF:MSG:SEND,78-78-0-0,s=3,c=1,t=24,pt=5,l=4,sg=0,ft=0,st=OK:2601
                                122254 TSF:MSG:SEND,78-78-0-0,s=2,c=1,t=18,pt=7,l=5,sg=0,ft=0,st=OK:2.6010
                                

                                The plus count seems OK, right?

                                My energy meter is 1000 pluses /kwh

                                Here is my sketch. I use Home assistant so i created three sensors for this as I don't think V_VAR1 is supported with S_POWER.
                                Otherwise it is the standard example.

                                /**
                                 * 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
                                 */
                                
                                // Enable debug prints
                                #define MY_DEBUG
                                
                                // Enable and select radio type attached
                                #define MY_RADIO_NRF24
                                //#define MY_RADIO_RFM69
                                #define MY_NODE_ID 78
                                #include <MySensors.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 20000          // Max watt value to report. This filetrs outliers.
                                #define WATT_CHILD_ID 1              // Id of the sensor child
                                #define KWH_CHILD_ID 2
                                #define PC_CHILD_ID 3
                                
                                unsigned long SEND_FREQUENCY =
                                    20000; // Minimum time between send (in milliseconds). We don't wnat to spam the gateway.
                                double ppwh = ((double)PULSE_FACTOR)/1000; // Pulses per watt hour
                                bool 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(WATT_CHILD_ID,V_WATT);
                                MyMessage kwhMsg(KWH_CHILD_ID,V_KWH);
                                MyMessage pcMsg(PC_CHILD_ID,V_VAR1);
                                
                                
                                void setup()
                                {
                                  // Fetch last known pulse count value from gw
                                  request(PC_CHILD_ID, V_VAR1);
                                
                                  // Use the internal pullup to be able to hook up this sketch directly to an energy meter with S0 output
                                  // If no pullup is used, the reported usage will be too high because of the floating pin
                                  pinMode(DIGITAL_INPUT_SENSOR,INPUT_PULLUP);
                                
                                  attachInterrupt(digitalPinToInterrupt(DIGITAL_INPUT_SENSOR), onPulse, RISING);
                                  lastSend=millis();
                                }
                                
                                void presentation()
                                {
                                  // Send the sketch version information to the gateway and Controller
                                  sendSketchInfo("Energy Meter", "1.0");
                                
                                  // Register this device as power sensor
                                  present(WATT_CHILD_ID, S_POWER);
                                  present(KWH_CHILD_ID, S_POWER);
                                  present(PC_CHILD_ID, S_CUSTOM);
                                }
                                
                                void loop()
                                {
                                  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)) {
                                        send(wattMsg.set(watt));  // Send watt value to gw
                                      }
                                      Serial.print("Watt:");
                                      Serial.println(watt);
                                      oldWatt = watt;
                                    }
                                
                                    // Pulse cout has changed
                                    if (pulseCount != oldPulseCount) {
                                      send(pcMsg.set(pulseCount));  // Send pulse count value to gw
                                      double kwh = ((double)pulseCount/((double)PULSE_FACTOR));
                                      oldPulseCount = pulseCount;
                                      if (kwh != oldKwh) {
                                        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
                                    request(PC_CHILD_ID, V_VAR1);
                                    lastSend=now;
                                  }
                                
                                  if (SLEEP_MODE) {
                                    sleep(SEND_FREQUENCY);
                                  }
                                }
                                
                                void receive(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++;
                                }
                                
                                

                                Anyone got any ideas?
                                BTW. First i tried the original example sketch, unmodified, with the same result.

                                1 Reply Last reply
                                0
                                • gohanG Offline
                                  gohanG Offline
                                  gohan
                                  Mod
                                  wrote on last edited by
                                  #130

                                  That's pretty much the same problem as I have

                                  1 Reply Last reply
                                  0
                                  • xydixX Offline
                                    xydixX Offline
                                    xydix
                                    wrote on last edited by
                                    #131

                                    I think i solved this.
                                    I don't know if it is a good solution.
                                    Maybe it is possible to solve in the code?
                                    I added a 0,1uf ceramic capacitor between DO and GND on the LM393.
                                    Then i tuned the LM393 until i had it blink as expected.

                                    I think, in my case the LED pulse from my meeter was to short, it gives a very short blink.
                                    Anyway.
                                    I tested it all day and it seems fine now.

                                    1 Reply Last reply
                                    0
                                    • gohanG Offline
                                      gohanG Offline
                                      gohan
                                      Mod
                                      wrote on last edited by
                                      #132

                                      Are you getting instant power measurements correct?

                                      1 Reply Last reply
                                      0
                                      • xydixX Offline
                                        xydixX Offline
                                        xydix
                                        wrote on last edited by xydix
                                        #133

                                        Yes. I guess.
                                        I don't have anything to compare with but i think it is accurate.
                                        I have a 1000blink/kwh
                                        Example:
                                        Node send state every 20 sec.
                                        pulsecount: 8 pulses every 20 sec.
                                        Instant power in W is about 1400W

                                        8 pulses x 3 = pulses /minute =24
                                        24 pulses x 60 min = pulses /hour = 1440.

                                        Edit.
                                        Now I get a new value every 20 sec, before I didn't get any value (W) from the node at all because it was too high. I only received pulse count and kWh earlier.

                                        1 Reply Last reply
                                        0
                                        • gohanG Offline
                                          gohanG Offline
                                          gohan
                                          Mod
                                          wrote on last edited by
                                          #134

                                          Besides the cap, what exactly did you do?

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


                                          10

                                          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