Page 1 of 1
Mysensors SCT-013-030 current monitor
Posted: Friday 29 May 2015 1:12
by chatainsim
Hi,
I'm working on a mysensors sensor for current monitoring.
http://forum.mysensors.org/topic/1464/s ... r-sensor/9
Domoticz see the sensors but don't add a new device.
Is it because it's not supported by Domoticz ?
If so, how can I add this new device ?
Thank you.
Regards,
Re: Mysensors SCT-013-030 current monitor
Posted: Friday 29 May 2015 7:11
by gizmocuz
maybe because you use V_VAR for sending the messages.
how about
V_WATT
V_KWH
Re: Mysensors SCT-013-030 current monitor
Posted: Thursday 04 June 2015 0:16
by chatainsim
Hello,
Thank you gor your answer.
It's better now, but I have another "issue".
Here is my arduino sketch :
Code: Select all
// EmonLibrary examples openenergymonitor.org, Licence GNU GPL V3 ***/
#include <SPI.h>
#include <MySensor.h>
#include "EmonLib.h" // Include Emon Library
EnergyMonitor emon1; // Create an instance
#define CHILD_ID 0
MySensor gw;
unsigned long lastSend;
unsigned long SEND_FREQUENCY = 20000; // Minimum time between send (in milliseconds). We don't wnat to spam the gateway.
MyMessage IrmsMsg(CHILD_ID,V_WATT);
void setup()
{
gw.begin();
gw.sendSketchInfo("Energy Meter", "1.0"); // Send the sketch version information to the gateway and Controller
gw.present(CHILD_ID, S_POWER); // Register this device as power sensor
emon1.current(A0, 29.0); // Current: input pin, calibration.
}
void loop()
{
gw.process();
unsigned long now = millis();
double Irms = emon1.calcIrms(1480);
bool sendTime = now - lastSend > SEND_FREQUENCY;
if (sendTime) {
gw.send(IrmsMsg.set(Irms*232.0,1));
Serial.println(Irms*232.0);
lastSend = now;
}
}
In the serial monitor of the Arduino IDE, line
Serial.println(Irms*232.0); gave me for exemple :
412.23
but in domoticz I have
0.4 watt. Is it normal or is there someting wrong in my sketch ?
And where can I find all the V_VAR supported by domoticz ? Is there a V_AMP ?
Thank you.
Re: Mysensors SCT-013-030 current monitor
Posted: Monday 15 June 2015 13:49
by chatainsim
Hello,
I've made some change in the Arduino code.
But there is still an issue.
I used V_WATT and V_KWH but in domoticz I've only V_KWH present, both.
Here is my arduino sketch :
Code: Select all
// EmonLibrary examples openenergymonitor.org, Licence GNU GPL V3 ***/
#include <SPI.h>
#include <MySensor.h>
#include "EmonLib.h" // Include Emon Library
EnergyMonitor emon1; // Create an instance
#define CHILD_ID_WATT 0
#define CHILD_ID_KWH 1
MySensor gw;
unsigned long lastSend;
unsigned long SEND_FREQUENCY = 20000; // Minimum time between send (in milliseconds). We don't wnat to spam the gateway.
MyMessage IrmsMsg(CHILD_ID_WATT,V_WATT);
MyMessage kWhMsg(CHILD_ID_KWH,V_KWH);
void setup()
{
gw.begin();
gw.sendSketchInfo("Energy Meter", "1.0"); // Send the sketch version information to the gateway and Controller
gw.present(CHILD_ID_WATT, S_POWER); // Register this device as power sensor
gw.present(CHILD_ID_KWH, S_POWER);
emon1.current(A0, 29.0); // Current: input pin, calibration.
}
void loop()
{
gw.process();
unsigned long now = millis();
//emon1.serialprint(); // Print out all variables (realpower, apparent power, Vrms, Irms, power factor)
double Irms = emon1.calcIrms(1480);
bool sendTime = now - lastSend > SEND_FREQUENCY;
if (sendTime) {
gw.send(IrmsMsg.set((Irms*232.0)*1000, 1));
// Serial.print("Watt: ");
// Serial.println(Irms*232.0);
gw.send(kWhMsg.set((Irms*232.0)/1000, 1));
// Serial.print("kWH: ");
// Serial.println((Irms*232.0)/1000);
lastSend = now;
}
}
Can you help me ?
Thank you.
Regards,
Re: Mysensors SCT-013-030 current monitor
Posted: Tuesday 16 June 2015 16:50
by chatainsim
Hello,
Anybody knows you to fixe this ?
Thank you.
Re: Mysensors SCT-013-030 current monitor
Posted: Saturday 13 February 2016 19:15
by KinDR
Here is my Arduino script not 100% clear bad working for me
Code: Select all
#include <SPI.h>
#include <MySensor.h>
#include <Time.h>
#include "EmonLib.h" // Include Emon Library
EnergyMonitor emon1; // Create an instance
//#define DEBUG
#define ScriptName "Energy Metter-1.3"
#define ScriptVersion "1.3"
boolean timeReceived = false , pcReceived = false , newDay = false; // start up without time
unsigned long lastUpdate = 0, lastRequest = 0 , minuten = 0;
float KWh = 0.00000 , oldKWH = 0.00000; // actualy KWH , gateway last walue of KWH
float Watt = 0.00000 , WattSum = 0.00000 ;
unsigned long samplCount = 0 , MultimetterDelay = 0 , WattDelay = 0; // maesure sample count , Volt & Amps Delay send(anti spam gtw)
MySensor gw;
#define NODE_ID 15 // fixed MySensors node ID
#define CHILD_ID_POWER 0
#define CHILD_ID_MULTIMETER 1
MyMessage voltMsg(CHILD_ID_MULTIMETER, V_VOLTAGE);
MyMessage ampMsg(CHILD_ID_MULTIMETER, V_CURRENT);
MyMessage wattMsg(CHILD_ID_POWER, V_WATT);
MyMessage kwhMsg(CHILD_ID_POWER, V_KWH);
MyMessage pcMsg(CHILD_ID_POWER, V_VAR1);
void gwWait() { //Radio wait
gw.wait(125);
}
void setup() { // put your setup code here, to run once:
gw.begin(incomingMessage, NODE_ID, false); //incomingMessage, NODE_ID, false
gw.sendSketchInfo(ScriptName, ScriptVersion);
gwWait();
gw.present( CHILD_ID_POWER , S_POWER, "Watt+KWH", true); // Register this device as power sensor
gwWait();
gw.present( CHILD_ID_MULTIMETER , S_MULTIMETER, "VOLTAGE+CURRENT", false); // Register this device as multimetter sensor
gwWait();
//gw.send(pcMsg.set(0.0, 6));
gw.request(CHILD_ID_POWER, V_VAR1); // Fetch last known kwh count value from gw
gwWait();
emon1.voltage(0, 272, 1.7); // Voltage: input pin, calibration, phase_shift
emon1.current(1, 29.03225); // Current: input pin, calibration. Cur Const= Ratio/BurdenR. 1800/62 = 29.
gw.requestTime(receiveTime);
}
void loop() {// put your main code here, to run repeatedly:
unsigned long now = millis();
gw.process(); // radio process incoming message
if ((!timeReceived && (now - lastRequest) > (10UL * 1000UL)) || (timeReceived && (now - lastRequest) > (60UL * 1000UL * 60UL))) {
timeReceived = false;//--- 130216
gwWait(); //--- 130216
gw.requestTime(receiveTime); // Request time from controller.
lastRequest = now;
}
if ((((hour() == 23) && (minute() > 55)) || (hour() == 0 && minute() < 5)) && newDay == false ) { // if (hour() == 0 && !newDay) {
if (timeReceived) {
newDay = true; // set flag to new day
oldKWH = 0;
// Serial.print(" _Sending:");
// Serial.print(" New day walue = 0:");
// gw.send(pcMsg.set(oldKWH, 6));
}
} else {
newDay = false;
}
measurePower();//measure energy...
}
void measurePower() {
float Irms = emon1.calcIrms(1480); // Calculate Irms only
float Vrms = emon1.calcVrms(1480); // Calculate Vrms only
if (Irms < 0.02) Irms = 0;
if (Irms > 0.060) {
Irms = (Irms - 0.060); //correction
}
Watt = Irms * Vrms;
WattSum += Watt;
samplCount += 1;
if (millis() - MultimetterDelay > 10000) { // send every 10 sec
MultimetterDelay = millis();
gw.send(voltMsg.set(Vrms, 1)); // voltage send
gw.send(ampMsg.set(Irms, 1)); //amps send
gwWait();
if (!pcReceived) {//Last kwh not yet received from controller, request it again
gw.request(CHILD_ID_POWER, V_VAR1);
return;
}
}
if (millis() - WattDelay > 60000) { // send every 60 sec
minuten += 1;
WattDelay = millis();
double wattsample = WattSum / samplCount ;
// Serial.print(" samplCount:");
// Serial.println(samplCount);
gw.send(wattMsg.set(wattsample, 2)); // Send watt value to gw
}
if (minuten == 1 && timeReceived == true && pcReceived == true ) {
KWh = ((WattSum / samplCount) / 1000.00 ) / 60.00;
// Pulse count has changed
if (oldKWH != KWh) {
oldKWH += KWh;
/* Serial.print(" KWh:");
Serial.println(KWh, 6);
Serial.print(" oldKWH:");
Serial.println(oldKWH, 6); */
if (!newDay) {
// Serial.print(" _Sending:");
gwWait();
gw.send(pcMsg.set(oldKWH, 6));
}
}
if (!newDay) {
gw.send(kwhMsg.set(oldKWH, 6));
minuten = 0;
samplCount = 0;
KWh = 0;
WattSum = 0;
}
}
}
// This is called when a new time value was received
void receiveTime(unsigned long time) {
setTime(time); // Ok, set incoming time
timeReceived = true;
// Serial.println(" timeReceived:");
}
void incomingMessage(const MyMessage &message) {
if (message.type == V_VAR1) {
float gwPulseCount = message.getFloat();
// Serial.print(" Received last value from gw:");
// Serial.println(gwPulseCount, 6);
oldKWH += gwPulseCount;
pcReceived = true;
}
}
Re: Mysensors SCT-013-030 current monitor
Posted: Wednesday 13 April 2016 8:55
by chatainsim
Hello all,
I tried another sketch from mysensors forum.
And only kWh is updated this time.
http://forum.mysensors.org/topic/1464/s ... -sensor/29
