I am trying to use a rule to take that value and update another string item with…
S0PTH5VM
I have started a rule with a “replace” but I don’t seem to be having much luck…
Any pointers?
rule “Ventillation Fan Serial”
when
Item VentillationSerial changed
then
var String ReplaceTest = VentillationSerial.state.replace(',"SSerialReceived":"', '')
VentillationSerial2.postUpdate(ReplaceTest)
end
Tried a different approach based on findings in the forum and still get an error though…
rule "Ventillation Fan Serial"
when
Item VentillationSerial changed
then
var String ReplaceTest = VentillationSerial.state
ReplaceTest=ReplaceTest.replace(',"SSerialReceived":"','')
ReplaceTest=ReplaceTest.replace('"}','')
VentillationSerial2.postUpdate(ReplaceTest)
end
Rule ‘Ventillation Fan Serial’: An error occurred during the script execution: Could not invoke method: java.lang.String.replace(java.lang.CharSequence,java.lang.CharSequence) on instance: ,“SSerialReceived”:“S0PTH5VM”}
rule "Ventillation Fan Serial"
when
Item VentillationSerial changed
then
val ReplaceTest = triggeringItem.state.toString().replace(',"SSerialReceived":"', '').replace('"}', '')
VentillationSerial2.postUpdate(ReplaceTest)
end
The topic fragment string you have shown us looks to me like part of a JSON payload.
You might be able to treat it as JSON in the binding or in a rule, rather than getting into direct string manipulation.