MQTT Hub/Gateway

Yes i found that setting but it didn’t have any effect, I can see the values shifting in MQTT explorer, but the device doesn’t update. I thought it had more impact on device output rather than input.

If this is supposed to work I’ll do some further testing this afternoon.

This is interesting, tested with just setting “value” in the template field, and suddenly the device started to register events on ON/OFF.

{
“alarm_motion”: {
“capability”: “alarm_motion”,
“stateTopic”: “ring/00e64a46-0000-4491-92ca-1c290525cb3d/alarm/00e00e0b-06bb-404b-ae80-e57c900ca6ae/motion/state”,
“setTopic”: “”,
“valueTemplate”: “value”,
“outputTemplate”: “”,
“displayName”: “Motion alarm”
}
}

And then I removed “value”, it still works. It seems like there’s been some hiccup that have ben solved by just pushing the values again.

Any ideas why my displayNames are not used?

{
    "measure_power": {
        "capability": "measure_power",
        "stateTopic": "ams/meter/import/active",
        "setTopic": "",
        "valueTemplate": "",
        "outputTemplate": "",
        "displayName": "Power"
    },
    "measure_current.l1": {
        "capability": "measure_current",
        "stateTopic": "ams/meter/l1/current",
        "setTopic": "",
        "valueTemplate": "",
        "outputTemplate": "",
        "displayName": "Current l1"
    },
    "measure_current.l2": {
        "capability": "measure_current",
        "stateTopic": "ams/meter/l2/current",
        "setTopic": "",
        "valueTemplate": "",
        "outputTemplate": "",
        "displayName": "Current l2"
    },
    "measure_current.l3": {
        "capability": "measure_current",
        "stateTopic": "ams/meter/l3/current",
        "setTopic": "",
        "valueTemplate": "",
        "outputTemplate": "",
        "displayName": "Current l3"
    },
    "measure_voltage.l1": {
        "capability": "measure_voltage",
        "stateTopic": "ams/meter/l1/voltage",
        "setTopic": "",
        "valueTemplate": "",
        "outputTemplate": "",
        "displayName": "Voltage l1"
    },
    "measure_voltage.l2": {
        "capability": "measure_voltage",
        "stateTopic": "ams/meter/l2/voltage",
        "setTopic": "",
        "valueTemplate": "",
        "outputTemplate": "",
        "displayName": "Voltage l2"
    },
    "measure_voltage.l3": {
        "capability": "measure_voltage",
        "stateTopic": "ams/meter/l3/voltage",
        "setTopic": "",
        "valueTemplate": "",
        "outputTemplate": "",
        "displayName": "Voltage l3"
    },
    "meter_power.acc": {
        "capability": "meter_power",
        "stateTopic": "ams/meter/import/active/accumulated",
        "setTopic": "",
        "valueTemplate": "",
        "outputTemplate": "",
        "displayName": "Energy"
    },
    "meter_power.hour": {
        "capability": "meter_power",
        "stateTopic": "ams/realtime/import/hour",
        "setTopic": "",
        "valueTemplate": "",
        "outputTemplate": "",
        "displayName": "Energy this hour"
    },
    "meter_power.day": {
        "capability": "meter_power",
        "stateTopic": "ams/realtime/import/day",
        "setTopic": "",
        "valueTemplate": "",
        "outputTemplate": "",
        "displayName": "Energy this day"
    }
}

All the capabilities uses the default name. So I have three Current, three Voltage and three Energy (in Norwegian). No way of knowing which is which when creating flows.

With one capability it is OK. Did you try what the result is with a one capability device?

{
  "measure_voltage": {
    "capability": "measure_voltage",
    "stateTopic": "",
    "commandTopic": "",
    "valueTemplate": "",
    "outputTemplate": "",
    "displayName": "Special Display Name Voltage"
  }
}

Screenshot from 2022-07-18 02-29-11

Hi all,

When I disable a device, it won’t dissapear from HA. Is that by design or is it a setting I can change?

Disabled in Mqtt Hub settings? In that case no updates will be pushed to Mqtt. But the HA device will stay. If you don’t neednit anymore, you can delete it in HA (settings/devices, search by name and delete).
If it’s activated in Homey again, state changes will be pushed again and the device will be created again in HA.

Thanks Ronny, that’s indeed how it works now.
As I am fiddling often with (temporary) new devices, I am also busy by removing them from HA afterwards :blush:
For me, a disabled device almost never gets enabled again, so it would be nice to have an “Auto add new devices” switch to prevent everything from popping up in HA when you are experimenting :upside_down_face:

If you add a new device in Homey, restart the Hub and it will update the HA devices (new device is created in HA).
A problem is: when you replace a Homey device (remove and add with same name), you will have 2 devices in HA. So I delete the old device in HA, replace in Homey and restart teh Hub to sync again. This way you don’t need to update the HA-Dashboard.

2 Likes

Hi, is it possible to publish the on/off values like ON/OFF with capital letters? by default it seems the payload is sent in lower case. My devices need capital letters in the payload to accept the message.

I have searched the forums without finding anything around this and been trying different things with the outputTemplate and the other settings but not been able to get it work. Is it possible to use string functions like “value.toUpperCase()” in the outputTemplate?

Any pointers on how to achieve this is highly welcome, thanks!

When Homey restarts, my MQTT Hub does seem to not start properly. This leads to the MQTT Hub not functioning, and my broker not receiving any messages.

I really need to manually restart the app, and then force another broadcast for things to return to normal, which requires my presence and is generally annoying.

I have now automated this flow (advanced flow).

  • once the Homey has restarted an event is emitted
  • when this event is emitted by Homey, most of the apps have not been started yet
  • I use simplelog to log things in my log and on the timeline, but at this point in time, the SImpleLog app has not been started yet. Instead I write a notification to the timeline. This will work as it is native supported functionality that is available when the homey-started event is emitted.

After that, the flow waits a considerable amount of time before doing the real work, since it can take quite some time before all apps are started after a reboot:

  • wait 20 minutes - this might be shorter, but I prefer to be safer than sorrier
  • restart the MQTT Hub
  • trigger a broadcast 2 minutes after the restart of the MQTT Hub

Whenever Homey restarts willingly or unwillingly, this ensures that my MQTT statuses are properly working - even when I’m not at home when a restart occurs spontaneously.

Please see this screenshot:

1 Like

I thought that restart of MQTT hub app automatically triggers broadcast - that’s my observation.

I had same flow in the past too, however now it’s disabled as it’s not needed. Still restarting regularly during night as suggested in this forum.

I have noticed the auto broadcast feature to be working most of the time. I have found a few occasions in the past few months where the app would not broadcast.
If it works for you without the forced broadcast then I’m still happy :wink:

Thats odd, my Homey only restarts after an update, and I never restart the MQTT Hub app.
It seems to be a local issue?


This is a Homey zigbee temperature sensor

Could be. One of my apps could have a memory leak. I have never investigated…

Hi all,

I do not know how to get the MQTT Hub app to send MQTT messages in JSON format and convert values. Perhaps one of you is willing to help me out. The idea is to link Homey to a device controlled in Home Assistant.

I have created a MQTT device of type light. MQTT topics are:
ha_test/light/kleedkamer_lamp/state for state
ha_test/light/kleedkamer_lamp/set_light for commands

Payload for on/off should be:
{ “state”: “OFF”} and { “state”: “ON”}

Payload for dim level should be in a 0-249 scale:
{ “brightness”: “249”}

After a lot of trial and error, the settings are as follows. Obviously, it does not work because it is not in proper JSON format:

{
  "onoff": {
    "capability": "onoff",
    "stateTopic": "ha_test/light/kleedkamer_lamp/state",
    "setTopic": "ha_test/light/kleedkamer_lamp/set_light",
    "valueTemplate":  "$.state",
    "outputTemplate": "value ? \"\"ON\"\" : \"OFF\"",
    "displayName": "Turned on"
  },
  "dim": {
    "capability": "dim",
    "stateTopic": "ha_test/light/kleedkamer_lamp/state",
    "commandTopic": "ha_test/light/kleedkamer_lamp/set_light",
    "valueTemplate": "$.brightness / 255 * 100",
    "outputTemplate": "round((value / 100) * 255)",
    "displayName": "Brightness"
  }
}

The only thing that properly changes in Homey when I change it in HA is on/off. Changing on/off in Homey does not work, because the payload is “ON” or “OFF” and not the JSON object stated above.

So my questions are:
How can I transform on/off in a proper JSON format
How can I make calculations in the value_template on the JSON input received? The current template does not work
How can I transform the output to make it a JSON object? Now only the value is send

I am sorry for all the questions. I cannot seem to find the right help on the internet to guide me in the right direction.

I do have a work around and that is using a virtual device controller by messages through MQTT client. I can properly format the messages in a flow. This works perfectly with sensors, which are one way of course. With lights not so much. When I change the dim level in Homey, it is not in sync with MQTT. While dimming, messages from the changing MQTT state are also coming in with a slight delay, messing up the process. Reading back in this thread, Harrie de Groot seems to have fixed that.

I appreciate your help. And thanks @HarriedeGroot for creating this app! I hope you and/or the developer community will maintain it in future as well.

Trying also to understand how to pick a value with JSONpath and use it in a MathJS expression for unit convertion. I.e
I have a topic that delivers temperature (t) in decigrades and not centigrades:
{"type":6,"t":406}
Now I would like to be able to evaluate "$.t / 10" to get centigrades in the valueTemplate. But somehow do not get that working.

And the answer is to use "valueTemplate": "t / 10"

2 Likes

MQTT Device as a thermostat. How can I set the range scale so that maximum temperature is 40°C instead of the default 35°C? I would be using the thermostat mode to set Spa temperature to 37°C.

I suspect Athom has set the limits for target_temperature and the MQTT device uses default ranges for capabilities.
My tado thermostat target temperature has an equal range: 4° - 35°
(while tado itself is limited to 25°, when using their mobile app)
https://support.homey.app/hc/en-us/requests/new