Enphase
Posted: Saturday 26 September 2015 17:19
Is it possible to let Domoticz read Enphase solar data (just like Solar Edge?), or do I need to use
Code: Select all
#!/bin/bash
# bash script to read current and actual day power from Enphase gateway
# second part caluclates the actual total power consumption and day consumption for the whole house
# V1.3 27/09/2015
# By Koen Vanduffel
# variables
solar_idx="57"
electricitydaily_idx="58"
enphase_IP="192.168.1.143"
# Read Enphase status page and store as of Currently
DATA=`wget -q -O - $enphase_IP/production | awk '/Currently/{print $0}'`
# Extract current and currentunits, power and powerunits reported
CURRENT=`echo $DATA | awk '/Currently/{print $3}'`
CURRENTUNIT=`echo $DATA | awk '/Currently/{print substr ($4, 1, 1)}'`
kWh=`echo $DATA | awk '/Currently/{print $6}'`
kWhUNIT=`echo $DATA | awk '/Currently/{print substr ($7, 1, 1)}'`
echo $CURRENT
echo $CURRENTUNIT
echo $kWh
echo $kWhUNIT
# convert to Watt and Wh if needed
if [ "$CURRENTUNIT" == "k" ]; then
CURRENT=`awk "BEGIN {print $CURRENT * 1000}"`
fi
if [ "$kWhUNIT" == "k" ]; then
kWh=`awk "BEGIN {print $kWh * 1000}"`
fi
echo $CURRENT
echo $kWh
# Execute curl command to post current and power to Domoticz
curl -i -H "Accept: application/json" "http://localhost:8080/json.htm?type=command¶m=udevice&idx=$solar_idx&nvalue=0&svalue=$CURRENT;$kWh"
# part 2:
# now calculate the total power consumed
# get actual consumption from P1 meter reading in Domoticz and return data
# there might be an easier way than to awk is from the json output
DATA=`wget -q -O - '192.168.1.9:8080/json.htm?type=devices&rid=12' | awk '/CounterDelivToday/{print $3}'`
CURRENTRETURNTODAY=`echo $DATA | awk -F, '{gsub(/"/,"",$1); print $1}'`
DATA=`wget -q -O - '192.168.1.9:8080/json.htm?type=devices&rid=12' | awk '/CounterToday/{print $3}'`
CURRENTUSAGETODAY=`echo $DATA | awk -F, '{gsub(/"/,"",$1); print $1}'`
echo $CURRENTUSAGETODAY
echo $CURRENTRETURNTODAY
TOTALCONSUMPTION=$(python -c "print $CURRENTUSAGETODAY*1000-$CURRENTRETURNTODAY*1000+$kWh")
echo $TOTALCONSUMPTION
# when 5 min around midnight post a zero otherwise Domoticz gets confused with not restarting at zero at 0:00 hours
# probably an imporvement is possible by continuing to calculate the total power long term
time=`date +%k%M` ;
if [ $time -gt 2355 ] || [ 6 -gt $time ]
then
TOTALCONSUMPTION=0
fi
echo $time
echo $TOTALCONSUMPTION
# now do the same for current
DATA=`wget -q -O - '192.168.1.9:8080/json.htm?type=devices&rid=12' | awk '/Usage/{print $3}'`
CURRENTUSAGE=`echo $DATA | awk '{print substr ($1, 2, 4)}'`
CURRENTRETURN=`echo $DATA | awk '{print substr ($2, 2, 4)}'`
echo $CURRENTUSAGE
echo $CURRENTRETURN
TOTALCURRENT=$(python -c "print $CURRENTUSAGE-$CURRENTRETURN+$CURRENT")
echo $TOTALCURRENT
# Execute curl command to post total electricity consumption today
curl -i -H "Accept: application/json" "http://localhost:8080/json.htm?type=command¶m=udevice&idx=$electricitydaily_idx&nvalue=0&svalue=$TOTALCURRENT;$TOTALCONSUMPTION"
Mine is connected to my local lan.smaus wrote:There is a possibillity to add a Enphase hardware item in Dotmoticz, what remote address and port number do i fill in?