Aircon-State reading via MQTT2 Binding.....transformationPattern?

Hello,
I’m on 2.5.12 + MQTT2 binding.

Recently did customize my Midea Aircon with an open dongle that provides following structure via MQTT.

/miAC/state [{"ist":23,"aussen":11,"conf":{"on":false,"turbo":false,"eco":false,"soll":17,"lamelle":false,"mode":5,"fan":0}}]

It looks little different from what i use via zigbee2mqtt, especially the outside []…i tried several ways but simply states invalid path in the logs…so something is wrong here…but what. Can you please help me to recevei for example the ist temp at 23°C.

This does not work at all:
Type number : miAC_TempIn "Temp Inside [%.1f °C]" [ stateTopic="/miAC/state", transformationPattern="JSONPATH:$.ist" ]

I find it easiest to play with transforms in rules, transfer to channel settings when validated.

val rawjson = '[{"ist":23,"aussen":11,"conf":{"on":false,"turbo":false,"eco":false,"soll":17,"lamelle":false,"mode":5,"fan":0}}]'
var results = transform("JSONPATH", "$.[0].ist", rawjson)
logInfo("test", " array path " + results)
2021-05-13 23:36:20.311 [INFO ] [.eclipse.smarthome.model.script.test] -  array path 23

[ ] denotes an array, even if it has only one element.

oh thanks. i’ve never came across json in an array, especially here as its only one field if i get it right.

Thanks also for the rule based solution. Is there any kind of direct way to not create additional rules for this transformation?

Cheers
Norbert

It’s not a rule based solution, it’s a test bed so that you can test out different ideas for the JSONPATH parameter you were struggling with. Of course you also need sample data, which you most helpfully provided.

I don’t know what you mean. You don’t need any rule for your original problem, just a revised JSONPATH parameter.

Type number : miAC_TempIn “Temp Inside [%.1f °C]” [ stateTopic="/miAC/state", transformationPattern=“JSONPATH:$.[0].ist” ]

ah OK that makes sense, using index 0 of 1 field overall size. Will try. thanks a lot!

works great thanks.

Now i struggle at the other direction. Sidenote I removed the useless Array completely in the AirCon Code.
The AirCon status can be seen here:

[ stateTopic="/miAC/state", transformationPattern="JSONPATH:$.conf.on",on="true", off="false" ]
…which works fine…but setting the AC to ON/OFF simply does not work.

Turning ON the AC should be sending MQTT to /miAC/cmd the following…{"on":true}
Which works great if i directly publish this via MQTT.fx client

Putting this into the same thing i thought it would be like this (similar to other working zigbee2mqtt switches)

Type switch : miAC_Power "miAC Power [%s]" [ stateTopic="/miAC/state", commandTopic="/miAC/cmd", transformationPattern="JSONPATH:$.conf.on", transformationPatternOut="JSONPATH:$.on", on="true", off="false" ]

After each successful integration of MQTT json messages i have some believe I now can handle this, but situations like right now show me the opposite.

Error log shows:

2021-05-15 00:19:39.665 [WARN ] [t.generic.ChannelStateTransformation] - Executing the JSONPATH-transformation failed: Invalid path '$.on' in 'true'

Any idea what i do wrong?
Thanks a lot Norbert

This is a nonsense; JSONPATH has only one function, to extract data from JSON. It does not work in reverse and build JSON.

You might be able to do this using formatBeforePublish

1 Like

hm, thanks for the feedback.

I now did it that way, which works:
Type switch : miAC_Power "miAC Power [%s]" [ stateTopic="/miAC/state", commandTopic="/miAC/cmd", transformationPattern="JSONPATH:$.conf.on", formatBeforePublish="{ \"on\": %s }", on="true", off="false" ]

Still few question. if there is no JSONPATH backward possible, what is the transformationOutPattern for?
Is there any documenttaion available for this part?

Another question i ask myself now many times before.
Is the order important? like stateTopic and directly afterwards the mapping table like on=“true”,…and after this the commandTopic…or first stateTopic, then commandTopic and in the end the mappings?

is the mapping on=“true”,… also used/valid for the commandTopic ?

Kind Regards
Norbert

Because … that is what you asked for?

You want to send the payload {"on":true} (or presumably {"on":false}
This is relatively simple, as JSON goes.
So you can build your required message as a string
{“on”: + substituteYourValue + }

formatBeforePublish is documented here

sorry @rossko57, i do not get your second message. it already works so not sure why you explain it a second time.

I guess you are aware here as well and can bring light into these questions:

Is the order inside the thing definition important? like stateTopic first and directly afterwards the mapping table like on=“true”,…and after this the commandTopic…or first stateTopic, then commandTopic and in the end the mappings?

Is the mapping on=“true”,… also used/valid for the commandTopic ?..meaning that if you use stateTopic and commandTopic, who of them is using the on="true,off=“false” mapping? both i guess…

Thanks
Norbert

because

Then

No. You can always try this stuff out for yourself.

Yes. You can call it bi-directional. It’s in the docs-

Thanks!

one more question that i have regarding an item that has a underlying map file “ACmode.map”.

1=Auto
2=Cool
3=Dry
4=Heat
5=Fan

I right now only show the %d values coming from the AC.

Type string : miAC_Mode "miAC Mode [%s]" [ stateTopic="/miAC/state", transformationPattern="JSONPATH:$.conf.mode" ]

My guess was/is that as advanced as MQTT2 is it would also be able to directly handle the map file.

So I found in the community the following example:

            Type switch : reachable "Reachable" [
                stateTopic="tele/sonoff-SW01/LWT",
                transformationPattern="MAP:reachable.map"

Which brings me to my question…how can I bring togehter the two transformationPattern when first i need the JSONPATH and second I would need the ACmode.map?

Is this still somehow able to manage?

hmm, I suppose you might be able to chain two transformations, one after the other. So you’d use JSONPATH to extract a value, and MAP to convert it to something else by lookup.

I found a discussion based on chaining…

which says to do it like this JSONPATH:$.conf.mode∩MAP:ACmode.map.
I tried it based on my map file but did not work. map file looks correct to me.
But in the documentation you mentioned there is no word written about this “∩” special character.

update: found it in the doc but still no success.

Transformations can be chained by separating them with the mathematical intersection character “∩”. Please note that the incoming value will be discarded if one transformation fails

Maybe you see something i did configure wrong:


 Type string : miAC_Mode "miAC Mode [%s]" [ stateTopic="/miAC/state", transformationPattern="JSONPATH:$.conf.mode∩MAP:ACmode.map" ]

MAP, like JSONPATH,is an installable add-on. Unlike JSONPATH, it relies on a text file you have to put in the correct folder.
Look in your logs.

sure, its installed (map add-on) and of course i have the map file in the transform folder.

1=Auto
2=Cool
3=Dry
4=Heat
5=Fan

Again, look in your logs.

As you’re configuring from file, it’s worth remembering that small Thing/channel edits are not always immediately implemented, depending on binding. Sometimes a package restart is need to ensure latest config is in use.

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.