Closed mclei-asw closed 6 years ago
Another reason: If I want to control Sonoff sockets directly through MQTT, then I also need 0/1 values and not JSON.
I'll see what I can do after I get the big refactor needed to get water sensor & co working :)
I've also done some work on this in the branch for [https://github.com/Frans-Willem/AqaraHub/issues/24](issue #24). If you pass the command-line argument "--recursive-publish", it will recursively publish JSON object properties & array elements to MQTT sub-topics. For example the Xiaomi button, on single press, would report to these topics:
<INFO> [PublishValue] Publishing to 'AqaraHub/00158d000152d7b2/1/in/OnOff/Report Attributes': {"reports":[{"Attribute data":{"type":"bool","value":true},"Attribute identifier":"OnOff"}]}
<INFO> [PublishValue] Publishing to 'AqaraHub/00158d000152d7b2/1/in/OnOff/Report Attributes/reports': [{"Attribute data":{"type":"bool","value":true},"Attribute identifier":"OnOff"}]
<INFO> [PublishValue] Publishing to 'AqaraHub/00158d000152d7b2/1/in/OnOff/Report Attributes/reports/0': {"Attribute data":{"type":"bool","value":true},"Attribute identifier":"OnOff"}
<INFO> [PublishValue] Publishing to 'AqaraHub/00158d000152d7b2/1/in/OnOff/Report Attributes/reports/0/Attribute data': {"type":"bool","value":true}
<INFO> [PublishValue] Publishing to 'AqaraHub/00158d000152d7b2/1/in/OnOff/Report Attributes/reports/0/Attribute data/type': "bool"
<INFO> [PublishValue] Publishing to 'AqaraHub/00158d000152d7b2/1/in/OnOff/Report Attributes/reports/0/Attribute data/value': true
<INFO> [PublishValue] Publishing to 'AqaraHub/00158d000152d7b2/1/in/OnOff/Report Attributes/reports/0/Attribute identifier': "OnOff"
<INFO> [OnZclCommand] Looks like something per-attribute. Publishing per-attribute too
<INFO> [PublishValue] Publishing to 'AqaraHub/00158d000152d7b2/1/in/OnOff/Report Attributes/OnOff': {"type":"bool","value":true}
<INFO> [PublishValue] Publishing to 'AqaraHub/00158d000152d7b2/1/in/OnOff/Report Attributes/OnOff/type': "bool"
<INFO> [PublishValue] Publishing to 'AqaraHub/00158d000152d7b2/1/in/OnOff/Report Attributes/OnOff/value': true
It'll be a bit 'chatty' on MQTT, but I think this will give you the most possibilities to listen for things without having to parse JSON. e.g. even the things that report bit-arrays (e.g. [true, false, false, false]
) where you only need the first element, will get a specific subtopic for each element in that array.
Let me know if this solves your problem :)
It is really too chatty, but it seems it simply works. I should test what is the impact on the mqtt server.
Current master version supports the --recursive-publish flag, which I think solves this. Closing for now :)
Continuing on issue #24:
It is ok for me to use JSON for sending commands, as it could be "constructed" as simple strings, without any JSON support. But for reading received values I have to use some JSON parser.
Now, the primary master of my home automation is PLC with IEC61131-3 programming (Foxtrot from Teco), where I have programmed a MQTT client. Parsing JSON is possible there, but it adds a unnecessary overhead because it is limited, specially in string resources.
Next I use some Arduino/ESP based gadgets, all connected to MQTT broker. And there I found it as a big overhead.