Tomorow i will try to get a smart meter, so i can use the p1 port and get even more information

I will try to get it for free normally they could ask up to 80 euro to install it.
gretings
Moderator: leecollings
A diswasser is not using 1500W continuously.arnoldg wrote:now i have, i some how added the mysensor hardware![]()
![]()
now it works, but i think the reading is not accurate. when my dishwasser is on i have a reading of 300 Watt (i think it should be somthing around 1500 watt)
what could it be.
Code: Select all
// This sketch is based on http://domoticz.com/forum/viewtopic.php?f=38&t=7300
// It will update counters in Domoticz.
// Via the serial port of the Pi you can set the initial counter values.
// do this while the Arduino is connected to the Pi but Domoticz is not running.
// Set the serial port to 9600 Baud.
// If not set, the counter will not start updating.
// Send the following command (with Newline ending):
// M[number of internal S0 counter]=[value in whole liters/Wh].
// So if your gasmeter is M1 and has value 123,456 m3 send:
// M1=123456
// So if your energymeter is M2 and has value 3456,23 kWh send:
// M2=3456230
// Start with M2, then M1. As soon as M1 !=0, the counter starts sending data.
//Number of pulses, used to measure energy.
volatile unsigned int pulseCount1 = 0;
volatile long pulseCount1_sinceStart = 0;
volatile unsigned int pulseCount2 = 0;
volatile long pulseCount2_sinceStart = 0;
volatile unsigned int reportInterval = 10000; //Interval between messages being sent out (in milliseconds)
int PulseCounterID = 12345;
int PulseCounterVersion = 999;
String readString = String(100); //string for fetching data from address
int ind1 = 0;
int ind2 = 0;
String valueSet;
String valueSetID;
float lastTime = 0;
// The interrupt routine
void onPulse1()
{
//pulseCounter
pulseCount1++;
pulseCount1_sinceStart++;
//Blink built-in LED on S0-pulse
}
// The interrupt routine
//void onPulse2()
//{
//pulseCounter
//pulseCount2++;
//pulseCount2_sinceStart++;
//}
void setup()
{
// KWH interrupt attached to IRQ 0 = pin2 (D2)
attachInterrupt(0, onPulse1, FALLING);
//KWH interrupt attached to IRQ 1 = pin3
//attachInterrupt(1, onPulse2, FALLING);
Serial.begin(9600);
Serial.print("/");
Serial.print(PulseCounterID);
Serial.print(":S0 Pulse Counter V");
Serial.println(PulseCounterVersion);
}
void loop()
{
// decode the start values
// it looks for M1=123456
while (Serial.available() > 0) {
char c = Serial.read();
//read char by char
// it expects a maximum of 20 char
if (readString.length() < 20) {
//store characters to string
readString +=c;
Serial.println(c);
}
//if endline has been received
if (c == '\n') {
Serial.println("endline");
if(readString.indexOf("M") >=0){
ind1 = readString.indexOf('M');
valueSetID = readString.substring(ind1+1, ind1+2);
ind2 = readString.indexOf('=');
valueSet = readString.substring(ind2+1);
if (valueSetID.toInt() == 1){
pulseCount1_sinceStart = valueSet.toFloat();
} else if (valueSetID.toInt() == 2){
pulseCount2_sinceStart = valueSet.toFloat();
} else {return;}
} // end readString M
readString = "";
} // end endline
} // end serial available
// send the data every reportInterval
if(millis() - lastTime > reportInterval) {
lastTime = millis();
// Only send the counter data if the initial pulse count is not zero
if (pulseCount1_sinceStart != 0){
Serial.print("ID:");
Serial.print(PulseCounterID);
Serial.print(":I:10:M1:");
Serial.print(pulseCount1);
Serial.print(":");
Serial.print(pulseCount1_sinceStart);
Serial.print(":");
Serial.print("M2");
Serial.print(":");
Serial.print(pulseCount2);
Serial.print(":");
Serial.println(pulseCount2_sinceStart);
pulseCount1 = 0;
pulseCount2 = 0;
} // end if not zero
} // end interval loop
} // end void loop()
Well I thought of using the EEPROM but in the case of a power failure or reset the EEPROM value does not correspond anymore to the meter (meter does not stop, but the Arduino counter does).ThinkPad wrote:Nice! Seems like bit of a fiddly workaround, but at least it's good that someone is busy with it!
2 options: in Domoticz->Settings you can set the meter divider.delchrys wrote:I like to use this with my setup. But i don't understand some things.
My rotating energy meter turn 187.5 rotations /Kwh.
How can i tell domoticz that and how can i make sure it calculates the right energy usage total??
Code: Select all
//Number of pulses, used to measure energy.
volatile unsigned int pulseCount1 = 0;
volatile long pulseCount1_sinceStart = 0;
volatile unsigned int reportInterval = 10000; //Interval between messages being sent out (in milliseconds)
int PulseCounterID = 197336;
int PulseCounterVersion = 999;
int led = 8;
int ledState = LOW;
float lastTime = 0;
// The interrupt routine
void onPulse1()
{
//pulseCounter
pulseCount1 += 2;
pulseCount1_sinceStart +=2;
if (ledState == LOW) {
ledState = HIGH;
} else {
ledState = LOW;
}
digitalWrite(led, ledState);
}
void setup()
{
pinMode(8, OUTPUT);
// KWH interrupt attached to IRQ 0 = pin2 (D2)
attachInterrupt(0, onPulse1, FALLING);
Serial.begin(9600);
Serial.print("/");
Serial.print(PulseCounterID);
Serial.print(":S0 Pulse Counter V");
Serial.println(PulseCounterVersion);
}
void loop()
{
// send the data every reportInterval
if(millis() - lastTime > reportInterval) {
lastTime = millis();
Serial.print("ID:");
Serial.print(PulseCounterID);
Serial.print(":I:10:M1:");
Serial.print(pulseCount1);
Serial.print(":");
Serial.print(pulseCount1_sinceStart);
pulseCount1 = 0;
} // end interval loop
} // end void loop()
hmm, i read that you can change the shortlog interval in the SQLHelper.cpp file.bbqkees wrote:You can't change the interval.
Code: Select all
//-------------------------------------
// This sketch is based on http://domoticz.com/forum/viewtopic.php?f=38&t=7300
// It will update counters in Domoticz.
// S0 Pulse counter based on CNY70 reflectometer.
// S0PCM emulator
//-------------------------------------
volatile unsigned int pulseCount1 = 0;
volatile unsigned int pulseCount1_sinceStart = 0;
volatile unsigned int pulseCount2 = 0;
volatile unsigned int pulseCount2_sinceStart = 0;
volatile unsigned int Counter = 0;
volatile unsigned int sensorVal;
volatile unsigned int reportInterval = 10; //Interval between messages being sent out (in seconds)
int PulseCounterID = 1337; // ELITE sensor ID, just because.
int PulseCounterVersion = 1; // Version number
const int S0Pulse = 2; // Input pin being used to count CNY70 sensor input.
const int OnboardLED = 13; //LED to indicate a S0 pulse has been seen.
const int RedLED = 4; //Red LED to indicate that the pulses are not counted.
const int GreenLED = 5; //Green LED to indicate that the pulses are being counted.
const int Enableswitch = 7; //Switch to disable counter (fitted for aligning CNY70 sensor without counts).
//-------------------------------------------
// The interrupt routine
//-------------------------------------------
void onPulse1()
{
//pulseCounter
if ( digitalRead (Enableswitch) == HIGH) {
pulseCount1++;
pulseCount1_sinceStart++;
}
//Blink built-in LED on S0-pulse
digitalWrite(OnboardLED, HIGH); // turn the LED on (HIGH is the voltage level)
delay(80); // wait for a few miliseconds
digitalWrite(OnboardLED, LOW); // turn the LED off by making the voltage LOW
}
//-------------------------------------------
// Initialize
//-------------------------------------------
void setup()
{
pinMode(S0Pulse, INPUT_PULLUP);
pinMode(Enableswitch, INPUT_PULLUP);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(OnboardLED, OUTPUT);
// KWH interrupt attached to IRQ 0 = pin2 (D2)
attachInterrupt(0, onPulse1, FALLING);
Serial.begin(9600);
Serial.print("/");
Serial.print(PulseCounterID);
Serial.print(":S0 Pulse Counter V");
Serial.println(PulseCounterVersion);
digitalWrite(OnboardLED, LOW); // turn the LED off by making the voltage LOW
}
//-------------------------------------------
// Main loop
//-------------------------------------------
void loop()
{
if (Counter == reportInterval ){
Counter = 0;
Serial.print("ID:");
Serial.print(PulseCounterID);
Serial.print(":I:10:M1:");
Serial.print(pulseCount1);
Serial.print(":");
Serial.print(pulseCount1_sinceStart);
Serial.print(":");
Serial.print("M2");
Serial.print(":");
Serial.print(pulseCount2);
Serial.print(":");
Serial.println(pulseCount2_sinceStart);
}
pulseCount2 = 0;
Counter++;
sensorVal = digitalRead(Enableswitch);
if (sensorVal == HIGH) {
digitalWrite(RedLED, LOW);
digitalWrite(GreenLED, HIGH);
}
else {
digitalWrite(RedLED, HIGH);
digitalWrite(GreenLED, LOW);
}
delay(1000); // Need to multiply it by 1000 because we need it in ms
}
TheBasher wrote:Hi all,
i've been following this topic for a while and since i got my first arduino from a collegue i also started working on this S0 counter.
I've taken the sketch from here and added something of my own and i would like to share it with you all:
It is running on a uno at the moment but i will port it to a nano as soon as it arrives and make a dedicated circuit board for it.Code: Select all
//------------------------------------- // This sketch is based on http://domoticz.com/forum/viewtopic.php?f=38&t=7300 // It will update counters in Domoticz. // S0 Pulse counter based on CNY70 reflectometer. // S0PCM emulator //------------------------------------- volatile unsigned int pulseCount1 = 0; volatile unsigned int pulseCount1_sinceStart = 0; volatile unsigned int pulseCount2 = 0; volatile unsigned int pulseCount2_sinceStart = 0; volatile unsigned int Counter = 0; volatile unsigned int sensorVal; volatile unsigned int reportInterval = 10; //Interval between messages being sent out (in seconds) int PulseCounterID = 1337; // ELITE sensor ID, just because. int PulseCounterVersion = 1; // Version number const int S0Pulse = 2; // Input pin being used to count CNY70 sensor input. const int OnboardLED = 13; //LED to indicate a S0 pulse has been seen. const int RedLED = 4; //Red LED to indicate that the pulses are not counted. const int GreenLED = 5; //Green LED to indicate that the pulses are being counted. const int Enableswitch = 7; //Switch to disable counter (fitted for aligning CNY70 sensor without counts). //------------------------------------------- // The interrupt routine //------------------------------------------- void onPulse1() { //pulseCounter if ( digitalRead (Enableswitch) == HIGH) { pulseCount1++; pulseCount1_sinceStart++; } //Blink built-in LED on S0-pulse digitalWrite(OnboardLED, HIGH); // turn the LED on (HIGH is the voltage level) delay(80); // wait for a few miliseconds digitalWrite(OnboardLED, LOW); // turn the LED off by making the voltage LOW } //------------------------------------------- // Initialize //------------------------------------------- void setup() { pinMode(S0Pulse, INPUT_PULLUP); pinMode(Enableswitch, INPUT_PULLUP); pinMode(4, OUTPUT); pinMode(5, OUTPUT); pinMode(OnboardLED, OUTPUT); // KWH interrupt attached to IRQ 0 = pin2 (D2) attachInterrupt(0, onPulse1, FALLING); Serial.begin(9600); Serial.print("/"); Serial.print(PulseCounterID); Serial.print(":S0 Pulse Counter V"); Serial.println(PulseCounterVersion); digitalWrite(OnboardLED, LOW); // turn the LED off by making the voltage LOW } //------------------------------------------- // Main loop //------------------------------------------- void loop() { if (Counter == reportInterval ){ Counter = 0; Serial.print("ID:"); Serial.print(PulseCounterID); Serial.print(":I:10:M1:"); Serial.print(pulseCount1); Serial.print(":"); Serial.print(pulseCount1_sinceStart); Serial.print(":"); Serial.print("M2"); Serial.print(":"); Serial.print(pulseCount2); Serial.print(":"); Serial.println(pulseCount2_sinceStart); } pulseCount2 = 0; Counter++; sensorVal = digitalRead(Enableswitch); if (sensorVal == HIGH) { digitalWrite(RedLED, LOW); digitalWrite(GreenLED, HIGH); } else { digitalWrite(RedLED, HIGH); digitalWrite(GreenLED, LOW); } delay(1000); // Need to multiply it by 1000 because we need it in ms }
The strange thing is if i disable my S0 hardware from domoticz , then pull the usb cable and put it back in and enable the hardware again, i do not have to set an initial value to the pulsesfromstart counter. Domoticz just keeps on counting from were it stopped.
I'm running version 3.4834 on my Pi 2B.
Code: Select all
2016-06-29 20:28:49.899 Error: S0 Meter: Invalid Data received! �5K^��w�=����I�?�y�9��q'�}��[���3����9�l�w����1);%���*��)c��o=�����?�=��?�b�}�����g�9�3����7����l�u�1��q�}���1!����o='ꧩ�?�yB�ʎ-{�9�}���;��3��������g�}�3�!�!�����i��)c��oy������k�/s�yB�?�+��}�}�!;*�u���I�}�}�w���1��5���
2016-06-29 20:28:59.517 Error: S0 Meter: Invalid Data received! �5K^��&��
Users browsing this forum: No registered users and 1 guest