Computed tags: a tag made from a formula
The number you want is often not one a sensor sends: the difference between supply and return, a temperature in °F, how much warmer the boiler room is than outdoors. A computed tag is a tag made from other tags with a formula, such as a - b. It has the whole history of its tags the moment you make it, in every chart, and you can put an alert on it.
Computed tags are free and do not count toward your tag limit. You can have as many computed tags as your plan has tags.
Last updated
Make one
In the Explorer, open Tags and press New computed tag. Give it a name, pick its tags - each one gets a letter, a for the first, b for the next - and write the formula with the letters. A unit and a description are optional.
While you type, Tag Historian checks the formula against your real history and shows, under it, how far back the tag will reach and which of its tags decides that, its last two days, and how many of the last 30 days have a value. A mistake is marked where it is, in words: a letter no tag was picked for, a bracket never closed, a decimal comma.
Up to 6 tags per formula, one per letter a to f. The tags must be all levels - temperatures, pressures, percentages - or all meters: energy, water, gas (see meters below). Levels and meters cannot be mixed in one formula, and an on/off tag cannot be calculated with: its numbers are states. A formula with no tags is a constant, a reference line from your earliest history.
What a formula can say
+ - * /and brackets, with numbers written with a point:1.8,0.001,1e-3.abs,min,max,sqrt,pow,round,clampandif, whose first argument may compare:if(a > b, a - b, 0).- Examples: the temperature difference
a - b; °C to °Fa * 1.8 + 32; the average of three rooms(a + b + c) / 3; a sharea / b * 100. - An hour where the formula has no answer - a division by zero, the square root of a negative number - has no value. It is never drawn as 0.
History and resolution
Nothing is stored for a computed tag. It is calculated from its tags' hourly averages whenever it is read, so it has a value for every hour in which all of its tags have one, back to where the youngest of them starts and at most 10 years, imported Home Assistant history included. Change the formula and every chart of it shows the new one over all of its history.
- A computed tag has one value per hour. A unit conversion of a single tag that is not a meter keeps every reading.
- On a chart the band around the line is its lowest and highest hourly value.
- A sum or difference of tags, scaled, is exact on hourly averages. For products and ratios the hourly value is close to, but not exactly, what a meter measuring it directly would show, and the Explorer says so beside the formula.
- Its value on the Tags page is the formula of its tags' newest readings. If one of them has sent nothing for a day, it has no current value; its history is still there.
Meters: totals and ratios
A formula over meters is a computed meter. It is never calculated from the meters' readings themselves - those are running totals that start over when a meter is reset or replaced - but from what each meter added: in an hour, a day or a month, and the formula is applied to those amounts. Each meter keeps its own resets and recorded replacements.
- A total, such as
a + b,a - bora * 0.001(Wh to kWh), adds up: its days add up to its months and years, as a meter's do. Years, the Excel report's Increase column and Fair winter all treat it as a meter. - A ratio, such as a COP
a / b, is worked out for each bucket on its own: a day's COP is that day's heat over that day's electricity, and a month's is the month's. It is never added up: in Years each month is its own ratio, and an Excel report leaves its total empty. Anything that is not a plain sum of meters - a constant added, amax- counts as a ratio. - In Trends a computed meter is drawn as its hourly value - the formula over what each meter added in the hour - and Show as gives its increase per hour, day or month, as for any meter.
- A bucket has a value when every meter has an hour in it; what a meter added while it was silent is counted in its first hour back, as its own increase counts it.
- It has no current value on the Tags page: its newest figure is its newest hour.
Where it shows
In Trends, Years and Compare with last year, in Grafana, in read-only shared links, in the CSV, JSON and Parquet downloads and in Excel reports, under its own name, as any tag. In an Excel report its minimum and maximum are its lowest and highest hourly value, and its readings are 0, as it stores none of its own; it counts toward the report's size as the tags it is calculated from. Export everything holds its hours, one row per hour, under computed/. Through the API its values come from the same endpoints as any tag's, with a Read key; the tag list includes computed tags when asked with GET /api/tags?include=computed, and the definitions are at GET /api/computed-tags.
Fair winter reads a computed meter that adds meters together; a ratio or a computed tag over levels has no energy for it to compare with the weather, and it says so.
Normal range and Unusual
A computed tag gets a normal range of its own, learned from its own hourly values - the formula over its tags' hours - exactly as a tag with readings gets one: early each morning, from three weeks of history for charts, and from a year or more, tried on its own past weeks first, before it may raise an alert. Trends draws it beside the line, and the tag's sheet on the Tags page says what it was learned from.
- A computed meter that adds meters together has a range of what it adds per hour and per day, drawn behind its bars. A ratio, such as a COP, has a range of its hours: a day's ratio is not its hours added up.
- A constant has no normal range.
- Its alerts can be judged by the outdoor temperature (SMHI's, for an account with a place in Sweden, or the account's own outdoor sensor - never a DWD station's, whose hours come the day after) or by the day of the week instead of the time of year, where its own past shows that is clearly better, as for any tag.
- Change the formula and its range is learned again from all of its history, within the hour.
- An Unusual alert is never turned on for a computed tag by itself. Once its range can raise alerts, its sheet offers Tell me when this is unusual, or make an Unusual rule on the Alarms page. It is then checked once an hour like any other, and an hour counts only when every one of its tags has a fresh hour of readings, or held its value while the rest of your sources were sending.
Alerts
Above, Below, Between and Equals work on a computed tag, and are checked once an hour, on the hour's value, within about a quarter of an hour after the hour ends - the same number the chart shows. A delay counts in whole hours. No data for, Stuck at one value and Rate of change are not offered: a computed tag has no readings of its own, so put those rules on its tags. On a computed meter the rule is checked on the hour's increase: the formula over what each meter added in the hour, the value its chart draws. See alerts for the rest.
Unusual works on a computed tag too, once you ask for it: see normal range and Unusual above.
Trying a rule on the last 12 months works on a computed tag too. It is tried on each hour's value - for a computed meter, each hour's increase - the value the rule is checked on once it is on, and the answer says so. As on any tag, an Unusual rule is not tried on its history: the range it is judged against is learned again as the months go by.
When its tags change
- Rename or merge one of its tags, and the computed tag follows: its formula reads the tag by its new name.
- A tag a computed tag uses cannot be deleted while it does; the Tags page names the computed tag to change or delete first.
- Rename a computed tag and its alert rules, its normal range, the chart views that show it and their read-only links take the new name with it. Its formula and values do not change. The old name is free afterwards.
- Delete a computed tag and its alert rules and normal range go with it, and it is taken off the chart views and links that show it. Its tags and their history are untouched, so making it again gives back the same values.
- Your account export holds every computed tag's definition and what its normal range was learned from; Export everything holds the range itself, beside its hours.
Common questions
- Does a computed tag count toward my tag limit?
- No. Computed tags are free and do not count toward your tag limit. You can have as many computed tags as your plan has tags. It counts toward neither your daily readings nor your storage: nothing is stored for it.
- Why does a new computed tag already have years of history?
- Because it is calculated from its tags’ hourly history whenever it is read. Wherever every tag in the formula has an hour, the computed tag has that hour, back to where the youngest of them starts.
- Is the value exact?
- A sum or difference of tags, scaled, is exact on hourly averages. A product, a ratio or a function is calculated from hourly averages too, which is close to, but not exactly, what a meter measuring it directly would show.
- Can I add two energy meters together, or work out a COP?
- Yes. Pick meters as the tags, and the formula is applied to what each meter added: a + b is their total, and heat over electricity, a / b, is the COP of each hour, day and month. Each meter's resets and replacements are counted on its own, so a total stays right when one of them starts over from zero.
- Can a computed tag use another computed tag?
- No. Pick the tags the other one is calculated from, and write the whole formula.