Page 1 of 2

Eastron sdm120c

Posted: Thursday 04 May 2017 10:24
by tomix
Hello
I have a eastron counter sdm120c and raspberry with domoticzem, i would like to read the voltage reading sdm120c with rs485 (modbus). Can anyone help me in advance thank you very much.

Re: Eastron sdm120c

Posted: Thursday 04 May 2017 21:27
by Toulon7559
Perhaps the quickest, suitable answer is in the Domoticz-wiki.
Implementation for SDM220 is almost identical (as described).
The script in the wiki is for reading the actual (=current) power & energy.
If you want to handle another value (such as voltage), then
1) read the instruction in github related to setup of call
2) modify (or add) the dedicated lines to extract the desired value(s)
3) check & modify the dedicated lines to get correct scaling for upload to Domoticz
4) modify (or add) the related curl-scriptlines at the end of the script.

Re: Eastron sdm120c

Posted: Friday 05 May 2017 11:02
by tomix
Hello
I can not cope with data reading from counter to domoticza.
In raspberry, after issuing the sdm120c -a 2 -b 9600 / dev / ttyUSB0 command, I have the data


Voltage: V 233.40
Current: 2.37 A
Power: 545.10 W
Active Apparent Power: 548.72 VA
Reactive Apparent Power: 0.00 VAR
Power Factor: 1.00
Phase Angle: 0.00 Degree
Frequency: 50.00 Hz
Import Active Energy: 1842537 Wh
Export Active Energy: 0 Wh
Total Active Energy: 1842537 Wh
Import Reactive Energy: 273398 VARh
Export Reactive Energy: 0 VARh
Total Reactive Energy: 273398 VARh
OKAY

Please help

Re: Eastron sdm120c

Posted: Friday 05 May 2017 14:45
by Toulon7559
@tomix

Your call

Code: Select all

sdm120c -a 2 -b 9600 / dev / ttyUSB0
generates a response in accordance with the bottomline of the text at github:

Code: Select all

Serial device is required. When no parameter is passed, retrieves all values
The example in the wiki is 'tuned' for specific extraction of compact Power-info with max. 10 retries, by the insertion in the string of
-p -q -z 10
For extraction of another value than Power you need to replace -p by another identifier from the list below (copied from the github-section):

Code: Select all

    -p             Get power (W)
    -v             Get voltage (V)
    -c             Get current (A)
    -f             Get frequency (Hz)
    -g             Get power factor
    -e             Get exported energy (Wh)
    -i             Get imported energy (Wh)
    -t             Get total energy (Wh)
Obviously you also have to align/match all subsequent, related lines in the script.

Re: Eastron sdm120c

Posted: Saturday 06 May 2017 11:44
by tomix
Hello
I would like to thank you very much for your interest and guidance, but I can not help myself. After creating the file and copying the sample script to the domoticz named sdm120 there is no response.Example script.

#!/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.x.x:8085" #server location
IDX=32 #id of your device

#SDM120C
SDM120="/home/pi/SDM120C/sdm120c" #location sdm120c script
TTY="/dev/ttyUSB0" #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


In my arithmetic I have created a virtual sensor (instantaneous electricity + meter)
What am I doing wrong?

Re: Eastron sdm120c

Posted: Saturday 06 May 2017 12:00
by Toulon7559
If no address and baudrate is specified, the latest script you tried by default assumes address = 1 and baudrate = 2400 bps (see the github-text)
In your first script you have scriptline

Code: Select all

sdm120c -a 2 -b 9600 / dev / ttyUSB0
to call the SDM120C in your configuration.
Because you got response, I deduct that in some way your SDM120C has been set to address 2 and baudrate 9600bps.
That setting information is missing in the scriptline in the latest script.
No success guaranteed, but suggestion to try

Code: Select all

CURRENT=$($SDM120 $TTY -a 2 -b 9600 -p -q -z 10 | awk '{print $1}') #get current from sdm120c at slave#2/9600bps

Re: Eastron sdm120c

Posted: Saturday 06 May 2017 20:30
by tomix
Can you still help me? It still does not work.

Re: Eastron sdm120c

Posted: Friday 04 August 2017 21:01
by benbammens
I've just installed the same meter yesterday and it took me a few hours of experimenting with the code to get it working. I THINK it is working now...

I also had problems with lock files not being accessible. After deleting them (several times) it works for now. Need to find a solution for this problem. Has been working the whole day now. You can check if you have this problem bij maken your script file executable and running it from the terminal. You will immediately see if the script runs OK or if the LCK file are blocked.

Also see if you got the right USB defined. I've noticed the USB port number can change just from restarting... Really annoying since the script will not work. There is a solution for this but this is not so simple.

My code for reading and sending the total of the meter and instant power:

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://xxx.xxx.xx.xxx:8080"   #server location
IDXT=106	  #id of your device for totaal + vermogen
 
VALUES=NOK
#echo $VALUES #Debugging line

sleep 5

while [ "$VALUES" = "NOK" ]
do
        VALUES=`/home/pi/SDM120C/sdm120c /dev/ttyUSB1 -P N -p -t -q` #i=imported / e=exported / t=totaal / p=vermogen/ q=short output
#       echo $VALUES #Debugging line
done
        VERMOGEN=`echo $VALUES | cut -d ' ' -f1`
        TOTAAL=`echo $VALUES | cut -d ' ' -f2`

curl -s {$SERVER"/json.htm?type=command&param=udevice&idx="$IDXT"&nvalue=0&svalue="$VERMOGEN";"$TOTAAL""}  #send to domoticz
The code for a meter with the imported and a meter for exported kWh's. I tried doing all the meters in one file, but this did not work for some reason. Put the code in a .sh file and run it every 5 mins with a cron task.

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://xxx.xxx.xx.xxx:8080"   #server location
IDXI=107	  #id of your device for import
IDXE=108	  #id of your device for export

 
VALUES=NOK
#echo $VALUES #Debugging line
while [ "$VALUES" = "NOK" ]
do
        VALUES=`/home/pi/SDM120C/sdm120c /dev/ttyUSB1 -i -e -q` #i=imported / e=exported / q=short output
#       echo $VALUES #Debugging line
done
        IMPORT=`echo $VALUES | cut -d ' ' -f1`
        EXPORT=`echo $VALUES | cut -d ' ' -f2`

curl -s {$SERVER"/json.htm?type=command&param=udevice&idx="$IDXI"&nvalue=0&svalue="$IMPORT""}  #send to domoticz
curl -s {$SERVER"/json.htm?type=command&param=udevice&idx="$IDXE"&nvalue=0&svalue="$EXPORT""}  #send to domoticz

Re: Eastron sdm120c

Posted: Monday 07 August 2017 0:07
by zuluman
benbammens wrote:I've just installed the same meter yesterday and it took me a few hours of experimenting with the code to get it working. I THINK it is working now...

I also had problems with lock files not being accessible. After deleting them (several times) it works for now. Need to find a solution for this problem. Has been working the whole day now. You can check if you have this problem bij maken your script file executable and running it from the terminal. You will immediately see if the script runs OK or if the LCK file are blocked.

Also see if you got the right USB defined. I've noticed the USB port number can change just from restarting... Really annoying since the script will not work. There is a solution for this but this is not so simple.

My code for reading and sending the total of the meter and instant power:

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://xxx.xxx.xx.xxx:8080"   #server location
IDXT=106	  #id of your device for totaal + vermogen
 
VALUES=NOK
#echo $VALUES #Debugging line

sleep 5

while [ "$VALUES" = "NOK" ]
do
        VALUES=`/home/pi/SDM120C/sdm120c /dev/ttyUSB1 -P N -p -t -q` #i=imported / e=exported / t=totaal / p=vermogen/ q=short output
#       echo $VALUES #Debugging line
done
        VERMOGEN=`echo $VALUES | cut -d ' ' -f1`
        TOTAAL=`echo $VALUES | cut -d ' ' -f2`

curl -s {$SERVER"/json.htm?type=command&param=udevice&idx="$IDXT"&nvalue=0&svalue="$VERMOGEN";"$TOTAAL""}  #send to domoticz
The code for a meter with the imported and a meter for exported kWh's. I tried doing all the meters in one file, but this did not work for some reason. Put the code in a .sh file and run it every 5 mins with a cron task.

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://xxx.xxx.xx.xxx:8080"   #server location
IDXI=107	  #id of your device for import
IDXE=108	  #id of your device for export

 
VALUES=NOK
#echo $VALUES #Debugging line
while [ "$VALUES" = "NOK" ]
do
        VALUES=`/home/pi/SDM120C/sdm120c /dev/ttyUSB1 -i -e -q` #i=imported / e=exported / q=short output
#       echo $VALUES #Debugging line
done
        IMPORT=`echo $VALUES | cut -d ' ' -f1`
        EXPORT=`echo $VALUES | cut -d ' ' -f2`

curl -s {$SERVER"/json.htm?type=command&param=udevice&idx="$IDXI"&nvalue=0&svalue="$IMPORT""}  #send to domoticz
curl -s {$SERVER"/json.htm?type=command&param=udevice&idx="$IDXE"&nvalue=0&svalue="$EXPORT""}  #send to domoticz
I am using a raspberry pi model B with Raspbian Jessie Lite and Domoticz V3.8153

i recently installed the SDM120C for power consumption. I used the script in the wiki. https://www.domoticz.com/wiki/Eastron_SDM120C
the script worked (after adding +P N) but the cronjob didnt work. i had to ad the following line in the cronjob.

Code: Select all

