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

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

SOLVED
Highlighted
Regular Member

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.

Tags (1)
1 ACCEPTED SOLUTION

Accepted Solutions

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

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);

2 REPLIES 2

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

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);

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

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.