[APP][Pro] MQTT Hub - Community version

I found a possible bug in MQTT Hub.

{
  "onoff": {
    "capability": "onoff",
    "stateTopic": "home/e04b4100adac0000000000007bac0000_m/status",
    "setTopic": "",
    "valueTemplate": "$.pir_detected",
    "outputTemplate": "",
    "displayName": "Motion"
  }
}

This will correctly reflect the state of motion sensor as a light switch and then if I replace

  "onoff": {
    "capability": "onoff",

with

  "alarm_motion": {
    "capability": "alarm_motion",

Then everything works correctly for a while. I did have it revert to not working once. I had it powered off, so I am not sure if that was causing the re-failure. I was able to make 2 sensors work using this process. How do I log this issue as I am new to Homey.

The MQTT Hub app settings offers a log. There you should find error messages if an error happens while converting a value (I think). And you should see the values read from MQTT Broker.

It shouldn’t male any difference whether you use onoff or alarm_motion capability. Both are boolean and are changed by a true/false value.

If you are using the value template "valueTemplate": "$.pir_detected",, then it’s using the number value (0 or 1) instead of true/false.
You can check if the connection is working if you set the calue in MqttExplorer to true/false instead of 0/1:

This way you can check if the JSON path is taken and the JSON value is used.

But at the end you will need a JS function to parse the JSON and then convert the number into a boolean value. I can check this the next days how a converter should be defined…

I checked the logs and saw no errors which confused me on why it was not working. The logs on the client and the Hub both indicated that I should be seeing something instead of absolutely nothing. That is what drove me to experiment with different device capabilities. I had tried every variation of conversion and nothing was giving a result before switching devices. It took switching the capabilities to get a result. I have been using the devices to correctly trigger flows after using the swapping method I described.

You can try with a custom MQTT topic. Create a topic “test”, set it to true/false in MqttExplorer. Then add a MQTT device using this test topic and check if this is read. Just to be sure the connection is ok.
If this is working, then it’s a issue with the JSON/value conversion.

I am not following your line of thinking. If

{
  "alarm_motion": {
    "capability": "alarm_motion",
    "stateTopic": "home/e04b4100adac0000000000007bac0000_m/status",
    "setTopic": "",
    "valueTemplate": "$.pir_detected",
    "outputTemplate": "",
    "displayName": "Motion"
  }
}

is now working correctly in a flow. How can value conversion be the issue?

Hmmm, I don’t get it to work though.
The field is interpeded as a number when I select it as a tag, and I can copy the value to a number variable. So it should be a number. Not sure how else to check it.
I also tried to add type: number to the capability, but it didn’t make a difference.
I tried just to test to add min and max properties, but these doesn’t seem to work either.
Unit works fine.

  "measure_monetary.import.0": {
    "capability": "measure_monetary",
    "stateTopic": "Pow-U/prices",
    "setTopic": "",
    "valueTemplate": "$.prices.0",
    "outputTemplate": "",
    "type": "number",
    "units": "kr",
    "decimals": "4",
    "title": "Price Now"
  }

I tested again…it seems there is a bug in Homey FW.

You can decrease the number of decimals like

"decimals": 0,

This is shown in the UI.
But it’s not possible to increase the number of decimals beyond the original capability settings.
I’ll ask Athom if that’s by design or a bug :slight_smile:

1 Like

Thank you for your help!
I see dropping the quotes around the number helps as I wasn’t able to reduse either when using the double quotes. Maybe that was the problem when I tested the max and min properties as well, as I used the quotes then too.
I recently got updated to the 12.3.0 stable fw, not sure if it behaved any differntly on previous 12.2.1 fw as I didn’t try this on that fw.

Afaik, with JSON formatting, putting numeric values between double qoutes, ‘formats’ numeric values as string values.
In that case, a Homey device setting which takes numeric values only, will not respond / error.

1 Like

Hi,
I have the MQTT Hub v4.3.10 installed on a Homey Pro 2023.
I am trying to add a MQTT Device with a simple switch on/off with state and set topic.
The closet i find is Closed (True | False) as a garagedor_closed

Is this switch on/off not available or am I just not able to find it?

BR Vegard

Hi, I had to check it myself :sweat_smile:
The app just shows the capability name defined by Athom.

In your case, the onoff capability is right. So “Turned on” is the right one.

{
  "type": "boolean",
  "title": {
    "en": "Turned on",
    "nl": "Aangezet",
    "de": "Eingeschaltet",
    "fr": "Activé",

Thanks for the hint. I’ll check if I can add the capability name in addition.

Thanks, it was exactly what I was looking for, Thanks @RonnyW

New test version 4.3.11

  • Changed capability selection in pair view. Added capability id.

Because there are so many capabilities now, it’s easier to find the right one by ID and not by title.

2 Likes

I’m facing the same challenge. Have you managed to get it working in the meantime?

The app offers all new capabilities in pair view.
What exactly is the problem?

This page wil probably help you if you are struggeling with finding the correct capability:
https://apps-sdk-v3.developer.homey.app/tutorial-device-capabilities.html

Hi

I’m facing the same problem as vasiya.

I setup my gPlugM which gives me the total power consumption of my house.
I’m able to brows the data in MQTT explorer. The value which i yould like to have on my virtual device from MQTT Hub. Ho do i get the Value Pi to be represented in the virtual device.

Topic: MaurerHome/gPlugM/SENSOR

{“Time”:“2025-02-20T21:00:12”,“z”:{“SMid”:“63536221”,“Pi”:1.942,“Po”:0.000,“Pi1”:0.000,“Pi2”:0.000,“Pi3”:0.000,“Po1”:0.000,“Po2”:0.000,“Po3”:0.000,“U1”:0.000,“U2”:0.000,“U3”:0.000,“I1”:0.491,“I2”:0.197,“I3”:0.231,“Ei”:16816.360,“Eo”:0.000,“Ei1”:8237.385,“Ei2”:8578.978,“Eo1”:0.000,“Eo2”:0.000,“Q5”:497.554,“Q6”:0.001,“Q7”:0.000,“Q8”:6033.209,“Q51”:252.571,“Q52”:244.983,“Q61”:0.000,“Q62”:0.001,“Q71”:0.000,“Q72”:0.000,“Q81”:2391.543,“Q82”:3641.666}}

Ho does the Topics section has to be configured?
{
“measure_power”: {
“capability”: “measure_power”,
“stateTopic”: “MaurerHome/gPlugM/SENSOR”,
“setTopic”: “”,
“valueTemplate”: “z.Pi”,
“outputTemplate”: “”,
“displayName”: “”
}
}

Try to change

"valueTemplate": "z.Pi",

into

"valueTemplate": "$.z[0].Pi.value",

Because the value of Pi is always a numeric value, quoting is not needed/undesired, so you’d format it like this:

"valueTemplate": $.z[0].Pi.value,

(quoting the value makes it a string/text value).

Make sure to use straight quotes " instead of the fancy ones you posted

1 Like

Hi Thanks for your answer.
With
“valueTemplate”: $.z[0].Pi.value,
I’ll get the following error on Saving
Invalid Value: class

If i return it sets the quotes themself.

I see the published data of my gplugM in the Hub Log, but I’m not able to setup a MQTT Device with MQTT Hub. Is the MQTT Client even necessary?
It looks for me like an issue with the MQTT Device from MQTT Hub but I’m not sure.

Does anyone have another input which i could try?
Thanks

Hi Philippe,

No problem!

Yes, MQTT hub uses it, to publish and receive messages.

Yes, my bad; I noticed it seems to be hardcoded somehow…

You’ll need to pick a matching class when you create the device; I picked “sensor”.
But you can change it afterwards as well:



Sooo, after lots of trial & error, I found a working solution.
You most probably need to use:

"valueTemplate": "$.z.Pi",

As example, and to compare, I used this MQTT message from topic ‘homey2/system/info’;
I used two values for my virtual MQTT device:



{
  "system": {
    "freememMachine": 112508928,
    "cpus": [
      {
        "model": "ARMv7 Processor rev 10 (v7l)",
        "speed": 996,
        "times": {
          "user": 1226178
        }
      },
      {
        "model": "ARMv7 Processor rev 10 (v7l)",
        "speed": 996,
        "times": {
          "user": 12277290
        }
      }
    ],
  },
}

Virtual MQTT device:

{
  "measure_data_size": {
    "capability": "measure_data_size",
    "stateTopic": "homey2/system/info",
    "setTopic": "",
    "valueTemplate": "$.system.freememMachine",
    "outputTemplate": "",
    "displayName": ""
  },
  "measure_data_rate": {
    "capability": "measure_data_rate",
    "stateTopic": "homey2/system/info",
    "setTopic": "",
    "valueTemplate": "$.system.cpus[0].times.user",
    "outputTemplate": "",
    "displayName": ""
  }
}