Comparing Variables in a Template Sensor

Hi all, I’m trying to create a template sensor that will give me the lowest ink level reading of my printer, allowing me to use it to create an alert when the printer will need a new ink cartridge soon.

For the purpose of this sensor, I don’t care which ink cartridge it is (I have a dashboard I can go to look for that), I just want to know that it needs investigating.

I have four variables that monitor the different ink levels (I don’t use the printer’s sensors, as they wouldn’t be available when its turned off):

var.printer_ink_black
var.printer_ink_magenta
var.printer_ink_cyan
var.printer_ink_yellow

These contain values between 0 -100, stating the current % level of ink in each cartridge.

What I want to create is a sensor that contains the value of the lowest cartridge…
eg, if:

var.printer_ink_black = 36
var.printer_ink_magenta = 87
var.printer_ink_cyan = 25
var.printer_ink_yellow = 45

Then this sensor would have a value of 25

However, I’m really struggling to work out what logic and syntax to use to create a value_template: configuration for the sensor.

Does anyone have any ideas? As I’ve ended up confusing myself trying to work this one out!

Thanks!

{{ [states('var.printer_ink_black)|int,
    states('var.printer_ink_magenta)|int,
    states('var.printer_ink_cyan)|int,
    states('var.printer_ink_yellow)|int]|min }}

Thanks @pnbruckner! I would have never have thought of this method, though makes so much sense.

The below is working perfectly for me:

      printer_ink_level:
        friendly_name: "Printer Ink Level"
        icon_template: mdi:printer
        value_template: >-
          {{ [states('var.printer_ink_black')|int,
          states('var.printer_ink_magenta')|int,
          states('var.printer_ink_cyan')|int,
          states('var.printer_ink_yellow')|int]|min }}

FWIW, I believe this should also work:

{{ states.var|selectattr('object_id','match','printer_ink_')|map(attribute='state')|map('int')|min }}

That’s great, both good options. Thanks!