This goes in the Formatters category. Release 0.0.5 is out -
https://github.com/FlyingDiver/Indigo-M ... /tag/0.0.5Added automatic publishing for Device changes
Added automatic publishing for Variable changes
Added template system for Device and Variable publishing
You can now specify devices and variables to automatically publish their updates. In the Broker device configuration, there are four panels for this capability. For devices, there's one panel to specify the devices which will have updates published. Then there's a second panel to specify a template for the formatting of the topic and payload fields. Then two more panels for variables.
The device/variable selection panels should be fairly self-explanatory. If not, let me know and I'll try to document sooner rather than later.
The Templates use the Mustache template system (
http://mustache.github.io) using the Pystache library (
https://github.com/defunkt/pystache). Default templates are included in all newly-created Broker devices, but I can't figure out how to get newlines and tabs into the defaultValue fields in the XML file, so the payload one isn't very readable. So here's some examples.
Say you want your payload to look like this (JSON):
- Code: Select all
{
'name': 'WeatherLink',
'deviceId':'732253293',
'model': 'WeatherLink Live',
'address': '192.168.111.40'
'states':
{
'did': '001D0A7107E9',
'status': 'OK',
'timestamp': 'Mon, 05 Aug 2019 14:46:51',
},
}
Yes, I know I'm missing the versioning and payload-type identifier Jay suggested. It's just an example. To get this output, the template looks like this:
- Code: Select all
{
'name': '{{name}}',
'deviceId':'{{deviceId}}',
'model': '{{model}}',
'address': '{{address}}',
'states':
{
{{#states}}
'{{name}}': '{{value}}',
{{/states}}
}
}
All the identifiers in the curly braces (they look sort of like mustaches, get it?) come from a python dictionary that the plugin creates that looks sort of like the one above. Not exactly, but close.
The #states and /states keywords are telling Mustache that this dictionary entry is actually a list of items, and this section should be repeated for each entry in the list.
If you want other data from the devices included in the dictionary so that you can get it into your payloads, just let me know.
The topic entry is pretty simple:
- Code: Select all
indigo/devices/{{deviceId}}/update
The variable templates are similar:
- Code: Select all
indigo/variables/{{variableId}}/update
{
'name': '{{name}}',
'variableId':'{{variableId}}',
'value': '{{value}}'
}
Clear? Probably not.