# \[APP\]\[Pro\] MQTT Hub - Community version

**URL:** <https://community.homey.app/t/app-pro-mqtt-hub-community-version/113463>\
**Category:** Apps\
**Tags:** app, mqtt, homey-pro\
**Created:** [July 26, 2024, 3:58pm UTC](https://community.homey.app/t/app-pro-mqtt-hub-community-version/113463 "2024-07-26T15:58:53Z")\
**Posts on this page:** 20\
**Page:** 13

<div class="post-metadata">

**Author:** ![RonnyW](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/ronnyw/32/10879_2.png) [@RonnyW](https://community.homey.app/u/RonnyW)\
**Post date:** [August 24, 2025, 6:36pm UTC](https://community.homey.app/t/app-pro-mqtt-hub-community-version/113463/252 "2025-08-24T18:36:48Z")

</div>

Well, it depends 😄

It’s like HA entities. You can perhaps have a Mqtt device that has ‘min’, ‘medium’, ‘max’ or 0..100%.

You can chabge your fan and check the topic in MqttExplorer.

Then you can add an export template as JavaScript to map the values. Just ask if you have some example values and need help.

---

<div class="post-metadata">

**Author:** ![OH2TH](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/oh2th/32/111414_2.png) [@OH2TH](https://community.homey.app/u/OH2TH)\
**Post date:** [October 7, 2025, 5:18am UTC](https://community.homey.app/t/app-pro-mqtt-hub-community-version/113463/253 "2025-10-07T05:18:19Z")

</div>

I have a MQTT topic that returns a JSON:

```auto
{
  "state": {
    "reported": {
      "ts": 1759810164000,
      "239": 1,
      "240": 1,
      "80": 5,
      "21": 4,
      "200": 0,
      "69": 1,
      "383": 3,
      "30": 0,
      "31": 0,
      "32": 71,
      "37": 76,
      "50": 101,
      "53": 11,
      "181": 9,
      "182": 6,
      "66": 14750,
      "24": 75,
      "206": 4210,
      "67": 3944,
      "68": 0,
      "17": 2,
      "18": -60,
      "19": 39,
      "15": 1000,
      "36": 1462,
      "42": 834,
      "43": 0,
      "49": 53266,
      "51": 14640,
      "241": 24491,
      "199": 9006,
      "16": 7859331,
      "449": 0,
      "636": 36734486,
      "389": 352056,
      "390": 442,
    }
  }
}

```

I can read paramter “390” and get the raw 442 value which is Fuel remaining, but it needs to be divided by 10 to get it into 44.2 liters.

This is the configuration for the capability

```auto
  "measure_content_volume": {
    "capability": "measure_content_volume",
    "stateTopic": "car/data",
    "setTopic": "",
    "valueTemplate": " (value) => { return value.state.reported[\"390\"]/10) }",
    "outputTemplate": "",
    "displayName": "Fuel remaining"
  }

```

$.state.reported["390"]" returns the raw value fine, but doing MathJS on that directly fails and returns always 0.

Then I tried  
`(value) => { return (JSON.parse(value).state.reported[\"390\"] / 10 ) }`  
but that also always returns 0

and now I tried also  
`(value) => { return value.state.reported[\"390\"]/10) }`  
and that too returns 0.

What should be the proper way to do the math on the value?

---

<div class="post-metadata">

**Author:** ![RonnyW](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/ronnyw/32/10879_2.png) [@RonnyW](https://community.homey.app/u/RonnyW)\
**Post date:** [October 7, 2025, 6:12am UTC](https://community.homey.app/t/app-pro-mqtt-hub-community-version/113463/254 "2025-10-07T06:12:19Z")

</div>

Please try single quotes ‘ instead of \”. The string is used as function without without unescaping.

I think this should work:

```auto
(value) => { return value.state.reported['390']/10 }

```

---

<div class="post-metadata">

**Author:** ![Tjar](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/tjar/32/61177_2.png) [@Tjar](https://community.homey.app/u/Tjar)\
**Post date:** [October 7, 2025, 7:01am UTC](https://community.homey.app/t/app-pro-mqtt-hub-community-version/113463/255 "2025-10-07T07:01:23Z")

</div>

Hi All,

I’m having some difficulties with the MQTT Hub app in thermostat mode.

 ![image](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/c/4/c44513c1017f9a31f5fb001a26a32d4858d1dab7.png)

```auto
{
  "measure_temperature": {
    "capability": "measure_temperature",
    "stateTopic": "thermostat1/status/number:201",
    "setTopic": "",
    "valueTemplate": "$.value",
    "outputTemplate": "",
    "displayName": "temperature"
  },
"target_temperature": {
    "capability": "target_temperature",
    "stateTopic": "thermostat1/status/number:202",
    "setTopic": "thermostat1/rpc",
    "valueTemplate": "$.value",
    "outputTemplate": "21.2", 
    "displayName": "temperature"
  },
  "measure_humidity": {
    "capability": "measure_humidity",
    "stateTopic": "thermostat1/status/number:200",
    "setTopic": "",
    "valueTemplate": "$.value",
    "outputTemplate": "",
    "displayName": "Humidity"
  },
  "onoff": {
    "capability": "onoff",
    "stateTopic": "thermostat1/status/boolean:202",
    "setTopic": "",
    "valueTemplate": "$.value",
    "outputTemplate": "",
    "displayName": ""
  }

}

```

Is this a bug in the Hub app? Or do I do something wrong here?

---

<div class="post-metadata">

**Author:** ![OH2TH](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/oh2th/32/111414_2.png) [@OH2TH](https://community.homey.app/u/OH2TH)\
**Post date:** [October 7, 2025, 7:42am UTC](https://community.homey.app/t/app-pro-mqtt-hub-community-version/113463/256 "2025-10-07T07:42:29Z")

</div>

Thanks, will test that next time that car moves.

Second question, for:

```auto
  "measure_number.2": {
    "capability": "measure_number",
    "stateTopic": "ajovalo/fmc003/864275078490771/data",
    "setTopic": "",
    "valueTemplate": "$.state.reported['389']",
    "outputTemplate": "",
    "displayName": "Odometer km",
    "units": "km"
  },

```

I’m trying to display the last known value for Odometer, when the attribute is missing from the JSON. Is there a way to retain the last good value instead of reseting to 0?

---

<div class="post-metadata">

**Author:** ![RonnyW](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/ronnyw/32/10879_2.png) [@RonnyW](https://community.homey.app/u/RonnyW)\
**Post date:** [October 7, 2025, 10:10am UTC](https://community.homey.app/t/app-pro-mqtt-hub-community-version/113463/257 "2025-10-07T10:10:21Z")

</div>

> [@OH2TH](#):
>
> when the attribute is missing from the JSON.

The Json changes (other fields), but sometimes, the Odo is empty/missing?

I would try the JS function template. Read the field and return it. If the field is empty/missing, throw an error. That should prevent an update in this case.

It’s just a guess, but should work I think 😄

---

<div class="post-metadata">

**Author:** ![OH2TH](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/oh2th/32/111414_2.png) [@OH2TH](https://community.homey.app/u/OH2TH)\
**Post date:** [October 7, 2025, 11:49am UTC](https://community.homey.app/t/app-pro-mqtt-hub-community-version/113463/258 "2025-10-07T11:49:11Z")

</div>

Throwing and error seems to result in null value and the capability value is set to null. So when null value is received, maybe have an option in the capability config to either allow null value, or keep last known good value.

---

<div class="post-metadata">

**Author:** ![RonnyW](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/ronnyw/32/10879_2.png) [@RonnyW](https://community.homey.app/u/RonnyW)\
**Post date:** [October 7, 2025, 3:56pm UTC](https://community.homey.app/t/app-pro-mqtt-hub-community-version/113463/259 "2025-10-07T15:56:55Z")

</div>

> [@Tjar](#):
>
> I’m having some difficulties with the MQTT Hub app in thermostat mode.

It seems the device registers capability listeners only at start up, not after settings changes.  
An app restart should fix the issue for you. I will check if I can add a this for settings, too.

---

<div class="post-metadata">

**Author:** ![RonnyW](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/ronnyw/32/10879_2.png) [@RonnyW](https://community.homey.app/u/RonnyW)\
**Post date:** [October 7, 2025, 5:36pm UTC](https://community.homey.app/t/app-pro-mqtt-hub-community-version/113463/260 "2025-10-07T17:36:10Z")

</div>

New **test version 4.5.2** :

- Fixed capability registration after settings changed. Capability listener should be added now (untested)
- Exception in JS template skips value.

@OH2TH I changed the logic a bit. An exception in a JS function skips the capability update now.

---

<div class="post-metadata">

**Author:** ![Tjar](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/tjar/32/61177_2.png) [@Tjar](https://community.homey.app/u/Tjar)\
**Post date:** [October 7, 2025, 6:38pm UTC](https://community.homey.app/t/app-pro-mqtt-hub-community-version/113463/261 "2025-10-07T18:38:16Z")

</div>

Hi RonnyW,

great the APP reset was already sufficient 🙂

I would like to send this payload:

```auto
 {"method":"number.set","params":{"value": 20.2, "id":202, "source":"homey"}
 

```

With the thermostat target as value (20.2). How should I handle this? Is that like?

```auto
"outputTemplate"=‘{"method":"number.set","params":{"value": value, "id":202, "source":"homey"}’

```

Best regards

---

<div class="post-metadata">

**Author:** ![Tjar](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/tjar/32/61177_2.png) [@Tjar](https://community.homey.app/u/Tjar)\
**Post date:** [October 7, 2025, 6:53pm UTC](https://community.homey.app/t/app-pro-mqtt-hub-community-version/113463/262 "2025-10-07T18:53:04Z")

</div>

I got it to work with:

```auto
{
  "measure_temperature": {
    "capability": "measure_temperature",
    "stateTopic": "thermostat1/status/number:201",
    "setTopic": "",
    "valueTemplate": "$.value",
    "outputTemplate": "",
    "displayName": "temperature"
  },
"target_temperature": {
    "capability": "target_temperature",
    "stateTopic": "thermostat1/status/number:202",
    "setTopic": "thermostat1/rpc",
    "valueTemplate": "$.value",
    "outputTemplate": "{\"method\":\"number.set\", \"params\":{\"id\":202, \"value\":value} }", 
    "displayName": "temperature"
  },
  "measure_humidity": {
    "capability": "measure_humidity",
    "stateTopic": "thermostat1/status/number:200",
    "setTopic": "",
    "valueTemplate": "$.value",
    "outputTemplate": "",
    "displayName": "Humidity"
  },
  "onoff": {
    "capability": "onoff",
    "stateTopic": "thermostat1/status/boolean:202",
    "setTopic": "",
    "valueTemplate": "$.value",
    "outputTemplate": "",
    "displayName": ""
  }

}

```

---

<div class="post-metadata">

**Author:** ![RonnyW](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/ronnyw/32/10879_2.png) [@RonnyW](https://community.homey.app/u/RonnyW)\
**Post date:** [October 7, 2025, 7:08pm UTC](https://community.homey.app/t/app-pro-mqtt-hub-community-version/113463/263 "2025-10-07T19:08:59Z")

</div>

Thanks fot the update. Haven’t used this myself yet 😄

---

<div class="post-metadata">

**Author:** ![Tjar](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/tjar/32/61177_2.png) [@Tjar](https://community.homey.app/u/Tjar)\
**Post date:** [October 7, 2025, 7:30pm UTC](https://community.homey.app/t/app-pro-mqtt-hub-community-version/113463/264 "2025-10-07T19:30:07Z")

</div>

Is there a way receiving a boolean and convert to a (capability) state?

(value) =\> { return (value.output == false)?”heat”:"cool” }

---

<div class="post-metadata">

**Author:** ![RonnyW](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/ronnyw/32/10879_2.png) [@RonnyW](https://community.homey.app/u/RonnyW)\
**Post date:** [October 7, 2025, 8:05pm UTC](https://community.homey.app/t/app-pro-mqtt-hub-community-version/113463/265 "2025-10-07T20:05:56Z")

</div>

Hehe, youd should create a Wiki post with examples 😃

---

<div class="post-metadata">

**Author:** ![OH2TH](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/oh2th/32/111414_2.png) [@OH2TH](https://community.homey.app/u/OH2TH)\
**Post date:** [October 8, 2025, 4:04am UTC](https://community.homey.app/t/app-pro-mqtt-hub-community-version/113463/266 "2025-10-08T04:04:20Z")

</div>

Thanks will try that, so something like this should work?

```auto
"valueTemplate": "(value) => { if (value.state.reported['389'] === undefined) throw Error(); return value.state.reported['389'] }",

```

Could be useful for `$.state.reported['256']` JSONpath also.

---

<div class="post-metadata">

**Author:** ![OH2TH](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/oh2th/32/111414_2.png) [@OH2TH](https://community.homey.app/u/OH2TH)\
**Post date:** [October 8, 2025, 4:11am UTC](https://community.homey.app/t/app-pro-mqtt-hub-community-version/113463/267 "2025-10-08T04:11:16Z")

</div>

in the JS template, is it possible to use Date() ?

```auto
(value) => new Date(value.state.reported['ts']).toLocaleString('sv-SE', { timeZone: 'Europe/Helsinki' })

```

Would be nice if I could convert timestamps to human readable.

---

<div class="post-metadata">

**Author:** ![OH2TH](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/oh2th/32/111414_2.png) [@OH2TH](https://community.homey.app/u/OH2TH)\
**Post date:** [October 8, 2025, 4:38am UTC](https://community.homey.app/t/app-pro-mqtt-hub-community-version/113463/268 "2025-10-08T04:38:23Z")

</div>

> [@\[Wiki\] MQTT Hub - Using templates](https://community.homey.app/t/wiki-mqtt-hub-using-templates/143892):
>
> This topic is for demonstrating different ways of using value templates with the [[APP][Pro] MQTT Hub - Community version](https://community.homey.app/t/113463). Templates can be used for valueTemplate - parsing the incoming meassage from a topic outputTemplate - preparing the message to be sent to a topic. valueTemplate Value When the topic returns a direct value, you can leave the value template empty. Simple math can be used on these values. Could be used to change the multiplication factor for different units. value / 10 va…

---

<div class="post-metadata">

**Author:** ![RonnyW](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/ronnyw/32/10879_2.png) [@RonnyW](https://community.homey.app/u/RonnyW)\
**Post date:** [October 8, 2025, 7:48am UTC](https://community.homey.app/t/app-pro-mqtt-hub-community-version/113463/269 "2025-10-08T07:48:31Z")

</div>

The JS function is executed in app context. You can use everything that’s also possible in apps (all existing Homey NodeJS modules).

---

<div class="post-metadata">

**Author:** ![OH2TH](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/oh2th/32/111414_2.png) [@OH2TH](https://community.homey.app/u/OH2TH)\
**Post date:** [October 8, 2025, 10:35am UTC](https://community.homey.app/t/app-pro-mqtt-hub-community-version/113463/270 "2025-10-08T10:35:53Z")

</div>

And Date does work correctly, my capability was number and not string.

---

<div class="post-metadata">

**Author:** ![RonnyW](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/ronnyw/32/10879_2.png) [@RonnyW](https://community.homey.app/u/RonnyW)\
**Post date:** [October 8, 2025, 6:14pm UTC](https://community.homey.app/t/app-pro-mqtt-hub-community-version/113463/271 "2025-10-08T18:14:45Z")

</div>

New **test version 4.5.3** :

- Undefined result of JSON path, MathJS or JS function skips value. Capability keeps unchanged in this case.

[Previous page](https://community.homey.app/t/app-pro-mqtt-hub-community-version/113463.md?page=12)

[Next page](https://community.homey.app/t/app-pro-mqtt-hub-community-version/113463.md?page=14)
