Marstek Battery plugin

Python and python framework

Moderator: leecollings

User avatar
waltervl
Posts: 5876
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: Marstek Battery plugin

Post by waltervl »

If you cannot have the DR134 send a proper mqtt payload then you could take the route FlyingDomoticz explained earlier:
- With MQTT mapper map the complete message to a text device to store the complete payload in that text device
- With a dzvents script triggered on a change in the text device read the changed message and send the requested data to dummy devices you have created.


Or take a modbus plugin like https://github.com/remcovanvugt/SDM120M ... /plugin.py and modify it to your needs.
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
RNEE
Posts: 26
Joined: Sunday 05 August 2018 10:13
Target OS: Raspberry Pi / ODroid
Domoticz version: 2025.1
Location: Eindhoven area
Contact:

Re: Marstek Battery plugin

Post by RNEE »

waltervl wrote: Friday 11 July 2025 16:54 If you cannot have the DR134 send a proper mqtt payload then you could take the route FlyingDomoticz explained earlier:
- With MQTT mapper map the complete message to a text device to store the complete payload in that text device
- With a dzvents script triggered on a change in the text device read the changed message and send the requested data to dummy devices you have created.


Or take a modbus plugin like https://github.com/remcovanvugt/SDM120M ... /plugin.py and modify it to your needs.
The DR134 sends proper payload, it can be read and manipulated by jq (https://en.m.wikipedia.org/wiki/Jq_(pro ... _language) ) and (https://jqlang.org/)

This is also the solution.
I posted the commandline syntax in a previous post.

It is exactly as you mentioned before in this post:
waltervl wrote: Wednesday 09 July 2025 10:08 If the order in the list is always is the same, so eg batteryvoltage is always the first value in the r_data list you can use the order eg
params.r_data[0].value for batteryvoltage
params.r_data[9].value for internaltemp

Not sure how this could be used in the MQTT mapper JSON configuration file.
This works with ./jq

The problem is Mqttmapper can only process very simple Json files .
Domoticz on Docker on Raspberry PI 5 with 500 Gb NvME|Milight|RFXCOM|Goodwe|Smartstuff P1 meter|Buienradar|Afval kalender|Tuya|deCONZ Conbee II| in development Marstek Homebattery 5,12Kwh via Modbus |
User avatar
waltervl
Posts: 5876
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: Marstek Battery plugin

Post by waltervl »

I do not agree, the JSON that the device is creating is not following normal JSON conventions. It can also be handled by the MQTTmapper but only after serious code changes. And doing it the way you did is definitely not future proof. One single change in format will force to do all other kind of changes.

But hey, if it works for you it works.
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
FlyingDomotic
Posts: 381
Joined: Saturday 27 February 2016 0:30
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Contact:

Re: Marstek Battery plugin

Post by FlyingDomotic »

I agree with @waltervl, even if syntax is correct, this is definitively not a standard JOSN file, where you normally should have all items at the same level.

In your case, what you have to explain to MqttMapper is: please scan all list items, find those having "name"=xxx, find item "value" and use it as value to load device.

I really don't know how to code syntax of this...

However, for complex cases, you may either use another plugin, or tool not linked with Domoticz, or use MqttMapper to extract full (port par of) message, and make you own script to do such kind of extraction.

I'll be please to assist should you want to implement former solution.
User avatar
waltervl
Posts: 5876
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: Marstek Battery plugin

Post by waltervl »

FlyingDomotic wrote: Friday 11 July 2025 22:42 I agree with @waltervl, even if syntax is correct, this is definitively not a standard JOSN file, where you normally should have all items at the same level.

In your case, what you have to explain to MqttMapper is: please scan all list items, find those having "name"=xxx, find item "value" and use it as value to load device.

I really don't know how to code syntax of this...

However, for complex cases, you may either use another plugin, or tool not linked with Domoticz, or use MqttMapper to extract full (port par of) message, and make you own script to do such kind of extraction.

I'll be please to assist should you want to implement former solution.
What perhaps could help is to enable something like

Code: Select all

"mapping": {"item": "params.r_data[9].value"}
In python json

Code: Select all

json_data = json.loads(json_payload)
print(json_data['params']['r_data'][9]['value'])
So support some kind of hardcoding of the parsing of the payload.
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
FlyingDomotic
Posts: 381
Joined: Saturday 27 February 2016 0:30
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Contact:

Re: Marstek Battery plugin

Post by FlyingDomotic »

I was more looking for "scan all list items, find those having "name"=xxx, find item "value" and use it as value to load device", as using fixed index is not so idiot proof ;-)
FlyingDomotic
Posts: 381
Joined: Saturday 27 February 2016 0:30
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Contact:

Re: Marstek Battery plugin

Post by FlyingDomotic »

I should apologize...

Getting back to my code, I discovered it was already able to extract a numbered item from a list for ... a while.

Here's an extract of README.md:

Code: Select all