PATH=~/bin:/usr/bin/:/bin
SHELL=/bin/bash
*/1 * * * * /home/pi/domoticz/scripts/sdm120c.sh </dev/null 2>&1
the script in the wiki was not giving not the right reading. actual wattage was ok. but total kwh was wrong, it was a factor 1.000 too low.
this line was mesing things up .

Code: Select all

	kilowattuur=$(($gelezenWaardE/1000))
but when i removed it the total kwh ws right but the daily kwh was 1.000x too high. By using your first script it is working good now.

i want to have more data from the easton in domoticz. (voltage, Amps, etc)
I was wondering how do you use the second script. do i add a 2nd script called sdm120c_2.sh and make a extra cronjob? Is it possible to run 2 cronjobs on the same hardware? i inmagine you cant excute 2 scripts at the same time. wont there will be a problem with the lock file?

and my easton sdm120c only records import. export is 0. weird because my utily meter from the energy company does show exported energy. is there a setting on the easton i must activate?

i fixed the usb ports issue with this guide. http://www.domoticz.com/wiki/PersistentUSBDevicesand

Re: Eastron sdm120c

Posted: Saturday 02 December 2017 18:20
by gianfrdp
> i want to have more data from the easton in domoticz. (voltage, Amps, etc)

Hello,
look at this script

https://github.com/gianfrdp/SDM120C/blo ... omoticz.sh

Hope it helps

Re: Eastron sdm120c

Posted: Sunday 01 July 2018 12:53
by tomix
Hello
I have a problem with sdm120c namely on raspberry pi after entering the command sdm120c -a 1 -b 9600 -PN -v -q -w 3 -z 10 / dev / ttyUSB0 shows the voltage content. In logs domoticz shows Status: SolarSDM120Update so crontab works and in domoticz shows 0v.Co can be the cause

Re: Eastron sdm120c

Posted: Monday 15 October 2018 21:11
by MaikelK
What USB adapter are you Guys using? Any links to aliexpress perhaps?

Re: Eastron sdm120c

Posted: Monday 22 October 2018 17:14
by Doggieman
USB to RS485 485 Converter Adapter Support Win7 XP Vista Linux Mac OS WinCE5.0
https://s.click.aliexpress.com/e/mrt5tGG

This one works for me. Have a Sdm220 working with this adapter.

Re: Eastron sdm120c

Posted: Monday 22 October 2018 18:13
by MaikelK
Ordered the same before i asked it and its working as a charme!

Re: Eastron sdm120c

Posted: Thursday 28 March 2019 21:24
by ILoveIOT
Got a SDM230, but already fried 2 cheap rs485 adapters (ebay or ali), also the PI was unreachable after (so something happend), ordered now 2 other ones with a GND connection, hope it stops frying the USB RS-485 dongle.

Not tested but waiting on them;

Image

https://www.ebay.com/itm/Industrial-USB ... 2749.l2649

Image

https://www.ebay.com/itm/USB-to-RS485-T ... 2749.l2649

Re: Eastron sdm120c

Posted: Thursday 09 May 2019 17:27
by emme
I use SDM120C with a nodeMCU flashed with EspEasy and a Serial-RS485 device
connected via Wifi and send data to domoticz.... really pround of it... works like a charm!

Re: Eastron sdm120c

Posted: Tuesday 14 May 2019 22:27
by Filip
If you would be interested in a plugin...
plugin.py.txt
(14.16 KiB) Downloaded 180 times
(remove extension .txt!)
SDM120.zip
(6.05 KiB) Downloaded 138 times
Requires the installation of pymodbus.
Success.

Re: Eastron sdm120c

Posted: Wednesday 29 May 2019 20:09
by ackcsaba
Hello!

I tried to install the SDM120 plugin in Domoticz. After restarting RPi, on the Hardware tab, I chose SMD120c Energy Meter. The following error messages were found in the log:

2019-05-29 19: 47: 11.075 Error: (SDM120) failed to load 'plugin.py', Python Path used was' /home/pi/domoticz/plugins/sdm120/:/usr/lib/python35.zip: /usr/lib/python3.5:/usr/lib/python3.5/plat-arm-linux-gnueabihf:/usr/lib/python3.5/lib-dynload:/usr/local/lib/python3.5/ dist-packages / usr / lib / python3 / dist-packages: /usr/lib/python3.5/dist-packages'.
2019-05-29 19: 47: 11.075 Error: (SDM120) Module Import failed, exception: 'ImportError'
2019-05-29 19: 47: 11.075 Error: (SDM120) Module Import failed: 'Name: pymodbus'
2019-05-29 19: 47: 11.075 Error: (SDM120) Error Line details not available.

What have I done wrong?

Thanks for the help.

Best regards:
Csaba

Re: Eastron sdm120c

Posted: Wednesday 29 May 2019 20:50
by Filip
You have to install pymodbus in python3.

Re: Eastron sdm120c

Posted: Thursday 30 May 2019 16:16
by ackcsaba
Yes. pymodbus installed in python3.