ESP Easy MQTT ARRAYs

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
oarchie
New user
Posts: 4
Joined: 15 Aug 2017, 03:16

ESP Easy MQTT ARRAYs

#1 Post by oarchie » 19 Aug 2017, 18:00

I am trying to connect ESP Easy to HomeAssistant.
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 }}'
The received mqtt encoded data looks like:

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"}
but HA will not read the DHT001 svalues.
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}
If I change the JSON encoding (in _C012.ino for test) to look like:

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?

User avatar
grovkillen
Core team member
Posts: 3621
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: ESP Easy MQTT ARRAYs

#2 Post by grovkillen » 19 Aug 2017, 18:55

If you want to create custom MQTT messages:

https://www.letscontrolit.com/wiki/inde ... th_own_IDX

But I would not use the Domoticz settings if I don't connect to a Domoticz controller.
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you :idea: :idea: :idea:

oarchie
New user
Posts: 4
Joined: 15 Aug 2017, 03:16

Re: ESP Easy MQTT ARRAYs

#3 Post by oarchie » 20 Aug 2017, 03:20

Yes, I saw that method.
I was hoping to use the device config for setting up a lot of different WiFi based sensors.
I have implemented _C012.ino as HomeAssistant MQTT control plugin, using the mega branch, and PIO, upload, test, 1024
I can now select that from the Controllers Protocol.
Image
My question is really about the MQTT protocol and JSON, which I have used before.
From bblanchon (https://bblanchon.github.io/ArduinoJson/doc/encoding/) :
svalue":[16.40,32.50,0] defines an array of three elements svalue[0],[1],[2]
What does"svalue":"15.90;32.70;0" mean and how do you access it?

I am happy just to use the modified _C012.ino, which works.
From reading the docs, I thought that defining a DHT22 sensor, and MQTT protocol would generate a JSON string defining RoomT and RoomH as per the attached.
I would rather find out if I am missing something with respect to the current code base.
Cheers
Archie
Attachments
Screen Shot 2017-08-20 at 11.17.54.png
Screen Shot 2017-08-20 at 11.17.54.png (73.86 KiB) Viewed 3575 times
Screen Shot 2017-08-20 at 11.06.09.png
Screen Shot 2017-08-20 at 11.06.09.png (59.17 KiB) Viewed 3575 times

Post Reply

Who is online

Users browsing this forum: No registered users and 19 guests