cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Need help navigating or using the PTC Community? Contact the community team. X

How to convert/parse a value into another property on the same Thing.

StefanBode
10-Marble

How to convert/parse a value into another property on the same Thing.

Hi gentlemen,

I'm using the MQTT extension to get values from my home-automation system. The problem is, that in e.g. the property BRIGHTNESS the MQTT text is a long "story" and not the value itself: This is the String: {"val":150,"ts":"1460135379176","lc":"1460135379176","hm_addr":"MEQ0246804:1"}

Now I want to use the DataChange event to create a small snippet that transfer the value in my new property BRIGHTNESS_NUMBER. Also the last String "MEQ..." is interesting to me and I want to post this into another variable if not already set in the same Thing.

Could anyone help me with the parsing? The String is with the {} at the begin and end. "," is the separator and ":" the separator between the property and its value.

Thanks a lot.

1 ACCEPTED SOLUTION

Accepted Solutions

Found my answer by Mr Google:

var array = JSON.parse("[" +me.BRIGHTNESS+ "]")

logger.info("Value: " + array[0].val);

logger.info("TypeID: " + array[0].hm_addr);

me.BRIGHTNESS_VALUE = parseFloat(array[0].val);

View solution in original post

2 REPLIES 2

Found my answer by Mr Google:

var array = JSON.parse("[" +me.BRIGHTNESS+ "]")

logger.info("Value: " + array[0].val);

logger.info("TypeID: " + array[0].hm_addr);

me.BRIGHTNESS_VALUE = parseFloat(array[0].val);

Hello Stefan,

What base type is used for the new property "me.Brightness_Value"?

I am trying to accomplish the same thing however my property is not displaying the data changed value.

Top Tags