I got the DS2242 board from robot-electronics (you can order over: https://www.antratek.de/ds2242).
Because I didn’t find any examples, I experimented around a lot and maybe someone in the future finds this useful.
The Board itself has:
Ethernet connected module, 10/100Mb auto negotiated.
Relays – 2 x 16Amp 250Vac C/O.
Inputs – 4 x analogue or digital. (0-3.3V)
Power – 12VDC 500mA supply required. 2.1mm center positive.
Connections – Screw Terminals for N/O N/C and Common contacts
PCB size – 82mm x 84mm
Controlled graphically by secure webpage or optionally one of ASCII, Binary or Modbus
command sets over TCP/IP.
Line powered (up to 300 meter range) extension modules.
Email notifications – 8 selectable notifications, up to 100 emails/hour max.
Peer to Peer – Control relays on other modules.
Sequencer – Programmable sequence of events
Schedules – Able to schedule events based on time of day/week
Counter/Timers – Count or time events. 20 counts/second Max.
Also available when optionally programming in dScript is a TTL level serial port.
(Source: User Manual v4.10 DS2422, 13.01.2023)
In the configuration.yaml I inserted that line:
modbus: !include modbus.yaml
In the same folder than the configuration.yaml is I created a new file with the filename modbus.yaml.
There I inserted that following code: behind “host” you need to put your ip address of the device.
- name: ds2242
type: tcp
host: 000.000.000.000
port: 502
switches:
- name: DS2242 Relay1
address: 0
write_type: coil
slave: 1
verify:
command_on: 1
command_off: 0
scan_interval: 5
unique_id: modbus_relay1
- name: DS2242 Relay2
address: 1
write_type: coil
slave: 1
verify:
command_on: 1
command_off: 0
scan_interval: 5
unique_id: modbus_relay2
- name: DS2242 Relay3
address: 2
write_type: coil
slave: 1
verify:
command_on: 1
command_off: 0
scan_interval: 5
unique_id: modbus_relay3
- name: DS2242 Relay4
address: 3
write_type: coil
slave: 1
verify:
command_on: 1
command_off: 0
scan_interval: 5
unique_id: modbus_relay4
- name: DS2242 Relay5
address: 4
write_type: coil
slave: 1
verify:
command_on: 1
command_off: 0
scan_interval: 5
unique_id: modbus_relay5
- name: DS2242 Relay6
address: 5
write_type: coil
slave: 1
verify:
command_on: 1
command_off: 0
scan_interval: 5
unique_id: modbus_relay6
- name: DS2242 Relay7
address: 6
write_type: coil
slave: 1
verify:
command_on: 1
command_off: 0
scan_interval: 5
unique_id: modbus_relay7
- name: DS2242 Relay8
address: 7
write_type: coil
slave: 1
verify:
command_on: 1
command_off: 0
scan_interval: 5
unique_id: modbus_relay8
- name: DS2242 Relay9
address: 8
write_type: coil
slave: 1
verify:
command_on: 1
command_off: 0
scan_interval: 5
unique_id: modbus_relay9
- name: DS2242 Relay10
address: 9
write_type: coil
slave: 1
verify:
command_on: 1
command_off: 0
scan_interval: 5
unique_id: modbus_relay10
binary_sensors:
- name: "DS2242 input1"
address: 40
input_type: coil
scan_interval: 5
slave: 1
unique_id: modbus_input1
- name: "DS2242 input2"
address: 41
input_type: coil
scan_interval: 5
slave: 1
unique_id: modbus_input2
- name: "DS2242 input3"
address: 42
input_type: coil
scan_interval: 5
slave: 1
unique_id: modbus_input3
- name: "DS2242 input4"
address: 43
input_type: coil
scan_interval: 5
slave: 1
unique_id: modbus_input4
sensors:
- name: "DS2242 Analog Input1"
slave: 1
address: 0
input_type: input
scan_interval: 5
unique_id: modbus_adc1
state_class: measurement
- name: "DS2242 Analog Input2"
slave: 1
address: 1
input_type: input
scan_interval: 5
unique_id: modbus_adc2
state_class: measurement
- name: "DS2242 Analog Input3"
slave: 1
address: 2
input_type: input
scan_interval: 5
unique_id: modbus_adc3
state_class: measurement
- name: "DS2242 Analog Input4"
slave: 1
address: 3
input_type: input
scan_interval: 5
unique_id: modbus_adc4
state_class: measurement
- name: "DS2242 Counter1"
slave: 1
address: 8
input_type: input
scan_interval: 5
unique_id: modbus_counter1
state_class: measurement
count: 2
data_type: int32
- name: "DS2242 Counter2"
slave: 1
address: 10
input_type: input
scan_interval: 5
unique_id: modbus_counter2
state_class: measurement
count: 2
data_type: int32
- name: "DS2242 Counter3"
slave: 1
address: 12
input_type: input
scan_interval: 5
unique_id: modbus_counter3
state_class: measurement
count: 2
data_type: int32
- name: "DS2242 Counter4"
slave: 1
address: 14
input_type: input
scan_interval: 5
unique_id: modbus_counter4
state_class: measurement
count: 2
data_type: int32
Make sure, that on the web configuration of the ds2242 you activated modbus and set the port to 502. The port must be the same number than you put under “port” in the yaml file.
if you need more Relays or Counters just copy and paste the existing and adjust the individual values and names.
If you need faster scan intervals you can adjust that value for each element. I put in 5 seconds cause for my purposes that is totally enough.
the analogue values for the inputs you can get on input register 0-3 with the values each from 0-1023
if you need further help with modbus, you can check the offical webpage Home Assistant Modbus
If you want to put the switches and inputs on your dashboard, you can use the following code, Just create a new card, switch to code editor view and paste in the code:
type: entities
entities:
- entity: switch.ds2242_relay1
- entity: switch.ds2242_relay2
- entity: switch.ds2242_relay3
- entity: switch.ds2242_relay4
- entity: switch.ds2242_relay5
- entity: switch.ds2242_relay6
- entity: switch.ds2242_relay7
- entity: binary_sensor.ds2242_input1
- entity: binary_sensor.ds2242_input2
- entity: binary_sensor.ds2242_input3
- entity: binary_sensor.ds2242_input4
- entity: sensor.ds2242_analog_input1
- entity: sensor.ds2242_analog_input2
- entity: sensor.ds2242_analog_input3
- entity: sensor.ds2242_analog_input4
- entity: sensor.ds2242_counter1
- entity: sensor.ds2242_counter2
- entity: sensor.ds2242_counter3
The Dashboard looks like that: