Problem with Magnum inverter via mqtt sensor showing unavailable

I am using a Pi to collect data from my Magnum inverter and associated devices, and send it over to HA via MQTT. No problem there. Once example of the data as seen in MQTT explorer is;

topic magnum/inverter
{
“datetime”: “2024-01-30T14:19:58-06:00”,
“comm_device”: “/dev/ttyUSB0”,
“device”: “INVERTER”,
“data”: {
“revision”: “1.6”,
“mode”: 9,
“mode_text”: “BATSAVER”,
“fault”: 0,
“fault_text”: “None”,
“vdc”: 13.2,
“adc”: 0,
“VACout”: 118,
“VACin”: 117,
“invled”: 1,
“invled_text”: “On”,
“chgled”: 0,
“chgled_text”: “Off”,
“bat”: 18,
“tfmr”: 37,
“fet”: 36,
“model”: 44,
“model_text”: “MSH3012M”,
“stackmode”: 0,
“stackmode_text”: “Stand Alone”,
“AACin”: 12,
“AACout”: 0,
“Hz”: 60.3
}
}

Following an online example for other devices, i added the following to configuration.taml;

mqtt:
  sensor:
    - name: Magnum Inverter
      state_topic: "magnum/inverter"
      value_template: "{{value_jason.VACin}}"

The problem is that the entities show as unknown and there is no data.

Here is what I tried;
Adding retain: false

- name: Magnum Inverter
      state_topic: "magnum/inverter"
      value_template: "{{value_jason.VACin}}"
      retain: false

that just generates the error
ERROR (MainThread) [homeassistant.components.mqtt.mixins] extra keys not allowed @ data[‘retain’] for manually configured MQTT sensor item, in /config/configuration.yaml, line 19 Got {‘name’: ‘Magnum Inverter’, ‘state_topic’: ‘magnum/inverter’, ‘value_template’: ‘{{value_jason.VACin}}’, ‘retain’: False}

I verified that the script is using json format in the MQTT messages

I also tried a value|json something… can’t remember the actual syntax and can’t find the example again.

Any suggestions

value_jason

Should be

value_json

json is a data format, jason is a bloke who stole a valuable sheep carcass. :wink:

Oh Jeez. And I knew it was json… Thanks!!!

BTW, that’s funny!!!

1 Like

I corrected the issue and no longer get unknown. However, I don’t see the data in VACin, and I get errors in the log;

Template variable warning: ‘dict object’ has no attribute ‘VACin’ when rendering '{{value_json.VACin}}

and the same basic error and no data for all 4 devices.

Try this:

value_template: "{{value_json.data.VACin}}"

There’s a tool here you can use to find the path to your values:

Past your data over the instructions on the left and drill down to your required value on the right. The path will be at the top of the right hand side. Replace x with value_json.

Thanks. Adding the .data worked.

I had no luck with the link. It said there was an error parsing. Which is weird because I had pasted it into an online json validator and it said it was valid. But HA works now!!

Your data above is unformatted for the forum so it now has illegal “fancy” quotes in it.

Paste it directly from wherever you copied it from originally into the tool.

Or replace all of these: “ ” with these " ".

Ahhh, ok. That did it. Thanks!!

Hi, I have an older rv with a magnum me2012 inverter. And I just setup HA on a raz pi. Could you point me in the right direction to interface magnum with HA?

Sorry, I just saw this.

I have HA on a pi with MQTT mosquito broker. In the configuration.yaml, I have the above code with the corrections Tom helped me with.

I have another pi, a 2b, near my invertot/charger with a rs-485 interface; https://www.amazon.com/dp/B07H3PZNM9?psc=1&ref=ppx_yo2ov_dt_b_product_details

I tried a different one, couldn’t get any data from it though. I had to create a cossover cable by reversing one end of the phone cord, the tools are pretty cheap on amazon to put an end on. Just make sure whatever phone stuff you use is 4 wire as the magum doesn’t use the center pins like a phone does.

I also used Amazon.com because I was putting the splitter on my BMK and couldn’t fit an all in one type plug splitter. If you don’t have any other devises, you won’t need the splitter, just plug into the network port on your inverter