In certain cases, payload contains lists (represented by [] delimiters).
In this case, you have to specify either list index to use (starting with 1) or * in order to analyze all list items.
Should you really want to extract 10th list item (human starts counting from 1, computers from 0 ;-), you may try this:

Code: Select all

{
	"Marstek internal temperature": {
		"topic": "myTestTopic",
		"type": "80", "subtype": "5", "switchype": "0",
		"mapping": {"item": "params/r_data/10/value", "multiplier": 0.1, "digits": 1}
	}
}
Replace "myTestTopic" by topic name of your real equipment.

For sure, this will provide amazing things if list order changes for any reason.
User avatar
waltervl
Posts: 5876
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: Marstek Battery plugin

Post by waltervl »

FlyingDomotic wrote: Saturday 12 July 2025 0:18 I should apologize...

Getting back to my code, I discovered it was already able to extract a numbered item from a list for ... a while.

Here's an extract of README.md:

Code: Select all

In certain cases, payload contains lists (represented by [] delimiters).
In this case, you have to specify either list index to use (starting with 1) or * in order to analyze all list items.
.........

For sure, this will provide amazing things if list order changes for any reason.
Great news. I was looking at your code just now and found out it was already supporting deeper json values.
I would advise you to create a separate French and English readme as it is very difficult to understand what I read.
If you need help a can send you a PR for this it soon.

@RNEE please check out this "new" solution.

Code: Select all

"mapping": {"item": "params/r_data/10/value", "multiplier": 0.1, "digits": 1}
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
FlyingDomotic
Posts: 381
Joined: Saturday 27 February 2016 0:30
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Contact:

Re: Marstek Battery plugin

Post by FlyingDomotic »

I'll provide a new README.md file with a full English version, followed by a full French version, in the same document BUT continuous for each language.
RNEE
Posts: 26
Joined: Sunday 05 August 2018 10:13
Target OS: Raspberry Pi / ODroid
Domoticz version: 2025.1
Location: Eindhoven area
Contact:

Re: Marstek Battery plugin

Post by RNEE »

Thank you Waltervl and Flyingdomotic.
This is the kind of help i was looking for !

And i see it kept you busy for many hours :idea:
It kept me busy too.
Well : Thanks again!

We can’t blame the device , it nicely performs many tasks in a single small package. The device doesn’t know what data it processes and can be used for a lot of different modbus devices on RS485.
Many use API’s from vendor websites and / or currently need a dedicated plugin.

I don’t think it is a problem to use fixed adressing because the modbus device is used on my own location. The Dr134 only sends data i select.

These now can be replaced with Mqttmapper and a single configuration line !
Instead of getting old data every 30 seconds from not always running API’s (i hate that) you can have live data from your device !
I think this is great!

I have 2 (one with wifi and one with fixed Lan port) now for use with my Goodwe solar convertor and Marstek battery.

I come back with my findings!
Domoticz on Docker on Raspberry PI 5 with 500 Gb NvME|Milight|RFXCOM|Goodwe|Smartstuff P1 meter|Buienradar|Afval kalender|Tuya|deCONZ Conbee II| in development Marstek Homebattery 5,12Kwh via Modbus |
FlyingDomotic
Posts: 381
Joined: Saturday 27 February 2016 0:30
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Contact:

Re: Marstek Battery plugin

Post by FlyingDomotic »

FlyingDomotic wrote: Saturday 12 July 2025 1:00 I'll provide a new README.md file with a full English version, followed by a full French version, in the same document BUT continuous for each language.
Done, new README.md contains now English version followed by French one!
User avatar
waltervl
Posts: 5876
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: Marstek Battery plugin

Post by waltervl »

FlyingDomotic wrote: Saturday 12 July 2025 9:37
FlyingDomotic wrote: Saturday 12 July 2025 1:00 I'll provide a new README.md file with a full English version, followed by a full French version, in the same document BUT continuous for each language.
Done, new README.md contains now English version followed by French one!
Thanks!
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
RNEE
Posts: 26
Joined: Sunday 05 August 2018 10:13
Target OS: Raspberry Pi / ODroid
Domoticz version: 2025.1
Location: Eindhoven area
Contact:

Re: Marstek Battery plugin

Post by RNEE »

To bad , can't get it running (tried a lot of things):

Message in Mosquito / MQTT Explorer :

Code: Select all

{"params":{"dir":"up","id":"02103225061700034587","r_data":[{"name":"batterySOC","value":"99","err":"0"},{"name":"ACpower","value":"-1153","err":"0"}]}}
Json for MqttMapper :

Code: Select all

{
	"Marstek_SOC": {
		"topic": "Marstek",
		"type": "243", "subtype": "6", "switchype": "0",
		"mapping": {"item": "params/r_data/0/value", "multiplier": 1, "digits": 1}
	}
}
Device is created in but does not get value's

Logging :

Code: Select all

2025-07-12 12:52:01.897 Status: MQTT Mapper for DR134: Stop directive received.
2025-07-12 12:52:01.897 MQTT Mapper for DR134: Message handler 'onStop' not callable, ignored.
2025-07-12 12:52:01.903 Status: MQTT Mapper for DR134: Exiting work loop.
2025-07-12 12:52:01.997 Status: MQTT Mapper for DR134: Stopping threads.
2025-07-12 12:52:01.997 Status: MQTT Mapper for DR134: Stopped.
2025-07-12 12:52:01.997 Status: MQTT Mapper for DR134: Entering work loop.
2025-07-12 12:52:01.997 MQTT Mapper for DR134: Worker thread started.
2025-07-12 12:52:01.997 Status: MQTT Mapper for DR134: Started.
2025-07-12 12:52:02.075 Status: MQTT Mapper for DR134: Initialized version 25.6.24-1, author 'Flying Domotic'
2025-07-12 12:52:02.076 MQTT Mapper for DR134: 'HardwareID': '33'
2025-07-12 12:52:02.076 MQTT Mapper for DR134: 'HomeFolder': '/opt/domoticz/userdata/plugins/MqttMapper/'
2025-07-12 12:52:02.076 MQTT Mapper for DR134: 'StartupFolder': '/opt/domoticz/'
2025-07-12 12:52:02.076 MQTT Mapper for DR134: 'UserDataFolder': '/opt/domoticz/userdata/'
2025-07-12 12:52:02.076 MQTT Mapper for DR134: 'Database': '/opt/domoticz/userdata/domoticz.db'
2025-07-12 12:52:02.076 MQTT Mapper for DR134: 'Language': 'en'
2025-07-12 12:52:02.076 MQTT Mapper for DR134: 'Version': '25.6.24-1'
2025-07-12 12:52:02.076 MQTT Mapper for DR134: 'Author': 'Flying Domotic'
2025-07-12 12:52:02.076 MQTT Mapper for DR134: 'Name': 'MQTT Mapper for DR134'
2025-07-12 12:52:02.076 MQTT Mapper for DR134: 'Address': '192.168.2.32'
2025-07-12 12:52:02.076 MQTT Mapper for DR134: 'Port': '1883'
2025-07-12 12:52:02.076 MQTT Mapper for DR134: 'Username': 'rene'
2025-07-12 12:52:02.076 MQTT Mapper for DR134: 'Password': 'rene'
2025-07-12 12:52:02.076 MQTT Mapper for DR134: 'Key': 'MqttMapper'
2025-07-12 12:52:02.076 MQTT Mapper for DR134: 'Mode1': 'MqttMapper.json'
2025-07-12 12:52:02.076 MQTT Mapper for DR134: 'Mode6': 'Verbose+'
2025-07-12 12:52:02.076 MQTT Mapper for DR134: 'DomoticzVersion': '2025.1 (build 16672)'
2025-07-12 12:52:02.076 MQTT Mapper for DR134: 'DomoticzHash': '7f861f5bd'
2025-07-12 12:52:02.076 MQTT Mapper for DR134: 'DomoticzBuildTime': '2025-05-05 08:31:45'
2025-07-12 12:52:02.076 MQTT Mapper for DR134: Device count: 1
2025-07-12 12:52:02.076 MQTT Mapper for DR134: Device: 1 - ID: 2443, Name: 'MQTT Mapper for DR134 - Marstek_SOC', nValue: 0, sValue: ''
2025-07-12 12:52:02.076 MQTT Mapper for DR134: Debug logging mask set to: PYTHON PLUGIN QUEUE DEVICE CONNECTION MESSAGE
2025-07-12 12:52:02.076 MQTT Mapper for DR134: Updating device Marstek_SOC
2025-07-12 12:52:02.076 (MQTT Mapper for DR134 - Marstek_SOC) Updating device from 0:'' to have values 0:''.
2025-07-12 12:52:02.076 MQTT Mapper for DR134: Pushing 'CPluginMessageBase' on to queue
2025-07-12 12:52:02.077 Error: Invalid Number sValue: '%' for device idx: '%'
2025-07-12 12:52:02.079 MQTT Mapper for DR134: MqttClient::__init__
2025-07-12 12:52:02.079 MQTT Mapper for DR134: Pushing 'ProtocolDirective' on to queue
2025-07-12 12:52:02.079 MQTT Mapper for DR134: Pushing 'ConnectDirective' on to queue
2025-07-12 12:52:02.080 MQTT Mapper for DR134: Pushing 'PollIntervalDirective' on to queue
2025-07-12 12:52:02.080 MQTT Mapper for DR134: Processing 'CPluginMessageBase' message
2025-07-12 12:52:02.080 MQTT Mapper for DR134: Calling message handler 'onDeviceAdded' on 'module' type object.
2025-07-12 12:52:02.080 MQTT Mapper for DR134: onDeviceAdded 001/MQTT Mapper for DR134 - Marstek_SOC
2025-07-12 12:52:02.080 MQTT Mapper for DR134: Processing 'ProtocolDirective' message
2025-07-12 12:52:02.080 MQTT Mapper for DR134: Protocol set to: 'MQTT'.
2025-07-12 12:52:02.080 MQTT Mapper for DR134: Processing 'ConnectDirective' message
2025-07-12 12:52:02.080 MQTT Mapper for DR134: Transport set to: 'TCP/IP', 192.168.2.32:1883.
2025-07-12 12:52:02.080 MQTT Mapper for DR134: Connect directive received, action initiated successfully.
2025-07-12 12:52:02.080 MQTT Mapper for DR134: Processing 'PollIntervalDirective' message
2025-07-12 12:52:02.080 MQTT Mapper for DR134: Heartbeat interval set to: 3.
2025-07-12 12:52:02.081 MQTT Mapper for DR134: Pushing 'onConnectCallback' on to queue
2025-07-12 12:52:02.130 MQTT Mapper for DR134: Processing 'onConnectCallback' message
2025-07-12 12:52:02.130 MQTT Mapper for DR134: Calling message handler 'onConnect' on 'module' type object.
2025-07-12 12:52:02.130 MQTT Mapper for DR134: MqttClient::onConnect
2025-07-12 12:52:02.130 MQTT Mapper for DR134: MqttClient::onConnect connect to 192.168.2.32:1883, ID=Domoticz_MqttMapper_33_1752317522
2025-07-12 12:52:02.130 MQTT Mapper for DR134: Pushing 'WriteDirective' on to queue
2025-07-12 12:52:02.130 MQTT Mapper for DR134: Processing 'WriteDirective' message
2025-07-12 12:52:02.130 MQTT Mapper for DR134: Sending 59 bytes of data
2025-07-12 12:52:02.130 MQTT Mapper for DR134: 10 39 00 04 4d 51 54 54 04 c2 00 3c 00 21 44 6f 6d 6f 74 69 .9..MQTT.®<.!Domoti
2025-07-12 12:52:02.130 MQTT Mapper for DR134: 63 7a 5f 4d 71 74 74 4d 61 70 70 65 72 5f 33 33 5f 31 37 35 cz_MqttMapper_33_175
2025-07-12 12:52:02.130 MQTT Mapper for DR134: 32 33 31 37 35 32 32 00 04 72 65 6e 65 00 04 72 65 6e 65 .. 2317522..rene..rene
2025-07-12 12:52:02.131 MQTT Mapper for DR134: Pushing 'ReadEvent' on to queue
2025-07-12 12:52:02.181 MQTT Mapper for DR134: Processing 'ReadEvent' message
2025-07-12 12:52:02.181 MQTT Mapper for DR134: Received 4 bytes of data
2025-07-12 12:52:02.181 MQTT Mapper for DR134: 20 02 00 00 .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. ....
2025-07-12 12:52:02.181 MQTT Mapper for DR134: Pushing 'onMessageCallback' on to queue
2025-07-12 12:52:02.181 MQTT Mapper for DR134: Processing 'onMessageCallback' message
2025-07-12 12:52:02.181 MQTT Mapper for DR134: Calling message handler 'onMessage' on 'module' type object.
2025-07-12 12:52:02.181 MQTT Mapper for DR134: onMQTTConnected
2025-07-12 12:52:02.181 MQTT Mapper for DR134: getTopics: '{'Marstek'}'
2025-07-12 12:52:02.181 MQTT Mapper for DR134: MqttClient::Subscribe to [{'Topic': 'Marstek', 'QoS': 0}]
2025-07-12 12:52:02.181 MQTT Mapper for DR134: Pushing 'WriteDirective' on to queue
2025-07-12 12:52:02.181 MQTT Mapper for DR134: Processing 'WriteDirective' message
2025-07-12 12:52:02.181 MQTT Mapper for DR134: Sending 14 bytes of data
2025-07-12 12:52:02.181 MQTT Mapper for DR134: 82 0c 00 01 00 07 4d 61 72 73 74 65 6b 00 .. .. .. .. .. .. ®....Marstek.
2025-07-12 12:52:02.181 MQTT Mapper for DR134: Pushing 'ReadEvent' on to queue
2025-07-12 12:52:02.231 MQTT Mapper for DR134: Processing 'ReadEvent' message
2025-07-12 12:52:02.231 MQTT Mapper for DR134: Received 5 bytes of data
2025-07-12 12:52:02.231 MQTT Mapper for DR134: 90 03 00 01 00 .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. Ю...
2025-07-12 12:52:02.231 MQTT Mapper for DR134: Pushing 'onMessageCallback' on to queue
2025-07-12 12:52:02.231 MQTT Mapper for DR134: Processing 'onMessageCallback' message
2025-07-12 12:52:02.231 MQTT Mapper for DR134: Calling message handler 'onMessage' on 'module' type object.
2025-07-12 12:52:02.231 MQTT Mapper for DR134: onMQTTSubscribed

Error : 2025-07-12 12:52:02.077 Error: Invalid Number sValue: '%' for device idx: '%'

When Type /subtype changed the error is gone.
Domoticz on Docker on Raspberry PI 5 with 500 Gb NvME|Milight|RFXCOM|Goodwe|Smartstuff P1 meter|Buienradar|Afval kalender|Tuya|deCONZ Conbee II| in development Marstek Homebattery 5,12Kwh via Modbus |
User avatar
waltervl
Posts: 5876
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: Marstek Battery plugin

Post by waltervl »

First parameter in the payload array so should be 1 instead of 0. FlyingDomotic uses the human way of counting, starting with 1 instead of the computer way, starting with 0.
So
"item": "params/r_data/1/value"
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
RNEE
Posts: 26
Joined: Sunday 05 August 2018 10:13
Target OS: Raspberry Pi / ODroid
Domoticz version: 2025.1
Location: Eindhoven area
Contact:

Re: Marstek Battery plugin

Post by RNEE »

i tried many combinations, does not work.

It seems nothing is send back from Mosquito.

Code: Select all

2025-07-12 14:45:20.021 MQTT Mapper for DR134: Pushing 'onHeartbeatCallback' on to queue
2025-07-12 14:45:20.071 MQTT Mapper for DR134: Processing 'onHeartbeatCallback' message
2025-07-12 14:45:20.071 MQTT Mapper for DR134: Calling message handler 'onHeartbeat' on 'module' type object.
2025-07-12 14:45:20.071 MQTT Mapper for DR134: Pushing 'WriteDirective' on to queue
2025-07-12 14:45:20.071 MQTT Mapper for DR134: Processing 'WriteDirective' message
2025-07-12 14:45:20.071 MQTT Mapper for DR134: Sending 2 bytes of data
2025-07-12 14:45:20.071 MQTT Mapper for DR134: c0 00 .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. �
2025-07-12 14:45:20.072 MQTT Mapper for DR134: Pushing 'ReadEvent' on to queue
2025-07-12 14:45:20.122 MQTT Mapper for DR134: Processing 'ReadEvent' message
2025-07-12 14:45:20.122 MQTT Mapper for DR134: Received 2 bytes of data
2025-07-12 14:45:20.122 MQTT Mapper for DR134: d0 00 .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. Ю
2025-07-12 14:45:20.122 MQTT Mapper for DR134: Pushing 'onMessageCallback' on to queue
2025-07-12 14:45:20.122 MQTT Mapper for DR134: Processing 'onMessageCallback' message
2025-07-12 14:45:20.122 MQTT Mapper for DR134: Calling message handler 'onMessage' on 'module' type object.
2025-07-12 14:45:23.025 MQTT Mapper for DR134: Pushing 'onHeartbeatCallback' on to queue
2025-07-12 14:45:23.076 MQTT Mapper for DR134: Processing 'onHeartbeatCallback' message
2025-07-12 14:45:23.076 MQTT Mapper for DR134: Calling message handler 'onHeartbeat' on 'module' type object.
2025-07-12 14:45:23.076 MQTT Mapper for DR134: Pushing 'WriteDirective' on to queue
2025-07-12 14:45:23.076 MQTT Mapper for DR134: Processing 'WriteDirective' message
2025-07-12 14:45:23.076 MQTT Mapper for DR134: Sending 2 bytes of data
2025-07-12 14:45:23.076 MQTT Mapper for DR134: c0 00 .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. �
2025-07-12 14:45:23.077 MQTT Mapper for DR134: Pushing 'ReadEvent' on to queue
2025-07-12 14:45:23.126 MQTT Mapper for DR134: Processing 'ReadEvent' message
2025-07-12 14:45:23.126 MQTT Mapper for DR134: Received 2 bytes of data
2025-07-12 14:45:23.126 MQTT Mapper for DR134: d0 00 .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. Ю
2025-07-12 14:45:23.127 MQTT Mapper for DR134: Pushing 'onMessageCallback' on to queue
2025-07-12 14:45:23.127 MQTT Mapper for DR134: Processing 'onMessageCallback' message
2025-07-12 14:45:23.127 MQTT Mapper for DR134: Calling message handler 'onMessage' on 'module' type object.
2025-07-12 14:45:26.032 MQTT Mapper for DR134: Pushing 'onHeartbeatCallback' on to queue
2025-07-12 14:45:26.082 MQTT Mapper for DR134: Processing 'onHeartbeatCallback' message
2025-07-12 14:45:26.082 MQTT Mapper for DR134: Calling message handler 'onHeartbeat' on 'module' type object.
2025-07-12 14:45:26.082 MQTT Mapper for DR134: Pushing 'WriteDirective' on to queue
2025-07-12 14:45:26.082 MQTT Mapper for DR134: Processing 'WriteDirective' message
2025-07-12 14:45:26.082 MQTT Mapper for DR134: Sending 2 bytes of data
2025-07-12 14:45:26.082 MQTT Mapper for DR134: c0 00 .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. �
Domoticz on Docker on Raspberry PI 5 with 500 Gb NvME|Milight|RFXCOM|Goodwe|Smartstuff P1 meter|Buienradar|Afval kalender|Tuya|deCONZ Conbee II| in development Marstek Homebattery 5,12Kwh via Modbus |
FlyingDomotic
Posts: 381
Joined: Saturday 27 February 2016 0:30
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Contact:

Re: Marstek Battery plugin

Post by FlyingDomotic »

Would it be possible to turn debug to "Verbose"?

Could you also check that MQTT topic really is "Marstek" (take care of upper/lowercases)?

Should you use same ("Marstek") topic more than once, ensure you properly set a "key" item for each device.
RNEE
Posts: 26
Joined: Sunday 05 August 2018 10:13
Target OS: Raspberry Pi / ODroid
Domoticz version: 2025.1
Location: Eindhoven area
Contact:

Re: Marstek Battery plugin

Post by RNEE »

Image

I set previously set to Verbose +, now it is only this :

Code: Select all

2025-07-12 15:30:21.081 MQTT Mapper for DR134: Sending 2 bytes of data
2025-07-12 15:30:21.081 MQTT Mapper for DR134: c0 00 .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. �
2025-07-12 15:30:21.131 MQTT Mapper for DR134: Received 2 bytes of data
2025-07-12 15:30:21.131 MQTT Mapper for DR134: d0 00 .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. Ю
When i run this :

Code: Select all

mosquitto_sub -t /Marstek/# -h 192.168.2.32 -p 1883 -u rene -P rene |jq -r --unbuffered '.[].r_data[1].value'|mosquitto_pub -t ACPower -l -h 192.168.2.32 -p 1883 -u rene -P rene
The AC Power (2nd item) is posted to Mosquito.
Domoticz on Docker on Raspberry PI 5 with 500 Gb NvME|Milight|RFXCOM|Goodwe|Smartstuff P1 meter|Buienradar|Afval kalender|Tuya|deCONZ Conbee II| in development Marstek Homebattery 5,12Kwh via Modbus |
RNEE
Posts: 26
Joined: Sunday 05 August 2018 10:13
Target OS: Raspberry Pi / ODroid
Domoticz version: 2025.1
Location: Eindhoven area
Contact:

