Instead of falling back to some comma separated solution, i decided to give JSON a try as we are already used to do JSON in publishing to MQTT in some cases.
First need was to obtain a unique ID used by the remote host that generated the event. Currently using the MAC address as this is both available for Ethernet devices as well as Zigbee (Philips Hue) devices that also have a (64 bit) MAC address.
So instead of the most simple incoming event:
Code: Select all
HA/Demo/Temperature=21.5
Code: Select all
HA/Demo/Temperature={"Value":21.5,"Mac":"00:11:22:33:44:55"}
So now i can send basic json objects as eventvalue from a remote system and the local ESP Rule Engine would be able to handle this without a single change to existing rule scripts.
Existing rule like this will still work (with the enhanced rule engine that internally parses the "Value" component):
Code: Select all
on HA/Demo/Temperature>0 do
if %eventvalue%<50
do something...
endif
endon
In my case, a more advanced systems like the WindowsRules engine passes the eventvalue to a powershell script that can fully decode the JSON object and fills a local MS-SQL database with all topics received on the MSGBUS by either UPD or MQTT. Here the Mac address is used as primary key in the database so it needs to be available on each event.
Sample WindowsRules:
Code: Select all
On HA/* do
shell powershell .\topic.ps1 '%event%
Endon
Code: Select all
MSGBUS HA/Demo/Temperature={"Value":%Temperature%,"Mac":"%mac%"}
Code: Select all
MQTTpublish HA/Demo/Temperature,{"Value":%Temperature%,"Mac":"%mac%"}
Next step could be to add a "parseFromJSON" rule command that can get addtional JSON values and store them into rule variables, either floats or strings.
Would this be of any interest on ESP Easy as well?
(not that i will likely be able to code it on the latest ESP Easy code, because it seems so much more complicated style of coding compared with R120)
Other question:
While surfing the internet on MQTT/JSON standards, i could not find any form of widely adopted standard structures for topics and JSON payloads related to IOT. So i just started to invent my own at the moment. But wouldn't it be great if there was something like a universal MQTT-IOT message format that will work on (m)any Home Automation system out of the box?
(or at least a subset that is widely understood?)
Anyone experience on this, or just stick with the standard of your chosen controller?
Which would mean a large change when changing controller.