Is there a way to get the full mqtt topic that is wildcarded?

I am trying to get the full topic that is being sent from a cheap yellow display so I can use that to action on.

I have a topic hasp/plate/state# and I can see the values of the topic but not where they are coming from.

I have tried lots of different ways to do this and out of desperation I asked chatgpt and still no luck.

I want to be able to do this in ECMAScrip and I am running OH 5.

Can this be done?

I can see the whole topic in mosquitto and it works even though I am seeing a space in the topic and don’t know why the space is there.

hasp/plate/command/ p1b11.val 14.4
hasp/plate/command/ p1b12.val 20.18
 

The rule that puts the temperature to the screen is:

var OUTTEMP = (items.getItem("Rawmqttdata_Outsidetemperature").state)
var INTEMP = (items.getItem("Rawmqttdata_Insidetemperature").state)


items.getItem("CYD_test_Test_lables").sendCommand("p1b11.val " + OUTTEMP)
items.getItem("CYD_test_Test_lables").sendCommand("p1b12.val " + INTEMP)

Thanks

Not through a state channel but you can through an event Channel.

Create a Channel on the Broker Thing to subscribe to the wild card topic. One of the properties will be defining a separator character but # which is the default is usually sufficient. The event generated by the Channel sent to the rule will be <topic>#<message>

Use that Channel to trigger a rule directly. In a UI rule event.event has the String of the Channel event. In a file based rule it’s in event.receivedEvent. Simply split the event and you have both.

var topic = event.event.split('#')[0];
var message = event.event.split('#')[1];

Thanks. I did see an article similar to your suggestion but it was in dsl. I spent days trying to figure this out.

Your suggestion does work!

The part I was missing is the event.event. Now I just have to figure out how to make it all work in openhasp.

There is an article here on openhasp and openhab:

And the code for it here:

https://github.com/HASwitchPlate/openHASP-demo

Thanks again. Much appreciated. I am not much of a programmer I am more a find an example and modify it person. :slightly_smiling_face:

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.