datenschuft / SMA-EM

SMA Energymeter measurement
GNU General Public License v2.0
92 stars 38 forks source link

How to get values vom pvdata/smamodbus to show up in mqtt or simplefswriter #30

Closed AnduriI closed 4 years ago

AnduriI commented 4 years ago

Hey there,

I just moved to my new house with pv and want to feed my home automation system with those stats. I got the SMA-EM working and found out the meaning of those values. Now I want to also include the pvdata to also have my inhouse usage stats. Therefor I have a few questions:

Regards, Anduril

datenschuft commented 4 years ago

Hi; add a config section in /etc/smaemd/config called [FEATURE-pvdata] (see ... SMA-EM/features/pvdata.py) (if not present) then add the feature to the list of loaded features (in section [SMA-EM])

list of features to load/run

features=simplefswriter sample pvdata mqtt remotedebug symcon influxdb

restart the daemon - done.

I'm not using mqtt, but the feature mqtt should send pv_data also to the mqtt-host.

I only have an SMA Energy Meter (not even a Home Manager). Since I don't have a battery storage device, I can't add any information or features here. If anyone writes a feature for a battery storage/battery controller, I'll be happy to include it here

Regards, Flo aka datenschuft

AnduriI commented 4 years ago

Hey,

I still don't know how to configure the feature pvdata correctly. Here my config:

[SMA-EM]
# serials of sma-ems the daemon should take notice
# seperated by space
serials=3007888915
# features could filter serials to, but wouldn't see serials if these serials was not defines in SMA-EM serials
# list of features to load/run
features=simplefswriter mqtt pvdata

[DAEMON]
pidfile=/run/smaemd.pid
# listen on an interface with the given ip
# use 0.0.0.0 for any interface
ipbind=0.0.0.0
# multicast ip and port of sma-datagrams
# defaults
mcastgrp=239.12.255.254
mcastport=9522

[...]

[FEATURE-pvdata]
# How frequently to send updates over (defaults to 20 sec)
min_update=20
inv_host : "SMA3006244818"
inv_port : 502
inv_modbus_id : 3
#registers = [
#['address', 'type', 'format', 'description', 'unit', 'value'],
['30057', 'U32', 'RAW', 'serial', ''],
['30201','U32','ENUM',Status',''],
['30775', 'S32', 'FIX0', 'AC Power', 'W']]
#debug output
debug=0
#inverter connection
#inv_host =
inv_manufacturer = SMA

I tried both IP and hostname as host, but still the same result:

python3 /opt/smaemd/sma-daemon.py
simplefswriter: feature enabled
mqtt: feature enabled
feature pvdata not found
Berlenz commented 3 years ago

Hi, I had the same problem: feature pvdata not found Cause: pymodbus was not installed Solution: install pymodbus sudo pip install -U pymodbus or sudo pip3 install -U pymodbus

MichScha commented 3 years ago

Hi, I had the same problem: feature pvdata not found Cause: pymodbus was not installed Solution: install pymodbus sudo pip install -U pymodbus or sudo pip3 install -U pymodbus

Working...

AnduriI commented 3 years ago

Hey @Berlenz @BratHuhn , thanks for your reply. That helped a little. I still suggest to have a config issue with my inverter. Could you be so kind to share your config? Thanks a lot.

Berlenz commented 3 years ago

Hey @Berlenz @BratHuhn , thanks for your reply. That helped a little. I still suggest to have a config issue with my inverter. Could you be so kind to share your config? Thanks a lot.

Hey Anduril,

below you will find my config file. I'm reading data from SMA Sunny Home Manager 2.0 and from SMA STP 20000TL-30 inverter.

ToDo:

  1. Enter serial number of your Home Manager 2.0 - sticker on the home manager unit. My home manager has the serial number 3002854582.
  2. If you want to read data (AC power, ...) from the inverter, enable pvdata feature (features=pvdata)
  3. Configure the items under [FEATURE-pvdata], e.g. enter IP address of the inverter and the Modbus registers you want to read.
  4. I have enabled MQTT feature (features=mqtt) to publish the data to an MQTT broker. My Home Assistant application subscribes the required data from the MQTT broker.
  5. Configure the items under [FEATURE-mqtt], enter IP address of your MQTT broker (I use IP address ::1 because the MQTT broker is running on the same device - raspberry), enter port, user name and user password of your MQTT broker.
  6. Use e.g. software MQTT Explorer to test if the data is published to the MQTT broker.

My config file:

[SMA-EM]
# serials of sma-ems the daemon should take notice
# separated by space
serials=3002854582
# features could filter serials to, but wouldn't see serials if these serials was not defines in SMA-EM serials
# list of features to load/run
#features=simplefswriter sample pvdata mqtt remotedebug symcon influxdb
features=pvdata mqtt

[DAEMON]
pidfile=/run/smaemd.pid
# listen on an interface with the given ip
# use 0.0.0.0 for any interface
ipbind=0.0.0.0
# multicast ip and port of sma-datagrams
# defaults
mcastgrp=239.12.255.254
mcastport=9522
statusdir=

# each feature/plugin has its own section
# called FEATURE-[featurename]
# the feature section is required if a feature is listed in [SMA-EM]features

[FEATURE-simplefswriter]
# list serials simplefswriter notice
serials=30028xxxxx
# measurement vars simplefswriter should write to filesystem (only from smas with serial in serials)
values=pconsume psupply qsupply ssupply
statusdir=

[FEATURE-sample]
nothing=here

[FEATURE-mqtt]
# MQTT broker details
mqtthost=::1
mqttport=1883
mqttuser=enter_user_name_here
mqttpass=enter_user_password_here
#The following list contains all possible field names that you can use with
#the feature mqtt, symcon, influxdb in the file /etc/smaemd/config.
#  prefix:  p=real power, q=reactive power, s=apparent power, i=current, u=voltage
#  postfix: unit=the unit of the item, e.g. W, VA, VAr, Hz, A, V, kWh, kVArh, kVAh ...
#  postfix: counter=energy value (kWh, kVArh, kVAh)
#           without postfix counter=>power value (W, VAr, VA)
#mqttfields=pconsume,  pconsumeunit, pconsumecounter, pconsumecounterunit,
#           psupply,   psupplyunit,  psupplycounter,  psupplycounterunit,
#           qconsume,  qconsumeunit, qconsumecounter, qconsumecounterunit,
#           qsupply,   qsupplyunit,  qsupplycounter,  qsupplycounterunit,
#           sconsume,  sconsumeunit, sconsumecounter, sconsumecounterunit,
#           ssupply,   ssupplyunit,  ssupplycounter,  ssupplycounterunit,
#           cosphi,    cosphiunit,
#           frequency, frequencyunit,
#           p1consume, p1consumeunit, p1consumecounter, p1consumecounterunit,
#           p1supply,  p1supplyunit,  p1supplycounter,  p1supplycounterunit, 
#           q1consume, q1consumeunit, q1consumecounter, q1consumecounterunit, 
#           q1supply,  q1supplyunit,  q1supplycounter,  q1supplycounterunit, 
#           s1consume, s1consumeunit, s1consumecounter, s1consumecounterunit, 
#           s1supply,  s1supplyunit,  s1supplycounter,  s1supplycounterunit, 
#           i1,        i1unit,
#           u1,        u1unit,
#           cosphi1,   cosphi1unit,
#           p2consume, p2consumeunit, p2consumecounter, p2consumecounterunit,
#           p2supply,  p2supplyunit,  p2supplycounter,  p2supplycounterunit, 
#           q2consume, q2consumeunit, q2consumecounter, q2consumecounterunit, 
#           q2supply,  q2supplyunit,  q2supplycounter,  q2supplycounterunit, 
#           s2consume, s2consumeunit, s2consumecounter, s2consumecounterunit, 
#           s2supply,  s2supplyunit,  s2supplycounter,  s2supplycounterunit, 
#           i2,        i2unit,
#           u2,        u2unit,
#           cosphi2,   cosphi2unit,
#           p3consume, p3consumeunit, p3consumecounter, p3consumecounterunit,
#           p3supply,  p3supplyunit,  p3supplycounter,  p3supplycounterunit, 
#           q3consume, q3consumeunit, q3consumecounter, q3consumecounterunit, 
#           q3supply,  q3supplyunit,  q3supplycounter,  q3supplycounterunit, 
#           s3consume, s3consumeunit, s3consumecounter, s3consumecounterunit, 
#           s3supply,  s3supplyunit,  s3supplycounter,  s3supplycounterunit, 
#           i3,        i3unit,
#           u3,        u3unit,
#           cosphi3,   cosphi3unit,
#           speedwire-version
mqttfields=pconsume,pconsumecounter,psupply,psupplycounter,p1consume,p2consume,p3consume,p1supply,p2supply,p3supply,frequency
#topic will be exteded with serial
mqtttopic=SMA-EM/status
pvtopic=SMA-PV/status
# publish all values as single topics (0 or 1)
publish_single=1
# How frequently to send updates over (defaults to 20 sec)
min_update=5
#debug output
debug=0

# ssl support
# adopt mqttport above to your ssl enabled mqtt port, usually 8883
# options:
# activate without certs=use tls_insecure
# activate with ca_file, but without client_certs
ssl_activate=0
# ca file to verify
ssl_ca_file=ca.crt
# client certs
ssl_certfile=
ssl_keyfile=
#TLSv1.1 or TLSv1.2 (default 2)
tls_protocol=2

[FEATURE-remotedebug]
# Debug settings
debughost=mypc
debugport=9100

[FEATURE-symcon]
# symcon
host=ips
port=3777
timeout=5
user=Symcon
password=SMA-EMdata

fields=pconsume,psupply,p1consume,p2consume,p3consume,p1supply,p2supply,p3supply,psupplycounter,pconsumecounter
emhook=/hook/smaem
pvfields=AC Power,grid frequency,DC input voltage,daily yield,total yield,Power L1,Power L2,Power L3,Status
pvhook=/hook/smawr

# How frequently to send updates over (defaults to 20 sec)
min_update=30

debug=1

[FEATURE-influxdb]
# influx
host=influxdb
port=8086
ssl=
db=SMA

timeout=5
user=
password=
# How frequently to send updates over (defaults to 20 sec)
min_update=30

debug=0
#emdata
measurement=SMAEM
fields=pconsume,psupply,p1consume,p2consume,p3consume,p1supply,p2supply,p3supply

#pvdata
pvmeasurement=SMAWR
pvfields=AC Power,grid frequency,DC input voltage,daily yield,total yield,Power L1,Power L2,Power L3

[FEATURE-pvdata]
#Reads data from SMA inverter via Modbus.
#Enable the mqtt feature to publish the data to a mqtt broker (features=pvdata mqtt),
#and/or stored the data to a influx database (features=pvdata influxdb), and/or symcom ...

# How frequently to send updates over (defaults to 20 sec)
min_update=5
#debug output
debug=0

#inverter connection
inv_host = 192.168.178.45
inv_port = 502
inv_modbus_id = 3

#For Modbus registers, see e.g. https://www.google.com/search?q=SMA_Modbus-TI-en-23.xlsx
#['Modbus register address', 'Format', 'Unit', 'Name', 'Type']
#If the mqtt feature is used, 'Name' is included in the MQTT JSON payload as tag name.
registers = [
    ['30057', 'U32', 'RAW', 'serial', ''],               #Don't change 'serial'      => it is used in some features/*.py files. As alternative use the mqtt topic
    ['30201', 'U32', 'ENUM', 'Status',''],               #Don't change 'Status'      => it is used in smamodbus.py to decode the enumeration
    ['30051', 'U32', 'ENUM', 'DeviceClass',''],          #Don't change 'DeviceClass' => it is used in smamodbus.py to decode the enumeration
    ['30053', 'U32', 'ENUM', 'DeviceID',''],             #Don't change 'DeviceID'    => it is used in smamodbus.py to decode the enumeration
#    ['40631', 'STR32', 'UTF8', 'Device_Name', ''],
    ['30775', 'S32', 'FIX0', 'AC Power', 'W'],           #Don't change 'AC Power'    => it is used in some features/*.py files. As alternative use the mqtt topic 'SMA-EM/status/30028xxxxx/pvsum' => 30028xxxxx => see 'serials' above
#    ['30813', 'S32', 'FIX0', 'AC_Power_Apparent', 'VA'],
    ['30977', 'S32', 'FIX3', 'AC_Current', 'A'],
#    ['30783', 'S32', 'FIX2', 'AC_Voltage_L1', 'V'],
#    ['30785', 'S32', 'FIX2', 'AC_Voltage_L2', 'V'],
#    ['30787', 'S32', 'FIX2', 'AC_Voltage_L3', 'V'],
#    ['30777', 'S32', 'FIX0', 'AC_Power_L1', 'W'],
#    ['30779', 'S32', 'FIX0', 'AC_Power_L2', 'W'],
#    ['30781', 'S32', 'FIX0', 'AC_Power_L3', 'W'],
    ['30803', 'U32', 'FIX2', 'Grid_Frequency', 'Hz'],
    ['30773', 'S32', 'FIX0', 'DC_Input1_Power', 'W'],
    ['30771', 'S32', 'FIX2', 'DC_Input1_Voltage', 'V'],
    ['30769', 'S32', 'FIX3', 'DC_Input1_Current', 'A'],
    ['30961', 'S32', 'FIX0', 'DC_Input2_Power', 'W'],
    ['30959', 'S32', 'FIX2', 'DC_Input2_Voltage', 'V'],
    ['30957', 'S32', 'FIX3', 'DC_Input2_Current', 'A'],
    ['30953', 'S32', 'FIX1', 'Device_Temperature', u'\xb0C'],
    ['30517', 'U64', 'FIX3', 'daily yield', 'kWh'],      #Don't change 'daily yield'    => it is used in some features/*.py files. As alternative use the mqtt topic 'SMA-EM/status/30028xxxxx/pvdaily' => 30028xxxxxs => see 'serials' above
    ['30513', 'U64', 'FIX3', 'Total_Yield', 'kWh'],
    ['30521', 'U64', 'FIX0', 'Operating_Time', 's'],
    ['30525', 'U64', 'FIX0', 'Feed-in_Time', 's'],
    ['30975', 'S32', 'FIX2', 'Intermediate_Circuit_Voltage', 'V'],
    ['30225', 'S32', 'FIX0', 'Isolation_Resistance', u'\u03a9']
    ]

[FEATURE-pvdata_kostal_json]
# How frequently to send updates over (defaults to 20 sec)
min_update=15
#debug output
debug=0

#inverter connection
inv_host = <inverter-ip>
#['address', 'NONE', 'NONE' 'description', 'unit']
# to get the same structure of sma pvdata feature
registers = [
      ['33556736', 'NONE', 'NONE', 'DC Power', 'W'],
      ['33555202', 'NONE', 'NONE', 'DC string1 voltage', 'V'],
      ['33555201', 'NONE', 'NONE', 'DC string1 current', 'A'],
      ['33555203', 'NONE', 'NONE', 'DC string1 power', 'W'],
      ['67109120', 'NONE', 'NONE', 'AC Power', 'W'],
      ['67110400', 'NONE', 'NONE', 'AC frequency', 'Hz'],
      ['67110656', 'NONE', 'NONE', 'AC cosphi', u'\xb0C'],
      ['67110144', 'NONE', 'NONE', 'AC ptot limitation', ''],
      ['67109378', 'NONE', 'NONE', 'AC phase1 voltage', 'V'],
      ['67109377', 'NONE', 'NONE', 'AC phase1 current', 'A'],
      ['67109379', 'NONE', 'NONE', 'AC phase1 power', 'W'],
      ['251658754', 'NONE', 'NONE', 'yield today', 'Wh'],
      ['251658753', 'NONE', 'NONE', 'yield total', 'kWh'],
      ['251658496', 'NONE', 'NONE', 'operationtime', ''],
      ]

Current data displayed with the MQTT Explorer. Some values are null because it's dark outside! MQTT

tkocher commented 1 year ago

Hello, I have a similar problem:

if I have installed the debian package python3-pymodbus (2.1.0+dfsg-2) pvdata is not collected, even more I do not see any packet going to the inverter (via tcpdump).

If I have installed the pymodbus via pip (pymodbus-3.0.2-py2.py3-none-any.whl) I see smaemd not starting with the error in syslog: Dependency problem: No module named 'pymodbus.client.sync'

running debian 11

as the sma-em sounds promising I am looking forward to get any support.

Thanks in advance..