MQTT and jsonpath transformation

thear all i’m trying to read the values of the following MQTT string using Jsonpath, I need the target_t value of 27 in the example, in thernostats section


{
  "device": {
    "type": "SHTRV-01",
    "mac": "60A423D7EB2A",
    "hostname": "shellytrv-60A423D7EB2A",
    "num_outputs": 0
  },
  "wifi_ap": {
    "enabled": false,
    "ssid": "shellytrv-60A423D7EB2A"
  },
  "wifi_sta": {
    "enabled": true,
    "ssid": "merola-Alice",
    "ipv4_method": "static",
    "ip": "192.168.0.221",
    "gw": "192.168.0.1",
    "mask": "255.255.254.0",
    "dns": "8.8.8.8"
  },
  "mqtt": {
    "enable": true,
    "server": "192.168.0.90:1883",
    "user": null,
    "id": "shellytrv-60A423D7EB2A",
    "clean_session": true,
    "max_qos": 0,
    "retain": false,
    "update_period": 60
  },
  "sntp": {
    "server": "time.google.com",
    "enabled": true
  },
  "login": {
    "enabled": false,
    "unprotected": false,
    "username": "xxxxx",
    "default_username": "xxxxxx"
  },
  "pin_code": "",
  "name": null,
  "fw": "20211223-144805/v2.1.0@d30148ec",
  "discoverable": true,
  "build_info": {
    "build_id": "20211223-144805/v2.1.0@d30148ec",
    "build_timestamp": "2021-12-23T14:48:05Z",
    "build_version": "2021122314"
  },
  "cloud": {
    "enabled": false
  },
  "coiot": {
    "enabled": false,
    "update_period": 3600,
    "peer": ""
  },
  "timezone": "Europe/Rome",
  "lat": 41.95967,
  "lng": 12.46035,
  "tzautodetect": true,
  "tz_utc_offset": 3600,
  "tz_dst": false,
  "tz_dst_auto": true,
  "time": "07:38",
  "child_lock": false,
  "display": {
    "brightness": 7,
    "flipped": false
  },
  "hwinfo": {
    "hw_revision": "dev-prototype",
    "batch_id": 0
  },
  "sleep_mode": {
    "period": 60,
    "unit": "m"
  },
  "thermostats": [
    {
      "target_t": {
        "enabled": true,
        "value": 27,
        "units": "C"
      },
      "schedule": false,
      "schedule_profile": 5,
      "schedule_profile_names": [
        "Livingroom",
        "Livingroom 1",
        "Bedroom",
        "Bedroom 1",
        "Holiday"
      ],
      "schedule_rules": [
        "0000-0123456-10"
      ],
      "temperature_offset": 0,
      "ext_t": {
        "enabled": false
      }
    }
  ]
}

in my things file I have the following line


Type number : temperatura_target  [ stateTopic="shellies/shellytrv-60A423D7EB2A/settings", transformationPattern="JSONPATH:$.thermostats.target_t.value", commandTopic="shellies/shellytrv-60A423D7EB2A/thermostat/0/command/target_t"]

in the items file i have the following line


Number Termovalvola_studio_target_t "Target T [%.1f °C]"    (gall)    {channel="mqtt:topic:mosquitto:shellytrv-60A423D7EB2A:temperatura_target"}

what is wrong?

I’m able to read all other values, for example mqtt server or wifi_sta ssid…

thanks in advance for your help.

Livio

Instead of the above in your transformation, use the following:

thermostats[0].target_t.value

The data inside thermostats seems to live within an array.

1 Like

thanks a lot…it works