Install & info https://www.domoticz.com/wiki/Eastron_SDM120C
For Domoticz;
Add dummy and virtual device Electric(Instant+counter)
Add dummy and virtual device Voltage (for voltage)
Add dummy and virtual device Voltage (for hertz/frequency so you see a nice line, instead off text, but the V should be a H)
Add dummy and virtual device Ampere (for amps)
Adjusted the script a bit to get more value's from it (p=power / t=total / v=voltage / f=frequency / c=amps) + 4x retry + don't send invalid value's to Domoticz. Tried to keep it simple as possible, so people can adjust it too their wishes.
Code: Select all
#!/bin/bash
#title : Eastron SDM230 Module with PL2303 Serial Port
#description : Read multiple value's from SDM230 and sends it to Domoticz.
#author : JM (updated by ILoveIoT)
#date : 17-02-2019
#version : 0.2
#usage : /root/scripts/stroomverbruik.sh
#notes : With p=power / t=total / v=voltage / f=frequency / c=amps and retry (-z 4)
#bash_version :
#==============================================================================
#=====================Change Server and IDX to youre config====================
#==============================================================================
SERVER="http://127.0.0.1:8080" # Server location
DOMOTICZIDXPOWERANDTOTAL="178" # Domoticz IDX for power and total
DOMOTICZIDXVOLTAGE="184" # Domoticz IDX for voltage
DOMOTICZIDXFREQUENCY="183" # Domoticz IDX for frequency
DOMOTICZIDXAMPERE="182" # Domoticz IDX for ampere
#==============================================================================
#===============================Begin Script===================================
#==============================================================================
# Getting the info
VALUES=`/usr/local/bin/sdm120c /dev/ttyUSB0 -P N -z 4 -p -t -v -f -c -q` #p=power / t=total / v=voltage / f=frequency / c=amps / q=short output
POWER=`echo $VALUES | cut -d ' ' -f3`
TOTAL=`echo $VALUES | cut -d ' ' -f5`
VOLTAGE=`echo $VALUES | cut -d ' ' -f1`
FREQUENCY=`echo $VALUES | cut -d ' ' -f4`
AMPERE=`echo $VALUES | cut -d ' ' -f2`
echo ""
echo "Eastron SDM230 Module with PL2303 Serial Port on /dev/ttyUSB0"
echo ""
echo "Use : (/usr/local/bin/sdm120c /dev/ttyUSB0 -P N -z 3) to get all available parameters"
echo ""
echo "POWER : $POWER"
echo "TOTAL : $TOTAL"
echo "VOLTAGE : $VOLTAGE"
echo "FREQUENCY : $FREQUENCY"
echo "AMPERE : $AMPERE"
echo ""
curl -s {$SERVER"/json.htm?type=command¶m=udevice&idx="$DOMOTICZIDXPOWERANDTOTAL"&nvalue=0&svalue="$POWER";"$TOTAL""} #send current to Domoticz
# If value's are NUL/NOK/0 or emtpy, don't send them to Domoticz
if [ "$VOLTAGE" = "0" ] || [ "$VOLTAGE" = "NOK" ] || [ -z "$VOLTAGE" ] ; then
echo "!! VOLTAGE = $VOLTAGE ..invalid value not sending it to Domoticz !!"
else
curl -s {$SERVER"/json.htm?type=command¶m=udevice&idx="$DOMOTICZIDXVOLTAGE"&nvalue=0&svalue="$VOLTAGE""} #send voltage to Domoticz
fi
if [ "$FREQUENCY" = "0" ] || [ "$FREQUENCY" = "NOK" ] || [ -z "$FREQUENCY" ] ; then
echo "!! FREQUENCY = $FREQUENCY ..invalid value not sending it to Domoticz !!"
else
curl -s {$SERVER"/json.htm?type=command¶m=udevice&idx="$DOMOTICZIDXFREQUENCY"&nvalue=0&svalue="$FREQUENCY""} #send frequency to Domoticz
fi
if [ "$AMPERE" = "NOK" ] || [ -z "$AMPERE" ] ; then
echo "!! AMPERE = $AMPERE ..invalid value not sending it to Domoticz !!"
else
curl -s {$SERVER"/json.htm?type=command¶m=udevice&idx="$DOMOTICZIDXAMPERE"&nvalue=0&svalue="$AMPERE""} #send ampere to Domoticz
fi
echo ""
echo ""
exit
#EOF