Hi,
I have a device in my local network, which exposes its information for reading purposes via HTTP. The output is not structured (e.g. json or xml), but plain text and can be:
Device is ACTIVE
or
Device is DISABLED
I use the HTTP binding to read the message frequently:
This reads the “ACTIVE” or “DISABLED” into the item MyDevice_Status. Now I want to map the extracted string (ACTIVE or DISABLED) to a good practice item state (ON or OFF). I can use a mapping for this:
ACTIVE=ON
DISABLED=OFF
=UNKNOWN
However, I don’t see any possibility to combine MAP and REGEX in the item definition using the HTTP binding. I tried “chaining” them through
rule "Proxy mydevice"
when
Item MyDevice_Status_Proxy changed
then
MyDevice_Status.postUpdate(transform("MAP", "device.map", MyDevice_Status_Proxy.state.toString))
end
Thanks much for the quick reply! I thought about a similar solution. Follow up question:
A second endpoint at the device I mentioned exposes to write a state change to the device (switching something on or off). I want to combine the status (ON/OFF) in Device_Status along with an additional HTTP binding to post the state to the device downstream.
No, now you need to use .sendCommand in order to pass the state to the binding:
rule "Proxy mydevice"
when
Item MyDevice_Status_Proxy changed
then
MyDevice_Status.sendCommand(transform("MAP", "device.map", MyDevice_Status_Proxy.state.toString))
end
I’m reading the state from the device frequently, through MyDevice_Proxy (and its HTTP binding). If the state of the device has changed, I don’t want to write the same state back to the device.