My Victron system is integrated with Home Assistant using MQTT. I have no issue reading any parameter from Victron by defining each variable as a sensor. However, I also want to write stuff back to Victron to change certain parameters (example: change the max allowed input amperage on the inverter). My thinking is to use the MQTT Number integration for that.
The issue is that Victron is sending and expecting to receive payload in JSON format. I can deal with the input configuration using a value template. But how do I send JSON to the proper command topic. Currently HA is just sending the variable to victron without formatting it as a JSON. The number integration doesn’t have an option to specify templating on the command topic. Any suggestions on how to handle this?
You can do the old way with an automation that uses a State Trigger listening to an input_number and publishing its value in the desired JSON format. Easy peasy.
How do I pass variables in an automation? I set it up so that I can an incoming MQTT message with the desired number as payload. Then, I want to construct an outgoing MQTT message, properly formatted to pass that number to Victron. How do I reference the incoming payload?
I was trying to do the same thing and ended up using command_template to set the payload. Seems a bit simpler, so I’m posting it here in case it helps anyone else: