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
{"HMI_outdoorTemp":7}
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
{"HMI_weather":32,"HMI_outdoorTemp":7}
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?
events.sendCommand("ns_temperature",""+ir.getItem("CabinDevices_CabinRoomTemperature").state.intValue())
Properties map = new Properties()
File file = new File("../conf/transform/weather.map")
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(
"{\"HMI_weather\":%s,\"HMI_outdoorTemp\":{\"current\":%d,\"range\":\"%d,%d\"}}",
weather, outdoorTemp, apparentTemp, apparentTemp)
events.sendCommand("nspsend_command",json)