Reading the documentation on the map transformation service and searching the forum didn’t give me a clear answer on how to setup a simple number to text mapping for a sensor item.
The case: I read a value from an MQTT message (DSMR meter tariff) which returns 1 or 2, and I want to display that on a sitemap as “Low” or “High”. Since it is not a switch or selection, I cannot use the mapping parameter (it wouldn’t make sense to be able to change the selection from Low to High for instance).
I found some clue in the map transformation documentation but don’t really know what to fill in at the Channel ID parameter.
I read the value from MQTT message with:
Number PowerTariff "Huidig Tarief [%d]" {mqtt="<[mosquitto:sensor/dsmr:state:JSONPATH($.power.tariff)]"}
So, I figured something like this would do the trick, except that I don’t know what to fill in at the channel parameter:
@noppes123
I followed your solution for doing kind of the same in my case, but it does not work.
I hope you can help me.
Situation: From my smart meter, I get tariff info in number format (0001 or 0002)
I would love to replace the numbers by text: 0001 should be ‘Day’ and 0002 should be ‘Night’.
I have, as you mentioned, put the mapping in the item label:
Number Elektriciteit_TariffIndicator “Huidig Tarief: [MAP(tariff.map):%s]” { channel=“dsmr:electricity_emucs_v1_0:1:emeter_tariff_indicator” }
Is your Item now a Number or a String type? Look in your events.log to see what states it is taking up.
When it is a Number, it won’t be 0001, it’ll be just 1 when converted to a string for lookup in the MAP. You can have both 1= and 0001= in your map file.
What we don’t know with all the changes and suggestions is what you have now.
Please show us -
Item definition
Sitemap line
An events.log entry showing a state change of current Item.
You should have error messages in your openhab.log at least relating to earlier attempts.