Marstek OpenAPI
Moderators: leecollings, remb0
-
tonbor
- Posts: 157
- Joined: Monday 17 February 2014 9:12
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Marstek OpenAPI
Use the new plugin Marstek open API. Working ok. But have a problem with the Energy Dashboard. Added Marstek battery. But the flow is the wrong way. Negative mains flow to battery. Besides the flow is from sun panels and not from house to marstek battery
- Attachments
-
- Wrong way 2026-02-25 124011.png (164.52 KiB) Viewed 133 times
-
- 2026-02-25 125318.png (74.06 KiB) Viewed 133 times
-
willemd
- Posts: 741
- Joined: Saturday 21 September 2019 17:55
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2024.1
- Location: The Netherlands
- Contact:
Re: Marstek OpenAPI
Yes, that was noticed by another user as well. The energy dashboard expects the sign to be different and as far as I know that is not configurable in the energy dashboard.
Marstek uses negative power numbers of charging and positive for discharging in the Open API.
But it can easily be adapted in the plugin. You have two options:
1) adapt the python line where the value for that device type is processed and add a multiplication by -1. But then it will apply to all devices and values of that device type.
2) in the device dictionary at the beginning of the plugin code, modify the multiplier of that device from 1 to -1. Then it can be configured per device.
I have uploaded a new version to github a minute ago that now handles the multiplier correctly also for kWh and counter devices (for those devices the previous version did not look at the multiplier, which was wrong of course). I have not yet changed the multiplier in the dictionary. It also corrects the pv1_power value that is reported incorrectly by the Open API. (release notes in the code)
Also note that there is another illogical thing in the dashboard in the sense that charging from the net to the battery is shown with a negative number, while usage from the net to the house is shown as a positive number, even though both flows are away from the net.
Marstek uses negative power numbers of charging and positive for discharging in the Open API.
But it can easily be adapted in the plugin. You have two options:
1) adapt the python line where the value for that device type is processed and add a multiplication by -1. But then it will apply to all devices and values of that device type.
2) in the device dictionary at the beginning of the plugin code, modify the multiplier of that device from 1 to -1. Then it can be configured per device.
I have uploaded a new version to github a minute ago that now handles the multiplier correctly also for kWh and counter devices (for those devices the previous version did not look at the multiplier, which was wrong of course). I have not yet changed the multiplier in the dictionary. It also corrects the pv1_power value that is reported incorrectly by the Open API. (release notes in the code)
Also note that there is another illogical thing in the dashboard in the sense that charging from the net to the battery is shown with a negative number, while usage from the net to the house is shown as a positive number, even though both flows are away from the net.
-
willemd
- Posts: 741
- Joined: Saturday 21 September 2019 17:55
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2024.1
- Location: The Netherlands
- Contact:
Re: Marstek OpenAPI
Following on from the above, you will get the most correct energy dashboard if:
1) you leave the plugin unchanged and use the sign as per Marstek conventions
2) set up a device that holds the sum of all solar production, either connected to the Marstek or not
3) set up a device that holds the nett power of the marstek battery/batteries (solar power minus ongrid and offgrid power)
4) a dzvents script to perform the calculations, my own example is shown below
1) you leave the plugin unchanged and use the sign as per Marstek conventions
2) set up a device that holds the sum of all solar production, either connected to the Marstek or not
3) set up a device that holds the nett power of the marstek battery/batteries (solar power minus ongrid and offgrid power)
4) a dzvents script to perform the calculations, my own example is shown below
Code: Select all
sumOfSolarIDX=370 -- output device holding the sum of all solar production for use in energy dashboard
solarHouseIDX=3 -- devices holding solar production, inputs to the sum of the total
solarMarstekPv1IDX=326
solarMarstekPv2IDX=330
-- add more if you have pv3 and/or pv4 connected
MarstekOnGridIDX=349
MarstekOffGidIDX=350
nettBatteryIDX=371
return {
on = {
devices = {
solarHouseIDX,
MarstekOnGridIDX,-- only one Marstek devcie needed since they are updated at the same time
}
},
logging = {
level = domoticz.LOG_DEBUG,
marker = 'solar sum',
},
execute = function(domoticz, device)
--domoticz.log('Device ' .. device.name .. ' was changed', domoticz.LOG_INFO)
sumOfSolarValue=domoticz.devices(solarHouseIDX).usage+domoticz.devices(solarMarstekPv1IDX).usage+domoticz.devices(solarMarstekPv2IDX).usage
domoticz.devices(sumOfSolarIDX).updateElectricity(sumOfSolarValue)
nettBatteryValue=domoticz.devices(solarMarstekPv1IDX).usage+domoticz.devices(solarMarstekPv2IDX).usage-domoticz.devices(MarstekOnGridIDX).usage-domoticz.devices(MarstekOffGidIDX).usage
domoticz.devices(nettBatteryIDX).updateElectricity(nettBatteryValue)
end
}Who is online
Users browsing this forum: No registered users and 1 guest