I'm trying to connect my DSMR reader data to the Victron by using MQTT.
Below is the initial question I asked to dbus-mqtt-devices:
I'm trying to create a small script which reads data from DSMR-reader send to a MQTT broker, and send it to the victron MQTT broker.
So far so good, and I've mapped out most of the values correctly. I've followed I've read: https://github.com/victronenergy/venus/wiki/dbus#grid-and-genset-meter to map all the data I have from DSMR to the corresponding Victron topics.
After running the script the entire day, I noticed my Victron values weren't updated when I was sending power back to the grid.
The snippet sending data to the topic in Victron is:
elif msg.topic == f"{DSMR_TOPIC}/reading/phase_currently_returned_l1":
wattage = float(msg.payload.decode("utf-8")) * 1000
publish_to_victron(f"W/{portal_id}/grid/{device_instance}/Ac/L1/Energy/Reverse", wattage)
This value is in Kw, so I multiply it by 1000 to get the W value, which I then publish to the Victron bus on Ac/L1/Energy/Reverse
topic. But this doesn't seem to do anything.
If I manually try to send the message on this topic, nothing happens.
The only way I can get the victron to display a negative number, is by sending data to the /Ac/L1/Energy/Forward
or /Ac/L1/Power
with a negative sign in front of it (e.g. -2).
My main questions:
- What is the correct way to use the Reverse topic?
- Should I calculate the negative number, and publish that to the
/Ac/L1/Energy/Forward
topic?
I'm sending it as Json, using separate function:
def publish_to_victron(topic, value):
payload = json.dumps({"value": value})
victron_client.publish(topic, payload)
print(f"Published to Victron: {topic} with payload {payload}")
For example a message published would be:Published to Victron: W/b827eba77875/grid/1/Ac/L1/Energy/Reverse with payload {"value": 0.0}
I see all values correctly on the bus, and it works for all my loads.
But for some reason as soon as I start delivering power back to the grid, it doesn't turn negative.
I hacked around a bit, and tried different stuff before actually moving to the grid sensor. But I'm by no means an expert in this.
Steps I took to make sure I have a basic understanding:
- Listened on the Victron bus for a while to see what's going on.
- Try to inject some payload to get an ID using MQTT Explorer (publishing to the device/name/Status topic)
- Start publishing some data on the needed topic to show data in the Victron
- After figuring it out by hand, start hacking away in Python
- Watching result, and be satisfied with the initial script
- See weird behaviour when returning solar.
- Hack around how to get value to display negative (sending a payload with a minus (-) sign in front)
- Question if this is the correct way to send payload, or I'm just making a rookie mistake.
Hopefully this clarifies it a bit, and how I got to this point.
And if I use `dbus-spy` I'm able to see the values on the reverse topic.
I've already done a lot of troubleshooting with the maintainer of dbus-mqtt-devices, but it looks like it's related to Victron. For reference: https://github.com/freakent/dbus-mqtt-devices/discussions/92#discussioncomment-8530877