I also added a wifi stick. I tried another, but the pi wouldn’t recognize it, so I got this one, https://www.amazon.com/dp/B01GC8XH0S?psc=1&ref=ppx_yo2ov_dt_b_product_details

Then installed pythom then pymagnum from here GitHub - CharlesGodwin/pymagnum: A read only interface for Magnum Energy Network devices

Once I got magtest to show data, I added this line to /etc/rc.local; "sudo /usr/bin/mqttlogger.py -b 192.168.3.5 -i 30 --username homeassistant --password ****** & "

This page got me started. Reading Magnum Energy RS485 infromation

The whole configuration .yaml entries are;

mqtt:
  sensor:
    - name: Magnum Inverter
      state_topic: "magnum/inverter"
      value_template: "{{value_json.data.VACin}}"
      #friendly_name: inverter volts in
      unit_of_measurement: V
      icon: mdi:sine-wave
      
    - name: Magnum Inverter
      state_topic: "magnum/inverter"
      value_template: "{{value_json.data.mode_text}}"
      #friendly_name: Inverter mode
      
    - name: Magnum Inverter
      state_topic: "magnum/inverter"
      value_template: "{{value_json.data.fault_text}}"
      #friendly_name: Inverter faults
      
    - name: Magnum Inverter
      state_topic: "magnum/inverter"
      value_template: "{{value_json.data.vdc}}"
      #friendly_name: Inverter Battery Voltage
      unit_of_measurement: V
      
    - name: Magnum Inverter
      state_topic: "magnum/inverter"
      value_template: "{{value_json.data.VACout}}"
      #friendly_name: Inverter voltage out
      unit_of_measurement: V
      
    - name: Magnum Inverter
      state_topic: "magnum/inverter"
      value_template: "{{value_json.data.AACin}}"
      #friendly_name: Inverter amps in
      unit_of_measurement: A
      
    - name: Magnum Inverter
      state_topic: "magnum/inverter"
      value_template: "{{value_json.data.AACout}}"
      #friendly_name: inveter amps out
      unit_of_measurement: A
      
      
    
    - name: Magnum PT100
      state_topic: "magnum/pt100"
      value_template: "{{value_json.data.mode_text}}"
      
    - name: Magnum PT100
      state_topic: "magnum/pt100"
      value_template: "{{value_json.data.battery_amps}}"
      unit_of_measurement: A
      icon: mdi:flash
      
    - name: Magnum PT100
      state_topic: "magnum/pt100"
      value_template: "{{value_json.data.pv_voltage}}"
      unit_of_measurement: V
      icon: mdi:sine-wave
      
     
      
      
      
    
    - name: Magnum BMK
      state_topic: "magnum/bmk"
      value_template: "{{value_json.data.vdc}}"
      unit_of_measurement: V
      icon: mdi:sine-wave
      
    - name: Magnum BMK
      state_topic: "magnum/bmk"
      value_template: "{{value_json.data.adc}}"
      unit_of_measurement: A
      icon: mdi:flash
      
    - name: Magnum BMK
      state_topic: "magnum/bmk"
      value_template: "{{value_json.data.vmin}}"
      unit_of_measurement: V
      icon: mdi:sine-wave
      
    - name: Magnum BMK
      state_topic: "magnum/bmk"
      value_template: "{{value_json.data.vmax}}"
      unit_of_measurement: V
      icon: mdi:sine-wave
      
    - name: Magnum BMK
      state_topic: "magnum/bmk"
      value_template: "{{value_json.data.Fault_Text}}"
      
    - name: Magnum BMK
      state_topic: "magnum/bmk"
      value_template: "{{value_json.data.soc}}"
      #unit_of_measurement: V
      device_class: BATTERY
      icon: mdi:battery
      
      
    
    - name: Magnum Remote
      state_topic: "magnum/remote"
      value_template: "{{value_json.data.ainput}}"

Just delete the things you don’t have/want.

1 Like

Also be aware, no devices show up in HA, only entities.

1 Like

This is great info, thank you for sharing!!

No Problem!