💬 Power Meter Pulse Sensor
-
@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.
@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. -
@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.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.
-
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.
-
This post is deleted!
-
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.
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 -
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.700Now I get this:
sqlite> select Name, sValue from DeviceStatus; Storage kWh|118.000;11678062.000Notice 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:00The 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. -
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++; }``` -
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) -
Is it only me that is getting a compile error?
Error: call of overloaded 'set(volatile long unsigned int&)' is ambiguous
send(wattMsg.set(watt)); \ Send watt value to gwerror: call of overloaded 'set(volatile long unsigned int&)' is ambiguous
send(pcMsg.set(pulseCount)); \ Send pulse count value to gwfollowed by all the possible candidates of .set arguments
-
Is it only me that is getting a compile error?
Error: call of overloaded 'set(volatile long unsigned int&)' is ambiguous
send(wattMsg.set(watt)); \ Send watt value to gwerror: call of overloaded 'set(volatile long unsigned int&)' is ambiguous
send(pcMsg.set(pulseCount)); \ Send pulse count value to gwfollowed by all the possible candidates of .set arguments
-
BTW, is there a way to have the pulse meter running on gateway? I got stuck because at startup it asks the controller the last count value and since the controller is not yet connected it just doesn't work.