sdm120c

Moderator: leecollings

Post Reply
MareRubato
Posts: 6
Joined: Tuesday 12 March 2019 10:50
Target OS: Raspberry Pi / ODroid
Domoticz version: Latest
Location: Amsterdam
Contact:

sdm120c

Post by MareRubato »

Hey All,

Very new to Pi but I love it.
I have a Eastron SDM120 modbus with a RS485 usb and connected it to my Pi 3 B+.
I installed https://www.domoticz.com/wiki/Eastron_SDM120C and made a dummy.

If I type

Code: Select all

sdm120c -a 1 -b 9600 -P N -S 2 -z 1 -j 20 /dev/ttyUSB1
I get

Code: Select all

pi@raspberrypi:~ $ sdm120c -a 1 -b 9600 -P N -S 2 -z 1 -j 20 /dev/ttyUSB1

Voltage: 233.00 V 
Current: 2.81 A 
Power: 572.80 W 
Active Apparent Power: 650.77 VA 
Reactive Apparent Power: 308.70 VAR 
Power Factor: 0.88 
Phase Angle: 0.00 Degree 
Frequency: 49.95 Hz 
Import Active Energy: 887773 Wh 
Export Active Energy: 82687 Wh 
Total Active Energy: 970460 Wh 
Import Reactive Energy: 607963 VARh 
Export Reactive Energy: 114013 VARh 
Total Reactive Energy: 721976 VARh 
OK
Put crontab every 10 sec which it does. But it gives no info. If I run it with Thonny in vnc I get this error:

Code: Select all

Python 3.5.3 (/usr/bin/python3)
>>> %Run sdm120.sh
Traceback (most recent call last):
  File "/home/pi/domoticz/scripts/sdm120.sh", line 18
    CURRENT=$($SDM120 $TTY -p -q -z 10 | awk '{print $1}') #get current from sdm120c
            ^
SyntaxError: invalid syntax
>>> 
What to do?
Toulon7559
Posts: 859
Joined: Sunday 23 February 2014 17:56
Target OS: Raspberry Pi / ODroid
Domoticz version: mixed
Location: Hengelo(Ov)/NL
Contact:

Re: sdm120c

Post by Toulon7559 »

Why 10s interval?
Did you try a longer interval (of e.g. 5 minutes)?
Set1 = RPI-Zero+RFXCom433+S0PCM+Shield for BMP180/DS18B20/RS485+DDS238-1ZNs
Set2 = RPI-3A++RFLinkGTW+ESP8266s+PWS_WS7000
Common = KAKUs+3*PVLogger+PWS_TFA_Nexus
plus series of 'satellites' for dedicated interfacing, monitoring & control.
MareRubato
Posts: 6
Joined: Tuesday 12 March 2019 10:50
Target OS: Raspberry Pi / ODroid
Domoticz version: Latest
Location: Amsterdam
Contact:

Re: sdm120c

Post by MareRubato »

Yes I did at first, no difference. I have it every 10 sec so it refreshes in the same speed as my P1 meter. Then I can see the real electricity use.
User avatar
emme
Posts: 909
Joined: Monday 27 June 2016 11:02
Target OS: Raspberry Pi / ODroid
Domoticz version: latest
Location: Milano, Italy
Contact:

Re: sdm120c

Post by emme »

can you post the entire script?
The most dangerous phrase in any language is:
"We always done this way"
MareRubato
Posts: 6
Joined: Tuesday 12 March 2019 10:50
Target OS: Raspberry Pi / ODroid
Domoticz version: Latest
Location: Amsterdam
Contact:

Re: sdm120c

Post by MareRubato »

My sdm120.sh script.

Code: Select all

#!/bin/bash
#title           :solar
#description     :Read current from sdm120 and sends it to Domoticz.
#author		 :JM
#date            :20160605
#version         :0.1
#usage		 :./solar
#notes           :
#bash_version    :
#==============================================================================
SERVER="http://192.168.1.100:8080"   #server location
IDX=9	  #id of your device

#SDM120C
SDM120="/home/pi/SDM120C/sdm120c" #location sdm120c script
TTY="/dev/ttyUSB1"		  #USB port sdm120c

CURRENT=$($SDM120 $TTY -p -q -z 10 | awk '{print $1}') #get current from sdm120c

# echo "$SERVER/json.htm?type=command&param=udevice&idx=$IDX&nvalue=$CURRENT&svalue=POWER;ENERGY"

x=0 
for gelezenWaardE in $($SDM120 $TTY -z 10  -ip|awk -F ":" '!/OK/ {print $2} '|sed 's/[ a-zA-Z]//g') ; do 

