I use a tickscript to process a stream of kwh energy values (arriving about 10 per minute) into an aggregated sum for each minute :hh:00-:hh01 etc. Alongside the aggregate value for any given minute, I want to save the tariff.
The tariff is stored in a separate measurement ‘tariff’ and changes one or two times per day. I simply want to store the value of
SELECT last(“t_kwh”) FROM “telegraf”.“autogen”.“tariff”
as an extra field in my aggregated data table ‘energy’.
I can’t seem to figure out how to do this, as the tariff value is not streaming in regularly like the energy values.
The script currently in use for aggregation looks something like this:
|from() .database('telegraf') .measurement('telem_calcs') .groupBy('uID') |window() .period(1m) .every(1m) .align() |sum('energy') .as('energy_this_minute') |influxDBOut() .database('telegraf') .retentionPolicy('autogen') .measurement('energy') .precision('s')