[SOLVED] Tasmota - Sonoff - SDS011 cannot transform PM2.5

Tags: #<Tag:0x00007f744f1102e0>

Raspberry Pi 3 B+
Openhab 2.4

I’ve been looking for days trying to reach a solution to this problem, finally gave in! (plus i’m only a month in to Openhab)

I’ve flashed a Sonoff Basic with Tasmota and connected a SDS011 via serial and MQTT is reporting:
{“Time”:“2019-05-14T21:23:38”,“SDS0X1”:{“PM2.5”:2.9,“PM10”:4.7}}

I’m using Paper UI to add the thing and using JSONPATH to transform for the value.

It works fine for PM10 using the below transformation:
JSONPATH:$.SDS0X1.PM10

However when I try and transform for the PM2.5 it fails.
Transformation:
JSONPATH:$.SDS0X1.PM2.5

Log Viewer:
2019-05-14 22:46:09.504 [WARN ] [l.generic.ChannelStateTransformation] - Executing the JSONPATH-transformation failed: Invalid path ‘$.SDS0X1.PM2.5’ in ‘{“Time”:“2019-05-14T22:46:09”,“SDS0X1”:{“PM2.5”:3.6,“PM10”:5.9}}’

I suspect its the decimal point in ‘2.5’

I’ve looked for how to remove the decimal in Tasmota and cannot work that one out, looked for how to handle decimals in JSONPATH with no joy.

Any suggestions would be much appreciated.

Thanks

John

Perhaps adding an escape before the .

JSONPATH:$.SDS0X1.PM2\.5

Thanks for getting back. Unfortunately we have the same error:
2019-05-15 09:45:38.116 [WARN ] [l.generic.ChannelStateTransformation] - Executing the JSONPATH-transformation failed: Invalid path ‘$.SDS0X1.PM2.5’ in ‘{“Time”:“2019-05-15T09:45:37”,“SDS0X1”:{“PM2.5”:2.0,“PM10”:9.1}}’

Thanks

John

There might be a bug or limitation in handling keys with a dot. But regex should work here as an alternative.

