Skip to content

Commit

Permalink
Merge pull request snaptec#1860 from Bembelfan/smaem
Browse files Browse the repository at this point in the history
Smarthome Smaem: Adoption of PR snaptec#1845 regarding SMA packages
  • Loading branch information
benderl authored Jan 9, 2022
2 parents 47ead2a + 33d90c1 commit e9de0ef
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions modules/smarthome/smaem/watt.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
# 2020-01-13 Kevin Wieland changes to run with openWB
# 2020-02-03 theHolgi added phase-wise load and power factor
# 2021-09-01 Markus Giessen adoption for usage as Smart Home Device for energy metering
# 2021-12-25 Markus Giessen adoption of PR 1845 due to SMA protocol change

import sys
import os
Expand Down Expand Up @@ -87,8 +88,17 @@ def abortprogram(signal,frame):
# We also have to take care if there are more than one EnergyMeter in the network sending, that's why we check the modification time in scenario 2.
# Without this check we would generate a ret-file everytime we receive data from a not desired EnergyMeter.
emparts={}
emparts=decode_speedwire(sock.recv(608))
sock_data = sock.recv(608)

# Ignore data package if the length is smaller 18 - this should not happen. If length is smaller 18, the following check for Protocol ID can't work
if len(sock_data) < 18:
sys.exit("Module SMAEM: Invalid data package received. The length of the received data package is smaller than 18 Byte. This should not happen.")

# Ignore data package if the SMA Protocol ID is not 0x6069 - adoption of PR 1845
if sock_data[16:18] != b'\x60\x69':
sys.exit("Module SMAEM: Invalid data package received. No need to worry, this is a normal situation if a SMA HomeManager (2) is sending in the network.")

emparts=decode_speedwire(sock_data)
debugfile.write(str(datetime.datetime.now()) + ': smaserial: #' + str(smaserial) + '# - Current SMA serial number:#' + str(emparts['serial']) + '# - watt:#' + str(int(emparts.get("pconsume"))) + '# - wattc:#' + str("{:.3f}".format(int(emparts.get('pconsumecounter')*1000))) + '#\n')

# Remember: We assume that beside of our EnergyMeter there are more SMA devices present (like HomeManager 2.0 or other EnergyMeter) - so must not accept any data or smaserial = None
Expand Down Expand Up @@ -133,4 +143,4 @@ def abortprogram(signal,frame):
t.close()

debugfile.write(str(datetime.datetime.now()) + ': 99 - Output answer: #' + answer + '#\n')
debugfile.close()
debugfile.close()

0 comments on commit e9de0ef

Please sign in to comment.