Where do labels come from?


Currently trying to learn grafana but the documentation is not that helpful and Im a bit stuck. I have a psql database and im trying to setup an alert. My DB sends a message once every hour, containing battery, time and name of a bunch of devices. I want to setup an alert that goes off if a battery is running low. This is mostly for practise and understanding how stuff works.

I have a super basic query that looks something like

Where time > NOW() :: DATE -1

And im trying to setup an annotation that displays the battery value and device name. In the docs I found a lot of this notation {{ $labels.A.something }} or {{ $values.A.labels.whatever }} but no explanation what any of this means. Currently I have " {{ $labels }} " as my alert annotation just to see if something happens but it just stays as is and displays that text literally without replacing something.

So my question is.

What are labels?
Where are they defined?
Do they come from the query?
Are they the names I set in the query?
If I want to display the value and name in the alert message, what do I have to write?

Any help appreciated, if you need further info lmk <3

On your alert do you have it set for table or time series?

Had a similar issue with MySQL: