How to use map in rule

I have a proxy item and I want to update this item with the status changed by another item

rule "PROXY state changed test"
when
Item DoorSensor18_TamperAlarm changed
then
Thread::sleep(10)
postUpdate(DoorSensor18_TamperAlarm_PROXY, DoorSensor18_TamperAlarm.state)
end

If the item has the same type this is working well. But if the item types are different I want to use the map to convert it.

But this does not work, syntac error.
postUpdate(DoorSensor18_TamperAlarmProxy, MAP(convert_contact_switch.map(DoorSensor18_TamperAlarm.state))

content of convert_contact_switch.map:
OFF=CLOSED
ON=OPEN
CLOSED=OFF
OPEN=ON
NULL=Unknown

I’m not sure where you got that code but it is all kinds of wrong.

To call a transform from a rule use the transform action:

transform("transform name", "transform argument", "string to transform")

So in your case you would use:

val trans = transform("MAP", "convert_contact_switch.map", DoorSensor18_TamperAlarm.state.toString)
1 Like

Ah, I understand, in my case?

DoorSensor18_TamperAlarmProxy = transform(“MAP”, “convert_contact_switch.map”, DoorSensor18_TamperAlarm.state.toString)

Like I already said

Then postUpdate(trans)

It is not working:

Rule ‘PROXY state changed test’: An error occured during the script execution: null

Ha
now it is working without any changes. I only opened the map file once and closed it. looks like the map file was not read into openhab.

Thanks, works perfect now.