How do I automate tag properties? History and storage provider

I have a few hundred sparkplug devices being added via the MQTT Engine. How do I automate the tag property to have history enabled with my storage provider?

Or is this not a thing? These are all devices sending timeseries data and there will be thousands of tags that need this enabled.

You could possibly script something using system.tag.configure.

pturmel's Spredsheet Import Tool might also be of use.

2 Likes

Be aware the MQTT tag providers can arbitrarily remove your tags, too, and any follow-up configuration you do may be lost. Consider using another tag provider that has reference tags pointing into the MQTT provider, and enable history on the reference tag. The source tag can then come and go without breaking your history.

4 Likes

Thank you. I managed to create reference tag script that runs periodically. Is this the best way to handle this type of data. The devices always send in approx a days worth of data at one time. So far I haven’t been able to get any backfill data to populate in my Postgres database.

Is it still true that back fill events on MQTT tags will not trigger the historization on reference tags?

I was able to get MQTT engine tags created with history and my chosen provider using this:

const definitions = {};
tagDefs.forEach(def => {
    definitions[def.tagName] = {
        dataType: 'Double',
        properties: {
            engUnits: { type: 'String', value: def.unit },
            documentation: { type: 'String', value: def.documentation },
            historyEnabled: {type: 'Boolean', value: true,},
            historyProvider: {type: 'String', value: 'Postgres',}
        }
    };
});
1 Like

You really should not use def as a variable name, as it is a python reserved word.

That's apparently a Javascript snippet, so no idea where they're executing that code... NodeRED, maybe?

1 Like

Yes, Node-RED.