Regex(.*PM2\.5\":(.*),.*)

Its still not playing ball. error as follows:
2019-05-15 17:50:29.520 [WARN ] [l.generic.ChannelStateTransformation] - Transformation service REGEX(.PM2.5" for pattern (.),.*) not found!

It looks like you are missing a * after the first .. You might need to escape the : with \:.

Please post your exact configuration if it still shows an error.

Thanks for the help.
Its still not working, for some reason the log entry doesn’t show all the char’s
the latest log for Regex(.PM2.5":(.),.):
2019-05-15 18:29:00.718 [WARN ] [l.generic.ChannelStateTransformation] - Transformation service REGEX(.PM2.5"\ for pattern (.),.
) not found!

Config:
the sensor is connected via serial into a sonoff with Tasmota.

MQTT.fx is reporting the following:
tele/AirQual/SENSOR
{“Time”:“2019-05-15T18:37:21”,“SDS0X1”:{“PM2.5”:2.3,“PM10”:6.3}}

The Thing is set up as generic MQTT and the channel is set up as TEXT (and I’ve tried Number) and as follows:

(This works fine with JSONPATH:$.SDS0X1.PM10)

If i remove the transformation i get the full results in the item.

However if i use JSONPATH:$.SDS0X1.PM2.5 or Regex(.PM2.5":(.),.) or Regex(.PM2.5":(.),.) it fails.

Thanks

John

If you are using the MQTT binding, you have to use the proper syntax for transforms.

REGEX:.*PM2\.5\"\:(.*),.*

The syntax for MQTT2 is different from what other bindings use.

That : still might cause some problems too. If it does, replace the \: with . and it should still work.

Thanks very much, its working fine now. as per the solution above. I didn’t know MQTT 2 Binding affects Regex as well. Some more reading needed!

The “standard” format for transformations everywhere else is <transform name>(<argument>) where <transform name> is the name of the transfomation add-on (e.g. REGEX, JSONPATH, MAP) and <argument> is the argument (e.g. mymap.map, $.SDS0X1.PM10, .PM2.5":(.),.*, etc).

For the MQTT2 binding, the developer decided to do his own thing and use a colon instead of the ().

<transform name>:<argument>

Hi rlkoshak
Your solution didn’t work in my case.
I have incoming from Tasmota:

20:34:53 MQT: tele/Pogoda/SENSOR = {"Time":"2019-11-01T20:34:53","Switch1":"OFF","BME280":{"Temperature":3.9,"Humidity":81.0,"Pressure":983.4},"SDS0X1":{"PM2.5":21.5,"PM10":33.8},"PressureUnit":"hPa","TempUnit":"C"}

PM10 I can tranform by JSONPATH:$.SDS0X1.PM10
And it works.
PM2.5 don’t work in this way.
I found this topic and I try to do it like you wrote.
Regex transformation is installed.
Item type connected for PM2.5 channel is Regex type.
I try put in channel
REGEX:.*PM2\.5\"\:(.*),.*
and I have in logs

2019-11-01 20:40:53.272 [WARN ] [eneric.internal.generic.ChannelState] - Incoming payload '20.8,"PM10":35.1},"PressureUnit":"hPa"' not supported by type 'NumberValue'

(where 20.8 is my PM2.5 value).
When I try put REGEX:.*PM2\.5\".(.*),.* I have in logs

2019-11-01 20:43:06.814 [WARN ] [eneric.internal.generic.ChannelState] - Incoming payload '18.7,"PM10":28.3},"PressureUnit":"hPa"' not supported by type 'NumberValue'

(log is the same like before - 18.7 is my PM2.5 value).

What I am doing wrong? I am new in OH.
My MQTT Bindind is 2.4.0.
Can you help me with this?

Please How to use code fences. I can’t see what your regex is.

If you can extract the value for PM10 why can’t you extract the value for PM2.5? What’s the error? What JSONPATH did you try to use?

I fixed fences in previous post.
I try use for PM2.5 this JSONPATH:$.SDS0X1.PM2.5
But I received in logs

2019-11-01 21:58:15.912 [WARN ] [eneric.internal.generic.ChannelState] - Incoming payload '{"Time":"2019-11-01T21:58:16","Switch1":"OFF","BME280":{"Temperature":3.5,"Humidity":82.1,"Pressure":982.7},"SDS0X1":{"PM2.5":22.1,"PM10":39.4},"PressureUnit":"hPa","TempUnit":"C"}' not supported by type 'NumberValue'

In Control in PaperUI I see “NaN”.

OK, it’s probably the 2.5. Try to escape the ..

JSONPATH:$.SDS0X1.PM2\.5

What is the type of your Item? Are you using a Unit of Measure such as Number:Pressure? MQTT doesn’t currently support units of measurement. Just use Number.

I try to use JSONPATH:$.SDS0X1.PM2\.5 but still I have in logs

2019-11-01 22:35:06.096 [WARN ] [eneric.internal.generic.ChannelState] - Incoming payload '{"Time":"2019-11-01T22:35:06","Switch1":"OFF","BME280":{"Temperature":3.4,"Humidity":82.4,"Pressure":982.2},"SDS0X1":{"PM2.5":20.4,"PM10":30.5},"PressureUnit":"hPa","TempUnit":"C"}' not supported by type 'NumberValue'

Type of item for PM10 and PM2.5 is Number. I don’t use in those items any Units. When I have Item with pressure I use type Number Pressure and it works normally.

I left Domoticz and started with OH. It’s nice but on first look it’s hard to understand.

OK, this might be running into a bug in the 2.4 binding. It is recommended to run a later version of the binding anyway so at this point my only suggestion is to upgrade to OH 2.5 M4.

I updated OH to 2.5.0 M4-1.
After this I needed to delete channels and add it again.
When I put JSONPATH:$.SDS0X1.PM2\.5 into transformation field I have in logs:

2019-11-02 23:56:20.971 [WARN ] [t.generic.ChannelStateTransformation] - Executing the JSONPATH-transformation failed: Invalid path '$.SDS0X1.PM2.5' in '{"Time":"2019-11-02T23:56:19","Switch1":"OFF","BME280":{"Temperature":7.7,"Humidity":90.9,"Pressure":971.8},"SDS0X1":{"PM2.5":19.8,"PM10":30.4},"PressureUnit":"hPa","TempUnit":"C"}'

I also try to use Regex. Nothing works.

A bit of googling suggests single quotes can be used to escape in JSONPATH

JSONPATH:$.SDS0X1.'PM2.5'

After changes I have warning:

2019-11-04 21:21:40.252 [WARN ] [t.generic.ChannelStateTransformation] - Executing the JSONPATH-transformation failed: Invalid path '$.SDS0X1.'PM2.5'' in '{"Time":"2019-11-04T21:21:40","Switch1":"ON","BME280":{"Temperature":12.2,"Humidity":93.1,"Pressure":965.9},"SDS0X1":{"PM2.5":30.5,"PM10":47.2},"PressureUnit":"hPa","TempUnit":"C"}'

I don’t know why it is “invalid path”. With PM10 I don’t have any problem.

Because of the . in the 2.5. . has a special meaning in JSONPATH. without figuring out how to escape it the JOSNPATH is asking for the 5 element under the PM2 element under the SDS0X1 element. What we want is the PM2.5 element under the SDS0X1 element. So all the stuff we’ve asked you to do is to figure out how to make the JOSNPATH treat the last . as part of the element name, not as part of the path.

It is possible the JSONPATH library used by OH supports bracket notation. Try

JSONPATH:$[`SDS0X1`][`PM2.5`]

See https://support.smartbear.com/readyapi/docs/testing/jsonpath-reference.html

object.property
['object'].['property']

Selects the property property in the object object.

Note: Use the latter notation if the name of the property includes special characters (for example, spaces), or begins with a character other than A..Za..z_ .