The MQTT string that I get from the ESP Easy with a DHT22 configured device.
I have enabled Controller 1 as domoticz mqtt.
My question relates to the mqtt protocol format.
I am successfully receiving mqtt messages.
My configuration.yaml looks like:
Code: Select all
- platform: mqtt
state_topic: "/home/ESPSensor/DHT001"
name: "RoomT"
unit_of_measurement: "°C"
value_template: '{{ value_json.svalue[0] }}'
- platform: mqtt
state_topic: "/home/ESPSensor/DHT001"
name: "RoomH"
unit_of_measurement: "%"
value_template: '{{ value_json.svalue[1] }}'
- platform: mqtt
state_topic: "/home/ESPSensor/WaterTemp"
name: "WaterT"
unit_of_measurement: "°C"
value_template: '{{ value_json.svalue }}'
Code: Select all
/home/ESPSensor/DHT001 {"idx":22,"nvalue":0,"svalue":"15.90;32.70;0"}
/home/ESPSensor/WaterTemp {"idx":18,"nvalue":0,"svalue":"16.19"}
It is OK with the WaterTemp svalue.
In order for the svalue to be encoded using JSON array notation - (svalue[0]) - shouldn't the mqtt JSON values look like this:
Code: Select all
/home/ESPSensor/DHT001 {"svalue":[16.40,32.50,0],"idx":22,"nvalue":0}
/home/ESPSensor/WaterTemp {"svalue":"15.44","idx":18,"nvalue":0}
Code: Select all
JsonObject& root = jsonBuffer.createObject();
JsonArray& svalue = root.createNestedArray("svalue");
...
case SENSOR_TYPE_TEMP_HUM: // temp + hum + hum_stat, used for DHT11
root[F("nvalue")] = 0;
svalue.add(UserVar[event->BaseVarIndex], ExtraTaskSettings.TaskDeviceValueDecimals[0]);
svalue.add(UserVar[event->BaseVarIndex + 1], ExtraTaskSettings.TaskDeviceValueDecimals[1]);
svalue.add(0);
// values = toString(UserVar[event->BaseVarIndex], ExtraTaskSettings.TaskDeviceValueDecimals[0]);
// values += ";";
// values += toString(UserVar[event->BaseVarIndex + 1], ExtraTaskSettings.TaskDeviceValueDecimals[1]);
// values += ";0";
// values.toCharArray(str, 80);
// root[F("svalue")] = values.c_str();
// root[F("svalue")] = str;
home assistant works and the values are captured.
Can you help me with this?