Help with data format

I use Weather Display for my weather station and am using thr clientraw integration to bring some local data to my dashboard.

Over the weekend I decided to obtain some different data using mqtt from Weather Display to my system. That was interesting but doable.

I am at the point of being stuck on how to format the data. For example, temp comes back as wd{ 19 }. I’m sure there a json call to extract the data and that is where I need help.

Thanks

Please post the sensor config you are using. If a sensor returns the string wd{ 19 } which is not valid json, you can extract the number with the following template:

value_template: '{{ value.split("{")[1].split("}")[0] | int }}'
  - platform: mqtt
    name: "Temperature"
    icon: mdi:thermometer
    state_topic: "temp"
    unit_of_measurement: ''

Thank you for the help.

Try this:

  - platform: mqtt
    name: "Temperature"
    icon: mdi:thermometer
    state_topic: "temp"
    unit_of_measurement: '°C'  # or °F 
    value_template: '{{ value.split("{")[1].split("}")[0] | int }}'

On the data that are integers, it’s working great. Thank you.

I have some that are float example baro reading wd{ 30.458 } returns 0

more of the data
image

on the data that did not have units attached and were floating point, I changed the int to float and that is working perfectly.

Enough for tonight, start fresh tomorrow.

Thanks again

For the mph units ones, you can try:

value_template: '{{ value.split("{")[1].split("mph }")[0] | int }}'

The second split need to match what is to the left of the closing bracket, inluding any space characters.

Just wanted to thank you again for the help. I was able to use the example to extract data that had units. And later on used it to extract string data.

You can simply slice off the unwanted characters from the value.

For example, this removes the first four characters and the last two:

value_template: "{{ value[4:-2] }}"

In other words, if the data is wd{ 30.458 } it will return 30.458

If it’s wd{ 13.0 mph } we need to remove the first four characters and the last six:

value_template: "{{ value[4:-6] }}"

The result will be 13.0