Re: Marstek Battery plugin

Post by RNEE »

I changed the topic to : "topic": "/Marstek/#",

Code: Select all

 2025-07-12 15:45:01.525 MQTT Mapper for DR134: 30 a2 01 00 08 2f 4d 61 72 73 74 65 6b 7b 22 70 61 72 61 6d 0®../Marstek{"param
2025-07-12 15:45:01.525 MQTT Mapper for DR134: 73 22 3a 7b 22 64 69 72 22 3a 22 75 70 22 2c 22 69 64 22 3a s":{"dir":"up","id":
2025-07-12 15:45:01.525 MQTT Mapper for DR134: 22 30 32 31 30 33 32 32 35 30 36 31 37 30 30 30 33 34 35 38 "0210322506170003458
2025-07-12 15:45:01.525 MQTT Mapper for DR134: 37 22 2c 22 72 5f 64 61 74 61 22 3a 5b 7b 22 6e 61 6d 65 22 7","r_data":[{"name"
2025-07-12 15:45:01.525 MQTT Mapper for DR134: 3a 22 62 61 74 74 65 72 79 53 4f 43 22 2c 22 76 61 6c 75 65 :"batterySOC","value
2025-07-12 15:45:01.525 MQTT Mapper for DR134: 22 3a 22 38 36 22 2c 22 65 72 72 22 3a 22 30 22 7d 2c 7b 22 ":"86","err":"0"},{"
2025-07-12 15:45:01.525 MQTT Mapper for DR134: 6e 61 6d 65 22 3a 22 41 43 70 6f 77 65 72 22 2c 22 76 61 6c name":"ACpower","val
2025-07-12 15:45:01.526 MQTT Mapper for DR134: 75 65 22 3a 22 2d 31 31 30 33 22 2c 22 65 72 72 22 3a 22 30 ue":"-1103","err":"0
2025-07-12 15:45:01.526 MQTT Mapper for DR134: 22 7d 5d 7d 7d .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. "}]}}
2025-07-12 15:45:04.079 MQTT Mapper for DR134: Sending 2 bytes of data
2025-07-12 15:45:04.079 MQTT Mapper for DR134: c0 00 .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. �
2025-07-12 15:45:04.129 MQTT Mapper for DR134: Received 2 bytes of data
2025-07-12 15:45:04.129 MQTT Mapper for DR134: d0 00 .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. Ю
2025-07-12 15:45:06.532 MQTT Mapper for DR134: Received 165 bytes of data
2025-07-12 15:45:06.532 MQTT Mapper for DR134: 30 a2 01 00 08 2f 4d 61 72 73 74 65 6b 7b 22 70 61 72 61 6d 0®../Marstek{"param
2025-07-12 15:45:06.532 MQTT Mapper for DR134: 73 22 3a 7b 22 64 69 72 22 3a 22 75 70 22 2c 22 69 64 22 3a s":{"dir":"up","id":
2025-07-12 15:45:06.532 MQTT Mapper for DR134: 22 30 32 31 30 33 32 32 35 30 36 31 37 30 30 30 33 34 35 38 "0210322506170003458
2025-07-12 15:45:06.532 MQTT Mapper for DR134: 37 22 2c 22 72 5f 64 61 74 61 22 3a 5b 7b 22 6e 61 6d 65 22 7","r_data":[{"name"
2025-07-12 15:45:06.532 MQTT Mapper for DR134: 3a 22 62 61 74 74 65 72 79 53 4f 43 22 2c 22 76 61 6c 75 65 :"batterySOC","value
2025-07-12 15:45:06.532 MQTT Mapper for DR134: 22 3a 22 38 36 22 2c 22 65 72 72 22 3a 22 30 22 7d 2c 7b 22 ":"86","err":"0"},{"
2025-07-12 15:45:06.532 MQTT Mapper for DR134: 6e 61 6d 65 22 3a 22 41 43 70 6f 77 65 72 22 2c 22 76 61 6c name":"ACpower","val
2025-07-12 15:45:06.532 MQTT Mapper for DR134: 75 65 22 3a 22 2d 31 31 33 39 22 2c 22 65 72 72 22 3a 22 30 ue":"-1139","err":"0
2025-07-12 15:45:06.532 MQTT Mapper for DR134: 22 7d 5d 7d 7d .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. "}]}}
2025-07-12 15:45:07.026 deCONZ: Pushing 'onHeartbeatCallback' on to queue
2025-07-12 15:45:07.049 Tuya: Pushing 'onHeartbeatCallback' on to queue
2025-07-12 15:45:07.077 deCONZ: Processing 'onHeartbeatCallback' message
2025-07-12 15:45:07.077 deCONZ: Acquiring GIL for 'onHeartbeatCallback'
The complete message is returned!
Domoticz on Docker on Raspberry PI 5 with 500 Gb NvME|Milight|RFXCOM|Goodwe|Smartstuff P1 meter|Buienradar|Afval kalender|Tuya|deCONZ Conbee II| in development Marstek Homebattery 5,12Kwh via Modbus |
User avatar
waltervl
Posts: 5876
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: Marstek Battery plugin

Post by waltervl »

It works for me.
Normal log from Domoticz (no debug or something)

Code: Select all

2025-07-12 18:07:59.193 MQTTmapper: onMQTTPublish found Marstek, Device 'MQTTmapper - Marstek_SOC', message '{'params': {'dir': 'up', 'id': 'xxxxxxxxxx', 'r_data': [{'name': 'batteryvoltage', 'value': '5426', 'err': '0'}, {'name': 'batterycurrent', 'value': '4373', 'err': '0'}, {'name': 'batterypower', 'value': '2374', 'err': '0'}, {'name': 'batterySOC', 'value': '57', 'err': '0'}, {'name': 'batterytotalenergy', 'value': '5120', 'err': '0'}, {'name': 'ACvoltage', 'value': '2341', 'err': '0'}, {'name': 'ACcurrent', 'value': '1045', 'err': '0'}, {'name': 'ACpower', 'value': '-2344', 'err': '0'}, {'name': 'ACfrequency', 'value': '4999', 'err': '0'}, {'name': 'internaltemp', 'value': '417', 'err': '0'}]}}'
2025-07-12 18:07:59.193 MQTTmapper: Setting MQTTmapper - Marstek_SOC to 57/57.0
2025-07-12 18:07:59.193 (MQTTmapper - Marstek_SOC) Updating device from 58:'58.0' to have values 57:'57.0'. 
This is the mqttmapper json part:

Code: Select all

{
	"Marstek_SOC": {
		"topic": "Marstek",
		"type": "243", "subtype": "6", "switchype": "0",
		"mapping": {"item": "params/r_data/4/value", "multiplier": 1, "digits": 1}
	}
}
And when I publish the following payload to Marstek topic with MQTT explorer I get the percentage value updated as seen in the log above.

Code: Select all

{
  "params": {
    "dir": "up",
    "id": "xxxxxxxxxx",
    "r_data": [
      {
        "name": "batteryvoltage",
        "value": "5426",
        "err": "0"
      },
      {
        "name": "batterycurrent",
        "value": "4373",
        "err": "0"
      },
      {
        "name": "batterypower",
        "value": "2374",
        "err": "0"
      },
      {
        "name": "batterySOC",
        "value": "57",
        "err": "0"
      },
      {
        "name": "batterytotalenergy",
        "value": "5120",
        "err": "0"
      },
      {
        "name": "ACvoltage",
        "value": "2341",
        "err": "0"
      },
      {
        "name": "ACcurrent",
        "value": "1045",
        "err": "0"
      },
      {
        "name": "ACpower",
        "value": "-2344",
        "err": "0"
      },
      {
        "name": "ACfrequency",
        "value": "4999",
        "err": "0"
      },
      {
        "name": "internaltemp",
        "value": "417",
        "err": "0"
      }
    ]
  }
}
So perhaps just use the exact payload that is coming out of the ModbustoSerial device without modifying it with JQ
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
FlyingDomotic
Posts: 381
Joined: Saturday 27 February 2016 0:30
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Contact:

Re: Marstek Battery plugin

Post by FlyingDomotic »

RNEE wrote: Saturday 12 July 2025 15:48 I changed the topic to : "topic": "/Marstek/#",

Code: Select all

 2025-07-12 15:45:01.525 MQTT Mapper for DR134: 30 a2 01 00 08 2f 4d 61 72 73 74 65 6b 7b 22 70 61 72 61 6d 0®../Marstek{"param
2025-07-12 15:45:01.525 MQTT Mapper for DR134: 73 22 3a 7b 22 64 69 72 22 3a 22 75 70 22 2c 22 69 64 22 3a s":{"dir":"up","id":
2025-07-12 15:45:01.525 MQTT Mapper for DR134: 22 30 32 31 30 33 32 32 35 30 36 31 37 30 30 30 33 34 35 38 "0210322506170003458
2025-07-12 15:45:01.525 MQTT Mapper for DR134: 37 22 2c 22 72 5f 64 61 74 61 22 3a 5b 7b 22 6e 61 6d 65 22 7","r_data":[{"name"
2025-07-12 15:45:01.525 MQTT Mapper for DR134: 3a 22 62 61 74 74 65 72 79 53 4f 43 22 2c 22 76 61 6c 75 65 :"batterySOC","value
2025-07-12 15:45:01.525 MQTT Mapper for DR134: 22 3a 22 38 36 22 2c 22 65 72 72 22 3a 22 30 22 7d 2c 7b 22 ":"86","err":"0"},{"
2025-07-12 15:45:01.525 MQTT Mapper for DR134: 6e 61 6d 65 22 3a 22 41 43 70 6f 77 65 72 22 2c 22 76 61 6c name":"ACpower","val
2025-07-12 15:45:01.526 MQTT Mapper for DR134: 75 65 22 3a 22 2d 31 31 30 33 22 2c 22 65 72 72 22 3a 22 30 ue":"-1103","err":"0
2025-07-12 15:45:01.526 MQTT Mapper for DR134: 22 7d 5d 7d 7d .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. "}]}}
2025-07-12 15:45:04.079 MQTT Mapper for DR134: Sending 2 bytes of data
2025-07-12 15:45:04.079 MQTT Mapper for DR134: c0 00 .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. �
2025-07-12 15:45:04.129 MQTT Mapper for DR134: Received 2 bytes of data
2025-07-12 15:45:04.129 MQTT Mapper for DR134: d0 00 .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. Ю
2025-07-12 15:45:06.532 MQTT Mapper for DR134: Received 165 bytes of data
2025-07-12 15:45:06.532 MQTT Mapper for DR134: 30 a2 01 00 08 2f 4d 61 72 73 74 65 6b 7b 22 70 61 72 61 6d 0®../Marstek{"param
2025-07-12 15:45:06.532 MQTT Mapper for DR134: 73 22 3a 7b 22 64 69 72 22 3a 22 75 70 22 2c 22 69 64 22 3a s":{"dir":"up","id":
2025-07-12 15:45:06.532 MQTT Mapper for DR134: 22 30 32 31 30 33 32 32 35 30 36 31 37 30 30 30 33 34 35 38 "0210322506170003458
2025-07-12 15:45:06.532 MQTT Mapper for DR134: 37 22 2c 22 72 5f 64 61 74 61 22 3a 5b 7b 22 6e 61 6d 65 22 7","r_data":[{"name"
2025-07-12 15:45:06.532 MQTT Mapper for DR134: 3a 22 62 61 74 74 65 72 79 53 4f 43 22 2c 22 76 61 6c 75 65 :"batterySOC","value
2025-07-12 15:45:06.532 MQTT Mapper for DR134: 22 3a 22 38 36 22 2c 22 65 72 72 22 3a 22 30 22 7d 2c 7b 22 ":"86","err":"0"},{"
2025-07-12 15:45:06.532 MQTT Mapper for DR134: 6e 61 6d 65 22 3a 22 41 43 70 6f 77 65 72 22 2c 22 76 61 6c name":"ACpower","val
2025-07-12 15:45:06.532 MQTT Mapper for DR134: 75 65 22 3a 22 2d 31 31 33 39 22 2c 22 65 72 72 22 3a 22 30 ue":"-1139","err":"0
2025-07-12 15:45:06.532 MQTT Mapper for DR134: 22 7d 5d 7d 7d .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. "}]}}
2025-07-12 15:45:07.026 deCONZ: Pushing 'onHeartbeatCallback' on to queue
2025-07-12 15:45:07.049 Tuya: Pushing 'onHeartbeatCallback' on to queue
2025-07-12 15:45:07.077 deCONZ: Processing 'onHeartbeatCallback' message
2025-07-12 15:45:07.077 deCONZ: Acquiring GIL for 'onHeartbeatCallback'
The complete message is returned!
There probably a configuration error somewhere, as top level topics are not empty (don't start by "/").

However, this seems to work, so don't try to fix something working ;-)
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest