Skip to content

Instantly share code, notes, and snippets.

@glynhudson
Created August 18, 2022 00:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save glynhudson/6f7ebc8be0ca594e02a37bf950ff5b75 to your computer and use it in GitHub Desktop.
Save glynhudson/6f7ebc8be0ca594e02a37bf950ff5b75 to your computer and use it in GitHub Desktop.
Samsung ASHP modbus MIM-B19N
import minimalmodbus
import serial
import struct
import time
def millis():
return int(round(time.time() * 1000))
def C(val):
return struct.pack('!H', val)
instrument = minimalmodbus.Instrument('/dev/ttyUSB0', 1)
instrument.serial.port # this is the serial port name
instrument.serial.baudrate = 9600 # Baud
instrument.serial.bytesize = 8
instrument.serial.parity = serial.PARITY_EVEN
instrument.serial.stopbits = 1
instrument.serial.timeout = 1 # seconds
instrument.debug = False
instrument.address = 1 # this is the slave address number
instrument.mode = minimalmodbus.MODE_RTU # rtu or ascii mode
instrument.clear_buffers_before_each_transaction = True
# Switch on DHW
# instrument.write_register(72,1)
# Switch on CH
# instrument.write_register(52,1)
# Set DHW temp to 50 deg C
# instrument.write_register(74,500)
# Set flow temp to 40 deg C - doenst seem to work
# instrument.write_register(68,400)
# Set indoor target temp to 21 deg C
# instrument.write_register(58,210)
# Set away mode on
# instrument.write_register(79,1)
dhw_temp = round(0.1*(instrument.read_register(75,functioncode=3)),2)
return_temp = round(0.1*(instrument.read_register(65,functioncode=3)),2)
flow_temp = round(0.1*(instrument.read_register(66,functioncode=3)),2)
target_flow_temp = round(0.1*(instrument.read_register(68,functioncode=3)),2)
dhw_status = instrument.read_register(72,functioncode=3)
target_dhw_temp = round(0.1*(instrument.read_register(74,functioncode=3)),2)
away_status = instrument.read_register(79,functioncode=3)
ch_status = instrument.read_register(52,functioncode=3)
indoor_temp = round(0.1*(instrument.read_register(59,functioncode=3)),2)
target_indoor_temp = round(0.1*(instrument.read_register(58,functioncode=3)),2)
defrost_status = instrument.read_register(2,functioncode=3)
print ("Central heating status: " + str(ch_status))
print ("Target indoor temp: " + str(target_indoor_temp))
print ("Indoor temp: " + str(indoor_temp))
print ("Target flow temp: " + str(target_flow_temp))
print ("Flow temp: " + str(return_temp))
print ("Return temp: " + str(flow_temp))
print ("DHW status: " + str(dhw_status))
print ("DHW target temp: " + str(target_dhw_temp))
print ("DHW temp: " + str(dhw_temp))
print ("Away mode status: " + str(away_status))
print ("Defrost opperation status: " + str(defrost_status))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment