Reading analog values from current sensor

Hello all, I am trying to figure out how to implement a new set of hardware - the end goal is to get 1-second (or half-second!) resolution power data from a CT current sensor (induction sensor).

I know two good ways to get the data off the sensor:
1- use an Arduino to read the analog data
2- use an Enviro PHAT to read the analog data

The problem is how to get that data into Home Assistant.

1-The Ardunio has a library that will output a variable (Irms) - but I don’t know how to load that into Home Assitant.

2-I can easily read the analog data from the PHAT - but how do I go about calculating the RMS level? Sampling of the analog data needs to be a minimum of 144 Hz (60 Hz power times 2.4 for anti-aliasing). Once I’ve got all of those values, how do I get HA to run the calculation?

If anyone can guide me to some information / examples of either solution it would be greatly appreciated thanks!

For the curious-
Arduino Library

Planned sensor: SCT-013-030

I have built a sensor to monitor my pump status using SCT-013-030 with OpenMQTTGateway
I have modified their ADC sensor to include the EmonLib
Here is the relevant file

/*  
  OpenMQTTGateway Addon  - ESP8266 or Arduino program for home automation 

   Act as a wifi or ethernet gateway between your 433mhz/infrared IR signal  and a MQTT broker 
   Send and receiving command by MQTT
 
    Analog pin reading Addon
  
    Copyright: (c)Florian ROBERT
    
    Contributors:
    - 1technophile
  
    This file is part of OpenMQTTGateway.
    
    OpenMQTTGateway is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    OpenMQTTGateway is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.

    updated to check for 200 w threshold and update only every minute
*/
#ifdef ZsensorADC
#include "EmonLib.h"
//#ifdef ESP8266
//  ADC_MODE(ADC_TOUT);
//#endif
EnergyMonitor emon1;
//Time used to wait for an interval before resending adc value
unsigned long timeadc = 0;

void setupADC() {
  emon1.current(A0, 111.1);
}
void MeasureADC(){
  if (millis() > (timeadc + TimeBetweenReadingADC)) {//retriving value of temperature and humidity of the box from DHT every xUL
    timeadc = millis();
    static int persistedadc;
  //  trc(F("Checking analog value"));
    double val = emon1.calcIrms(1480);  // Calculate Irms only
   // Serial.print(val*230.0);           // Apparent power
   // Serial.print(" ");
   // Serial.println(val);
    double power = val*230.0; 
    if (power < 200){
          power = 0;
        }
    if (isnan(power)) {
      trc(F("Failed to read from ADC !"));
    }else{
      if(power  >= persistedadc + ThresholdReadingADC || power  <= persistedadc - ThresholdReadingADC){
        char val[10];
        dtostrf(power,4,2,val);
        //sprintf(value, "%d", power);
        trc(F("Sending analog value to MQTT"));
        trc(String(power));
        client.publish(ADC,val);
        persistedadc = power;
       }
    }
  }
}
#endi

If you need the full configuration and files let me know.

1 Like