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.
  • moumout31M moumout31

    @flopp After a few days, I confirm you that the index is consistent with power meter index.
    However, instant power in watt is not correcly calculated.
    For example, when power meter indicates 550W, about 1500W is calculated by the sketch. Do you know how I can resolve this problem please ?

    Thanks a lot !

    F Offline
    F Offline
    flopp
    wrote on last edited by
    #77

    @moumout31
    Watt calculation is using time between two interrupts.
    How often do you send watt?
    Did you measure watt with a measurement tool How did you get 500 watts from power meter?
    When you send watt you need to measure exact same second otherwise it will not be correct.

    moumout31M 1 Reply Last reply
    0
    • F flopp

      @moumout31
      Watt calculation is using time between two interrupts.
      How often do you send watt?
      Did you measure watt with a measurement tool How did you get 500 watts from power meter?
      When you send watt you need to measure exact same second otherwise it will not be correct.

      moumout31M Offline
      moumout31M Offline
      moumout31
      wrote on last edited by
      #78

      @flopp Watt is sent every 20 seconds (as done in the original sketch).
      500 watts is the power indicated on the screen of the power meter.

      1 Reply Last reply
      0
      • NiklasON Offline
        NiklasON Offline
        NiklasO
        wrote on last edited by NiklasO
        #79

        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 1 Reply Last reply
        0
        • S Offline
          S Offline
          Samuel235
          Hardware Contributor
          wrote on last edited by
          #80

          I seem to be getting a connection to my gateway, while monitoring the two topics for the gateway i only seem to see any activity regarding this sensor on the gateway-out topic, and it keeps sending out a type 2 message (req). The serial monitor of the sensors is showing:

          104198 TSF:MSG:SEND,16-16-0-0,s=1,c=2,t=24,pt=0,l=0,sg=0,ft=0,st=OK:
          114199 TSF:MSG:SEND,16-16-0-0,s=1,c=2,t=24,pt=0,l=0,sg=0,ft=0,st=OK:
          124200 TSF:MSG:SEND,16-16-0-0,s=1,c=2,t=24,pt=0,l=0,sg=0,ft=0,st=OK:
          134201 TSF:MSG:SEND,16-16-0-0,s=1,c=2,t=24,pt=0,l=0,sg=0,ft=0,st=OK:
          144202 TSF:MSG:SEND,16-16-0-0,s=1,c=2,t=24,pt=0,l=0,sg=0,ft=0,st=OK:
          154203 TSF:MSG:SEND,16-16-0-0,s=1,c=2,t=24,pt=0,l=0,sg=0,ft=0,st=OK:
          164204 TSF:MSG:SEND,16-16-0-0,s=1,c=2,t=24,pt=0,l=0,sg=0,ft=0,st=OK:
          174205 TSF:MSG:SEND,16-16-0-0,s=1,c=2,t=24,pt=0,l=0,sg=0,ft=0,st=OK:
          184206 TSF:MSG:SEND,16-16-0-0,s=1,c=2,t=24,pt=0,l=0,sg=0,ft=0,st=OK:
          194207 TSF:MSG:SEND,16-16-0-0,s=1,c=2,t=24,pt=0,l=0,sg=0,ft=0,st=OK:

          So it seems to be sending a request package, but i don't see it on the gateway-in topic and i see other sensors sending data to the gateway-in topic so i'm not subscribed to the wrong one. Is this a structural request message or is this the feature that requests the last known message from the gateway? Either way, there doesn't seem to be any sensor data being sent from the node to the gateway.

          sundberg84S 1 Reply Last reply
          0
          • S Samuel235

            I seem to be getting a connection to my gateway, while monitoring the two topics for the gateway i only seem to see any activity regarding this sensor on the gateway-out topic, and it keeps sending out a type 2 message (req). The serial monitor of the sensors is showing:

            104198 TSF:MSG:SEND,16-16-0-0,s=1,c=2,t=24,pt=0,l=0,sg=0,ft=0,st=OK:
            114199 TSF:MSG:SEND,16-16-0-0,s=1,c=2,t=24,pt=0,l=0,sg=0,ft=0,st=OK:
            124200 TSF:MSG:SEND,16-16-0-0,s=1,c=2,t=24,pt=0,l=0,sg=0,ft=0,st=OK:
            134201 TSF:MSG:SEND,16-16-0-0,s=1,c=2,t=24,pt=0,l=0,sg=0,ft=0,st=OK:
            144202 TSF:MSG:SEND,16-16-0-0,s=1,c=2,t=24,pt=0,l=0,sg=0,ft=0,st=OK:
            154203 TSF:MSG:SEND,16-16-0-0,s=1,c=2,t=24,pt=0,l=0,sg=0,ft=0,st=OK:
            164204 TSF:MSG:SEND,16-16-0-0,s=1,c=2,t=24,pt=0,l=0,sg=0,ft=0,st=OK:
            174205 TSF:MSG:SEND,16-16-0-0,s=1,c=2,t=24,pt=0,l=0,sg=0,ft=0,st=OK:
            184206 TSF:MSG:SEND,16-16-0-0,s=1,c=2,t=24,pt=0,l=0,sg=0,ft=0,st=OK:
            194207 TSF:MSG:SEND,16-16-0-0,s=1,c=2,t=24,pt=0,l=0,sg=0,ft=0,st=OK:

            So it seems to be sending a request package, but i don't see it on the gateway-in topic and i see other sensors sending data to the gateway-in topic so i'm not subscribed to the wrong one. Is this a structural request message or is this the feature that requests the last known message from the gateway? Either way, there doesn't seem to be any sensor data being sent from the node to the gateway.

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

            @Samuel235 said in 💬 Power Meter Pulse Sensor:

            164204 TSF:MSG:SEND,16-16-0-0,s=1,c=2,t=24,pt=0,l=0,sg=0,ft=0,st=OK:

            I dont know if I dont understand you, but it seems like your node is requesting the last pulse counter. I have mentioned this in several threads I have a problem with this (both this thread and rain sensor thread). Im using an ethernet gw and the request reaches the gw but there my error led blinks and it fails to send it back (or recieve it on the node) so it re-request it.

            I have never been able to pinpoint it due to repeaters in between.
            https://forum.mysensors.org/topic/2116/hard-to-grab-time-and-value-sent-from-controller/ (old).

            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
            1
            • sundberg84S sundberg84

              @Samuel235 said in 💬 Power Meter Pulse Sensor:

              164204 TSF:MSG:SEND,16-16-0-0,s=1,c=2,t=24,pt=0,l=0,sg=0,ft=0,st=OK:

              I dont know if I dont understand you, but it seems like your node is requesting the last pulse counter. I have mentioned this in several threads I have a problem with this (both this thread and rain sensor thread). Im using an ethernet gw and the request reaches the gw but there my error led blinks and it fails to send it back (or recieve it on the node) so it re-request it.

              I have never been able to pinpoint it due to repeaters in between.
              https://forum.mysensors.org/topic/2116/hard-to-grab-time-and-value-sent-from-controller/ (old).

              S Offline
              S Offline
              Samuel235
              Hardware Contributor
              wrote on last edited by
              #82

              @sundberg84 - You do understand me correctly :). I made a thread on the troubleshooting section of the forum for this simply because i suspected it was normal behaviour, however. It seems that the node isn't sending any other data to the gateway at all and it can not get the previous value as there isn't one. So, my post here and on the troubleshooting section was me aiming to get to this point and then troubleshoot the actual node to see what can be done to get it to send data.

              1 Reply Last reply
              0
              • S Offline
                S Offline
                Samuel235
                Hardware Contributor
                wrote on last edited by
                #83

                Has anyone came across their pulse meter not sending the message for WATT, the other two messages are being sent perfectly fine. My WATT message has been working all day and suddenly stopped.

                1 Reply Last reply
                0
                • NiklasON Offline
                  NiklasON Offline
                  NiklasO
                  wrote on last edited by
                  #84

                  Make sure that you don't reach your wattage limit in the sketch.

                  S 1 Reply Last reply
                  0
                  • NiklasON NiklasO

                    Make sure that you don't reach your wattage limit in the sketch.

                    S Offline
                    S Offline
                    Samuel235
                    Hardware Contributor
                    wrote on last edited by
                    #85

                    @NiklasO - Where is this value stored? I've cleared the EEPROM and the MQTT topic too, but it still refuses to send the watt value.

                    NiklasON 1 Reply Last reply
                    0
                    • S Samuel235

                      @NiklasO - Where is this value stored? I've cleared the EEPROM and the MQTT topic too, but it still refuses to send the watt value.

                      NiklasON Offline
                      NiklasON Offline
                      NiklasO
                      wrote on last edited by NiklasO
                      #86

                      @Samuel235
                      In the sketch, change this
                      #define MAX_WATT 10000 // Max watt value to report. This filetrs outliers.
                      I have it set to 20000, using 15 000 easily when it's cold outside. ;-) Just make sure that you use the right divider for your pulse/kWh count.

                      S 1 Reply Last reply
                      0
                      • NiklasON NiklasO

                        @Samuel235
                        In the sketch, change this
                        #define MAX_WATT 10000 // Max watt value to report. This filetrs outliers.
                        I have it set to 20000, using 15 000 easily when it's cold outside. ;-) Just make sure that you use the right divider for your pulse/kWh count.

                        S Offline
                        S Offline
                        Samuel235
                        Hardware Contributor
                        wrote on last edited by
                        #87

                        Ahh i see what it is it; its set to not send if it hasn't changed.... how much of a silly error that was from me. The wattage is way below 1000 but because i'm using a normal LED on another arduino flashing at a constant rate to set my node up, its not changing the watt value.

                        Back to solving my initial issue now >.<

                        Thank you.

                        1 Reply Last reply
                        1
                        • NiklasON Offline
                          NiklasON Offline
                          NiklasO
                          wrote on last edited by
                          #88

                          Ah, I see. Well, I would like the sensor to send data even if it hasn't changed. What did you change?

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

                            Watt usage is normally changing all the time, so you should have data reported quite often

                            NiklasON 1 Reply Last reply
                            0
                            • gohanG gohan

                              Watt usage is normally changing all the time, so you should have data reported quite often

                              NiklasON Offline
                              NiklasON Offline
                              NiklasO
                              wrote on last edited by NiklasO
                              #90

                              @gohan But Samuel235 had that problem? ;-) Edit: well, ok, he had a different setup. I need to read better. ;)

                              1 Reply Last reply
                              0
                              • S Offline
                                S Offline
                                Samuel235
                                Hardware Contributor
                                wrote on last edited by
                                #91

                                To be honest, i had it running for a while before it stopped sending the WATTS. But i'm guessing this is the issue as if i vary the blinks it sends it. I'de like to see if anyone has this working recently on OpenHAB through means of not touching the node sketch like people have posted before. I have an idea to send the data of the pulse count message onto the request message topic on MQTT and so then when it requests previous count it would have it.

                                M 1 Reply Last reply
                                0
                                • S Offline
                                  S Offline
                                  Samuel235
                                  Hardware Contributor
                                  wrote on last edited by Samuel235
                                  #92
                                  This post is deleted!
                                  1 Reply Last reply
                                  0
                                  • S Samuel235

                                    To be honest, i had it running for a while before it stopped sending the WATTS. But i'm guessing this is the issue as if i vary the blinks it sends it. I'de like to see if anyone has this working recently on OpenHAB through means of not touching the node sketch like people have posted before. I have an idea to send the data of the pulse count message onto the request message topic on MQTT and so then when it requests previous count it would have it.

                                    M Offline
                                    M Offline
                                    mickecarlsson
                                    wrote on last edited by mickecarlsson
                                    #93

                                    EDIT:
                                    This was not the case, I am still debugging the issue, in the mean time I have deleted the code.

                                    After some debugging it seems that Domoticz messes with the V_WATT and V_KWH, and the solution is to have two sensors, one for kWh and one for W.
                                    After I changed it, I have consistent W and kWh.
                                    See also this issue for Home Assistant

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

                                      OK, I think I have nailed it. I am now running a beta code pulling S0 from my energy meter and I am getting consistent results.
                                      Before when I checked the domoticz.db I got this for Energy:

                                      sqlite> select Name, sValue from DeviceStatus;
                                      Storage kWh|0.000;4773.700
                                      

                                      Now I get this:

                                      sqlite> select Name, sValue from DeviceStatus;
                                      Storage kWh|118.000;11678062.000
                                      

                                      Notice that the first field is now with value, previously it was 0.000 (and I have updated the meter count to the actual value)
                                      And in table Meter I now get consistent results:

                                      sqlite> SELECT Value, Usage, Date FROM Meter WHERE DeviceRowID=43;
                                      11678003|1170|2017-07-22 09:25:00
                                      11678012|1170|2017-07-22 09:30:00
                                      11678021|1180|2017-07-22 09:35:00
                                      11678031|1180|2017-07-22 09:40:00
                                      11678043|1170|2017-07-22 09:45:00
                                      11678053|1180|2017-07-22 09:50:00
                                      11678062|1180|2017-07-22 09:55:00
                                      11678072|1180|2017-07-22 10:00:00
                                      

                                      The field Usage is now populated as it should.
                                      I will let the code run for a couple of days, then I will post the updated code here.

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

                                        Here is a code example that works for me. I have an energy meter with S0 output and I use Domoticz as the controller.

                                        /**
                                         * 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
                                         * Version 1.1 - Mikael Carlsson
                                         *
                                         * DESCRIPTION
                                         * This sketch provides an example how to implement a sensor reading from an energy meter
                                         * 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
                                        
                                        #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 meter
                                        #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 filters bad data.
                                        #define CHILD_ID 1              // Id of the sensor child
                                        
                                        unsigned long SEND_FREQUENCY =
                                            20000; // Minimum time between send (in milliseconds). We don't want 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(CHILD_ID,V_WATT);
                                        MyMessage kwhMsg(CHILD_ID,V_KWH);
                                        MyMessage pcMsg(CHILD_ID,V_VAR1);
                                        
                                        
                                        void setup()
                                        {
                                            // Fetch last known pulse count value from gw
                                            request(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(CHILD_ID, S_POWER);
                                        }
                                        
                                        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 happen when long wraps or false interrupt triggered
                                                    // We need to send in all values at one time to get consistent data
                                                    if (watt<((unsigned long)MAX_WATT)) {
                                                        send(wattMsg.set(watt));  // Send watt value to gw
                                                        Serial.print("Watt: ");
                                                        Serial.println(watt);
                                                        oldWatt = watt;
                                                        send(pcMsg.set(pulseCount));  // Send pulse count value to gw
                                                        Serial.print("pulseCount: ");
                                                        Serial.println(watt);
                                                        double kwh = ((double)pulseCount/((double)PULSE_FACTOR));
                                                        oldPulseCount = pulseCount;
                                                        send(kwhMsg.set(kwh, 4));  // Send kwh value to gw
                                                        Serial.print("kWh: ");
                                                        Serial.println(kwh);
                                                        oldKwh = kwh;
                                                    }
                                                }
                                                lastSend = now;
                                            } else if (sendTime && !pcReceived) {
                                                // No count received. Try requesting it again
                                                request(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++;
                                        }```
                                        1 Reply Last reply
                                        0
                                        • D Offline
                                          D Offline
                                          dakipro
                                          wrote on last edited by
                                          #96

                                          One (probably stupid) question about the batter powered option: Since sensor cannot keep track of real time power usage as it sleeps most of the time, would it be possible to do the math on the controller side and get "5min delay real time power usage"?
                                          By dividing number of pulses since last transmission, is that basically what this sensor is doing when not being powered by batteries?

                                          I could experiment with 2min delay f.eks, and see how batteries hold. If dht22 temp sensors works over a year with 5min transmission time, i hope 2min delay in pulse meter can hold 6mnt or something?
                                          Another thing is that the electrical box is all metal, and there is a lot of electricity around the sensor so radio could struggle (I guess a repeater would definitively help)

                                          C: OpenHAB2 with node-red on linux laptop
                                          GW: Arduino Nano - W5100 Ethernet, Nrf24l01+ 2,4Ghz mqtt
                                          GW: Arduino Mega, RFLink 433Mhz

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


                                          25

                                          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