MQTT JSON not appearing as an Input

Hi.

I have a shelly Pro 3EM 63A device, that i use to collect data about a waterheater. When i enable MQTT(set emon to be the prefix), i see the device pops up in “inputs”.

However, the device is pushing 2 elements under “status”, em:0 and emdata:0

I can select the emdata:0 values, eg; total_act and add it to feeds - it gets update, great all good. but all the data in emdata:0 is of a more historical aspect.

the data in em:0 is current live data.

The object is in the list: “status_em0” but everything in the object; (is not)

emon/shellypro3em63-6825ddd1cb9c/status/em:0{“id”:0,“a_current”:0.230,“a_voltage”:226.9,“a_act_power”:4.6,“a_aprt_power”:52.1,“a_pf”:0.09,“a_freq”:50.0,“b_current”:0.387,“b_voltage”:229.1,“b_act_power”:14.3,“b_aprt_power”:88.5,“b_pf”:0.16,“b_freq”:50.0,“c_current”:0.251,“c_voltage”:227.4,“c_act_power”:3.1,“c_aprt_power”:57.0,“c_pf”:0.06,“c_freq”:50.0,“n_current”:null,“total_current”:0.867,“total_act_power”:22.060,“total_aprt_power”:197.704, “user_calibrated_phase”:}

is not.

for reference emdata:0 looks like:

emon/shellypro3em63-6825ddd1cb9c/status/emdata:0{“id”:0,“a_total_act_energy”:82614.11,“a_total_act_ret_energy”:3.79,“b_total_act_energy”:90803.77,“b_total_act_ret_energy”:2.67,“c_total_act_energy”:76627.69,“c_total_act_ret_energy”:1.77,“total_act”:250045.57, “total_act_ret”:8.23}

Where would i have to see in the code, to understand why one is working, and the other is not?

Maybe there is something going on when the code has to read the data within em:0 ?

I am using version 11.7.4 (local)

In your pasted text, there is a random character at the end

image

Have you looked at the emoncms logs to see if there is a parse error?

Hi Borpin - i think the forum is doing magic with the input, it should be “” or \[\] - the field “user_calibrated_phase” refers to a user calibration, where a user can select phase A,B,C,N to do a calibration against.

Which log should i look in?

it did it again, [], [<no space>] - trying with preformattted text

Emoncms logs.

Try checking it against JSON Online Validator and Formatter - JSON Lint

[edit]
Not sure where you are getting the text to paste from, but (assuming a Windows machine) paste it into notebook (or a text editor) first, then copy and paste into the forum.

It does. You can fool it with backslashes - its escape character. HTML also naturally collapses multiple spaces and tabs into a single space, so on occasions you need to defeat both.
To tell you to use a single back-tick to `format text as a quote` so it appears as format text as a quote, I have to type \` each time.

Arh, thank you, from the log: (took another device along with it, just to validate my point)

2025-10-08 01:09:50.-320|INFO|emoncms_mqtt.php|MQTT Valid JSON found
2025-10-08 01:09:50.-320|INFO|emoncms_mqtt.php|No time element found in JSON - System time used
2025-10-08 01:09:50.-320|INFO|emoncms_mqtt.php|emon/shellyplus1-10061c79e0d0/status/temperature100 {"id": 100,"tC":25.8, "tF":78.3}
2025-10-08 01:09:53.059|INFO|emoncms_mqtt.php|emon/shellypro3em63-6825ddd1cb9c/status/em0 {"id":0,"a_current":0.226,"a_voltage":225.5,"a_act_power":4.4,"a_aprt_power":50.9,"a_pf":0.09,"a_freq":50.0,"b_current":0.383,"b_voltage":228.4,"b_act_power":13.9,"b_aprt_power":87.5,"b_pf":0.16,"b_freq":50.0,"c_current":0.249,"c_voltage":227.8,"c_act_power":3.3,"c_aprt_power":56.8,"c_pf":0.05,"c_freq":50.0,"n_current":null,"total_current":0.859,"total_act_power":21.544,"total_aprt_power":195.270, "user_calibrated_phase":[]}
2025-10-08 01:10:01.136|INFO|emoncms_mqtt.php|MQTT Valid JSON found
2025-10-08 01:10:01.136|INFO|emoncms_mqtt.php|No time element found in JSON - System time used
2025-10-08 01:10:01.136|INFO|emoncms_mqtt.php|emon/shellypro3em63-6825ddd1cb9c/status/emdata0 {"id":0,"a_total_act_energy":85300.06,"a_total_act_ret_energy":3.79,"b_total_act_energy":93716.95,"b_total_act_ret_energy":2.67,"c_total_act_energy":79071.95,"c_total_act_ret_energy":1.77,"total_act":258088.95, "total_act_ret":8.23}
2025-10-08 01:10:09.056|INFO|emoncms_mqtt.php|emon/shellypro3em63-6825ddd1cb9c/status/em0 {"id":0,"a_current":0.226,"a_voltage":225.5,"a_act_power":4.5,"a_aprt_power":51.0,"a_pf":0.09,"a_freq":50.0,"b_current":0.384,"b_voltage":228.3,"b_act_power":13.9,"b_aprt_power":87.6,"b_pf":0.16,"b_freq":50.0,"c_current":0.249,"c_voltage":227.8,"c_act_power":3.4,"c_aprt_power":56.8,"c_pf":0.06,"c_freq":50.0,"n_current":null,"total_current":0.859,"total_act_power":21.789,"total_aprt_power":195.367, "user_calibrated_phase":[]}


It appears, as its not recognized as a valid json input, but JSON lint, thinks it is. For some reason i am not able to calibrate the device, to see if the last element contained some data, it would recognize it as valid.

emoncms_mqtt.php seems to be the code running the analyze function, and based on some logging in the file, my guess is that $jsondata = json_decode($value,true,2) - is either NOT json_last_error() = JSON_ERROR_NONE or is_array($jsondata) is false.

i will debug this shortly.

thanks for pointing the direction.

arh, there in lies the “problem” - bumping 2 to 3, makes php print the array.

Is there a reason why the limitation has been set to 2 and not higher?

my test code:

<?php
$value = '{"id":0,"a_current":1.927,"a_voltage":226.7,"a_act_power":419.2,"a_aprt_power":436.7,"a_pf":0.96,"a_freq":50.0,"b_current":1.851,"b_voltage":228.2,"b_act_power":403.2,"b_aprt_power":422.2,"b_pf":0.95,"b_freq":50.0,"c_current":1.812,"c_voltage":229.1,"c_act_power":393.3,"c_aprt_power":415.4,"c_pf":0.95,"c_freq":50.0,"n_current":null,"total_current":5.591,"total_act_power":1215.761,"total_aprt_power":1274.326, "user_calibrated_phase":[]}';

//$value = '{"id": 102,"tC":27.2, "tF":80.9}';
$jsondata = json_decode($value, true, 3); // swap this with 2, and change the value
print(json_last_error());
print("\n");
print(is_array($jsondata));
print_r($jsondata);
?>

I’ve change this to:

json_decode($value,true,3)

and rebooted the system - now i can see the values properly in input under each device. but could there be a reason to why its set to 2?

The parameter you have changed is the depth the decoding goes to. Because you had a value as an empty array, that is why it failed.

You must be running an old version. This was fixed in 2022.

mqtt: support nested JSON values · emoncms/emoncms@c964857

note your local change will block and future updates.