I’m currently setting up my NSPanel flashed with Tasmota and I want to set the temperature which is displayed on the main screen independently of the displayed weather icon and the forecast range.
However it is required to send one JSON object to a topic which contains all 4 values.
What I want to achieve is that if one of the 4 is updated, one JSON payload will be send to the topic.
My initial thought was that JS Transformation might be the way to go, but it will only receive one of the 4 states, not all of them.
This is my thing:
Bridge mqtt:broker:mosquitto [
//...
] {
Thing topic livingroomNsPanel "Livingroom NsPanel" @ "Livingroom" [
availabilityTopic="livingroom/nspanel/LWT",
payloadAvailable="Online",
payloadNotAvailable="Offline"
] {
Channels:
Type string : screenMainWeatherIcon [
commandTopic="livingroom/nspanel/cmnd/nspsend",
transformationPatternOut="???",
allowedStates="sunny,partlyCloudy,cloudy,fog,storm,lightSnow,snow,hail,softHail,redThermostat,blueThermostat,windy,rainy"
]
Type number : sreenMainOutdoorTemperature [
commandTopic="livingroom/nspanel/cmnd/nspsend",
transformationPatternOut="???"
]
}
}
The JSON being send out must look like this:
{"HMI_weather":7,"HMI_outdoorTemp":{"current":5,"range":"-3,8"}}
If I had all values available, the JS Transformation would probably look like this:
/**
*
* @param {string} icon
* @param {number} temperature
* @param {number} min
* @param {number} max
* @returns string
*/
function (icon, temperature, min, max) {
const iconMap = {
"sunny": 1,
"partlyCloudy": 2,
"cloudy": 7,
"fog": 11,
"storm": 15,
"lightSnow": 20,
"snow": 22,
"hail": 24,
"softHail": 29,
"redThermostat": 30,
"blueThermostat": 31,
"windy": 32,
"rainy": 40
};
const result = {
"HMI_weather": iconMap[icon],
"HMI_outdoorTemp": {
"current": temperature,
"range": `${min}-${max}`
}
};
return result;
}
But how do I get all the different states if only one is updated?