if [ ! $x -eq 1 ]; then
	watt=$gelezenWaardE
	x=1
	else
	kilowattuur=$(($gelezenWaardE/1000))
fi 

done

curl -s {"$SERVER/json.htm?type=command&param=udevice&idx=$IDX&nvalue=0&svalue=${watt};${kilowattuur}"}  #send current to domoticz
curl -s {"$SERVER/json.htm?type=command&param=addlogmessage&message=SolarSDM120Update"}  #send current to domoticz
User avatar
emme
Posts: 909
Joined: Monday 27 June 2016 11:02
Target OS: Raspberry Pi / ODroid
Domoticz version: latest
Location: Milano, Italy
Contact:

Re: sdm120c

Post by emme »

could it be that CURRENT should be
CURRENT=`$SDM120 $TTY -p -q -z 10 | awk "{print $1}"`
The most dangerous phrase in any language is:
"We always done this way"
MareRubato
Posts: 6
Joined: Tuesday 12 March 2019 10:50
Target OS: Raspberry Pi / ODroid
Domoticz version: Latest
Location: Amsterdam
Contact:

Re: sdm120c

Post by MareRubato »

Unfortunately not. It gives the same error.
User avatar
emme
Posts: 909
Joined: Monday 27 June 2016 11:02
Target OS: Raspberry Pi / ODroid
Domoticz version: latest
Location: Milano, Italy
Contact:

Re: sdm120c

Post by emme »

uh... just figure it out!!!
you're running a bash script under python interpreter!!! tha's why it does not work!

your SDM120C.sh script should have execution rights (sudo chmod +x SDM120C.sh )
and the you have to invoke it using ./SDM120C.sh
The most dangerous phrase in any language is:
"We always done this way"
MareRubato
Posts: 6
Joined: Tuesday 12 March 2019 10:50
Target OS: Raspberry Pi / ODroid
Domoticz version: Latest
Location: Amsterdam
Contact:

Re: sdm120c

Post by MareRubato »

Thanks
Ok I did

Code: Select all

pi@raspberrypi:~/domoticz/scripts $ sudo chmod +x sdm120.sh
Then

Code: Select all

pi@raspberrypi:~/domoticz/scripts $ ./sdm120.sh
{
   "status" : "OK",
   "title" : "Update Device"
}
{
   "status" : "OK",
   "title" : "AddLogMessage"
}
What does this mean?
Still can not see it in Domoticz.

I did change the CURRENT line to tell it has address 1 and 9600 baudrate. Also did not change anything.

Code: Select all

CURRENT=$($SDM120 $TTY -a 1 -b 9600 -p -q -z 10 | awk '{print $1}') #get current from sdm120c
MareRubato
Posts: 6
Joined: Tuesday 12 March 2019 10:50
Target OS: Raspberry Pi / ODroid
Domoticz version: Latest
Location: Amsterdam
Contact:

Re: sdm120c

Post by MareRubato »

With some help I got it to work.
I made a new virtual sensor with sensor type P1 smart meter
I changed the sdm120.sh script to:

Code: Select all

#!/bin/bash

# Read out modbus meter
#echo Reading values from Eastron SDM120c Modbus Meter, please wait....
values=`sudo sdm120c -a 1 -b 9600 -e -p -P N -q -z 3 -j 20 /dev/ttyUSB1`

# Convert the values
echo ${values}
W=`echo ${values} | awk '{print $1}' | sed 's/-//' `
T=`echo ${values} | awk '{print $2}'`

#Values to upload
echo
echo Values to upload to Domoticz:
echo $T
echo $W
echo


# Only upload W and T if both W and T are not empty or "NOK"
if [[ -n $W ]] && [[ $T -gt "1" ]] && [[ NOK != $T ]]; then
#echo Waardes correct uitgelezen! De waardes worden naar Domoticz verstuurd!
curl -s "http://192.168.1.100:8080/json.htm?type=command&param=udevice&idx=10&nvalue=0&svalue=$T;0;0;0;$W;0"
else
echo Waardes niet correct uitgelezen! Het script wordt beeindigd
curl -s "http://192.168.1.100:8080/json.htm?type=command&param=addlogmessage&message=Error+reading+Eastron+kWh+meter.+Values+skipped!"
fi
It gives the production, very nice, but...
The log file does nothing. I changed a bit on this line:

Code: Select all

curl -s "http://192.168.1.100:8080/json.htm?type=command&param=udevice&idx=10&nvalue=0&svalue=$watts;$watthours;0;0;$W;0"
It looks better but no data. How can I get the log data showing up.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest