Best way to send command with 2 values

Looking for ideas on best way to do this.

To change the weather display on the nspanel you need to send a message with two elements.

nspsend {"HMI_weather":32,"HMI_outdoorTemp":7}

These are two openhab items taken from openweather binding.

Originally I had a rule on change of each which sent a command to the corresponding mqtt item on the NSpanel, so a change it temp would send the
However this doesn’t work bc the command needs both parts to be valid.

I know I could make the script actually make the json string from both parts and set that as the item like
and have no formatting on the channel. This would work I’m sure, but it would mean you see the actual json in the item, which feels a little clunky. Is there a better way?

Is it possible to send direct to the channel from the script, without an item? As I dont really need or want to see this internal item with the json in. feels a fudge to have it.

This works, but is it best way?


Properties map = new Properties()
File file = new File("../conf/transform/")
map.load(new FileReader(file))

def weather = map.getProperty(ir.getItem("LocalWeatherandForecast_WeatherConditionId").state.toString())
def outdoorTemp = ir.getItem("outdoor_temp").state.intValue()
def apparentTemp = ir.getItem("apparent_temperature").state.intValue()

def json = String.format(
  weather, outdoorTemp, apparentTemp, apparentTemp)


Why is that a problem, who is ever going to look at this compound Item?

No. All channel interactions are via a single Item.

What you can do is use the MQTT binding Action to send some text to an arbitrary topic directly from a rule.

I don’t know, your “best” will be different from mine.
“Works” goes a long way to satisfy me.
“Not going to catch me out in future” comes second - to me, having all relevant topics together in channels sounds like a good idea to me. You’ll have different priorities.

Your best would probably be better!! :slight_smile:

Anyway, all working a treat now. All the values on the screen are NOW populated from openhab items and not from the values from the unit, which are poor efforts to say the least.

Thermostat next…

If you are talking MainUI, remember it serves two purposes. System admin, where we might expect to see all kinds of behind the scenes stuff.
And user facing, where we see prettified presentations of stuff that actually matters to the user.

Don’t design your behind the scenes machinery on the basis of what it ‘looks like’.