Skip to content
Rigel docs
Open Rigel

Units

Amounts are a number and a unit from one fixed list, and the list only grows.

Sending an amount#

Commands take an amount as two fields: a number and a unit ID from the table below. The number is more than 0 and at most 1,000,000. Send the ID exactly as the table spells it. tbsp works, and tablespoon and Tbsp are validation errors.

Leave the unit out, or send null, for a plain count of the things themselves: 3 eggs, 4 apples. Use an item unit when you count something other than the thing: 2 cloves of garlic, 1 can of black beans, 3 rolls of paper towels.

The field names follow the app. A recipe ingredient has quantity, quantity_max for the top of a range, and unit. A shopping list item has quantity and unit. An inventory item has quantity and quantity_unit, and the size of one package as size_value and size_unit. Other fields called unit, such as the unit of a maintenance task's interval (day, week, month or year), are not from this list.

Shell
curl -X POST https://rigel.house/api/v1/households/hh_01JC8Q4W2N7XK5R3VYTZ9D6HBE/commands/recipes.ingredient.add \
  -H "Cookie: rigel_session=$RIGEL_SESSION" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: cmd_01JC9A3M5N6P3VZ8KW1TXQ4DRG" \
  -d '{
    "recipe_id": "rcp_01JC9C1H8W3ZT6QXN5KDV2RMYA",
    "name": "garlic",
    "quantity": 2,
    "quantity_max": 3,
    "unit": "clove",
    "preparation": "minced"
  }'

See recipes.ingredient.add for the rest of that command, and IDs and formats for how amounts sit beside other values.

The unit list#

There are 31 units. Sizes are in grams for mass and milliliters for volume. Volume sizes are US customary, so a cup is 236.5882365 ml. A recipe written in metric cups is recorded in milliliters.

IDNameShown asKindSize
mgmilligram, milligramsmgMass0.001 g
ggram, gramsgMass1 g
kgkilogram, kilogramskgMass1000 g
ozounce, ouncesozMass28.349523125 g
lbpound, poundslbMass453.59237 g
mlmilliliter, millilitersmlVolume1 ml
lliter, litersLVolume1000 ml
tspteaspoon, teaspoonstspVolume4.92892159375 ml
tbsptablespoon, tablespoonstbspVolume14.78676478125 ml
fl_ozfluid ounce, fluid ouncesfl ozVolume29.5735295625 ml
cupcup, cupsas a wordVolume236.5882365 ml
pintpint, pintsas a wordVolume473.176473 ml
quartquart, quartsas a wordVolume946.352946 ml
gallongallon, gallonsas a wordVolume3785.411784 ml
pinchpinch, pinchesas a wordItemnone
dashdash, dashesas a wordItemnone
cloveclove, clovesas a wordItemnone
sliceslice, slicesas a wordItemnone
stickstick, sticksas a wordItemnone
sprigsprig, sprigsas a wordItemnone
headhead, headsas a wordItemnone
bunchbunch, bunchesas a wordItemnone
stalkstalk, stalksas a wordItemnone
cancan, cansas a wordItemnone
jarjar, jarsas a wordItemnone
bottlebottle, bottlesas a wordItemnone
boxbox, boxesas a wordItemnone
bagbag, bagsas a wordItemnone
packagepackage, packagesas a wordItemnone
cartoncarton, cartonsas a wordItemnone
rollroll, rollsas a wordItemnone

What converts to what#

Mass converts to mass and volume converts to volume. Mass and volume don't convert to each other, because that depends on what is being measured: a cup of flour and a cup of honey weigh different amounts. An item unit converts only to itself, and a plain count converts to nothing.

To convert, multiply by the source unit's size, divide by the target's, and round to 6 decimal places. Rounding at 6 places gives the same result on every platform and no floating-point noise.

ConvertResult
1 cup to tbsp16 tbsp
2 tbsp to ml29.57353 ml
500 g to oz17.636981 oz
2 lb to kg0.907185 kg
1 g to mldoes not convert
2 cloves to gdoes not convert
1 can to jardoes not convert

Rigel converts when it has to, such as when it adds two amounts of the same ingredient. The sum is in the first amount's unit, so 1 cup plus 2 tbsp is 1.125 cup, shown as 1⅛ cups. Amounts that don't convert stay separate.

Showing an amount to people#

Some queries return an amount already written for people, such as the amount on each ingredient from recipes.recipe.get. Use it as it is. If you format your own, follow these rules, which are the ones Rigel uses. Text is English only.

  • Units with a short form are never pluralized: 2 tbsp, 2 lb.
  • Units shown as words are plural unless the amount is exactly 1 or a fraction below 1: ½ cup, 1½ cups, 1 can, 3 cans.
  • A range uses an en dash and is plural: 2–3 cloves.
  • Metric amounts are decimals with at most 2 places and no trailing zeros: 1.5 kg, 0.25 L.
  • Everything else uses a fraction when the amount is within 0.02 of an eighth or a third, and otherwise a decimal with at most 2 places.
QuantityUnitShown
2tbsp2 tbsp
500g500 g
0.25l0.25 L
1.5cup1½ cups
1.3333cup1⅓ cups
2 to 3clove2–3 cloves
1can1 can
3none3

The list only grows#

A unit's ID is never renamed or removed, because stored rows and queued commands use it. New units are added when an app needs one. So a client should treat the list as open: if you read a unit ID you don't know, show the ID rather than failing, and don't copy this table into your code when you can read it from the reference. Every field that takes a unit lists the current IDs.

Rigel is in early access, and sign-up is by invitation. Open Rigel