Page 1 of 1
sdm120c
Posted: Sunday 14 July 2019 20:34
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?
Re: sdm120c
Posted: Sunday 14 July 2019 21:07
by Toulon7559
Why 10s interval?
Did you try a longer interval (of e.g. 5 minutes)?
Re: sdm120c
Posted: Monday 15 July 2019 8:12
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.
Re: sdm120c
Posted: Monday 15 July 2019 10:00
by emme
can you post the entire script?
Re: sdm120c
Posted: Monday 15 July 2019 13:03
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¶m=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¶m=udevice&idx=$IDX&nvalue=0&svalue=${watt};${kilowattuur}"} #send current to domoticz
curl -s {"$SERVER/json.htm?type=command¶m=addlogmessage&message=SolarSDM120Update"} #send current to domoticz
Re: sdm120c
Posted: Monday 15 July 2019 13:38
by emme
could it be that CURRENT should be
CURRENT=`$SDM120 $TTY -p -q -z 10 | awk "{print $1}"`
Re: sdm120c
Posted: Tuesday 16 July 2019 11:58
by MareRubato
Unfortunately not. It gives the same error.
Re: sdm120c
Posted: Tuesday 16 July 2019 17:05
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
Re: sdm120c
Posted: Tuesday 16 July 2019 19:59
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
Re: sdm120c
Posted: Sunday 21 July 2019 17:22
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¶m=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¶m=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¶m=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.