Order medication
The Order medication action places an order for one product at a Farmad pharmacy. The order is paid at pickup. Only users with administrator rights can run this action.
Give the product as a CNK code, a seven-digit code that identifies a product. Use the Search medication action to find the CNK code of a product. A CNK code that already appears in your order history can be ordered without a search.
This action does not support targets. You select the pharmacy through the Pharmacy field instead of choosing an area, device, entity, or label.
Ordering places a real order at your pharmacy. If the action reports that the order could not be confirmed, check the Mijn Farmad Apotheek app before calling it again. The order may have gone through, and calling again can order the same product twice.
Using this action from the user interface
If you prefer building automations and scripts visually, Home Assistant walks you through this action step by step. You pick what to target, tweak a few options, and save. No YAML knowledge required.
To order a product from an automation or a script:
- Go to Settings > Automations & scenes.
- Open an existing automation or script, or select Create automation > Create new automation.
- If you’re setting up a new automation, add a trigger in the When section. Scripts don’t need a trigger. They run when something else calls them.
- In the Then do section, select Add action.
- From the search box, search for and select Mijn Farmad Apotheek: Order medication.
- Under Product, enter the CNK code of the product to order.
- Set the Quantity, the number of packages to order.
- Under Pharmacy, enter the APB number of the pharmacy to order from, for example
343602. - Optionally, enter a Comment for the pharmacist.
- Optionally, in the Response variable field, enter a name to store the order details in, such as
order_result. - Select Save.
Options in the UI
The CNK code of the product to order. Use the Search medication action to find the CNK code of a product.
Using this action in YAML
If you work directly in YAML, or you want to know exactly what Home Assistant does under the hood, this section has the technical reference. It lists the field names you use in YAML, their types, and which ones are required. For how an automation or a script is built in YAML, refer to Automations in YAML and Scripts.
In YAML, refer to this action as mijn_farmad_apotheek.order_medication. A basic example looks like this:
action: mijn_farmad_apotheek.order_medication
data:
product: "3093242"
apb: "343602"
comment: "I will pick the order up on Saturday."
This orders one package, the default, of the product with CNK code 3093242 at the pharmacy with APB number 343602, with a comment for the pharmacist.
Options in YAML
YAML sometimes provides additional options for more complex use cases that are not available through the UI.
Response data
The action returns:
-
basket_id: The ID of the order at the pharmacy. -
description: The product name, in Dutch.
Good to know
- The action refuses to order when your draft basket at the pharmacy still holds products or a comment. If a previous order could not be confirmed, check the order history first and contact the pharmacy if its status remains unclear. Once you know the order was not placed, either submit the draft in the Mijn Farmad Apotheek app, or clear it and run the action again.
- Each order holds one product. To order several products, call the action once per product.
Try it yourself
Ready to test this? Open Settings > Tools > Actions, search for this action, fill in the fields, and select Perform action. You see what happens on your actual entitiesAn entity represents a sensor, actor, or function in Home Assistant. Entities are used to monitor physical properties or to control other entities. An entity is usually part of a device or a service. [Learn more] without writing a line of YAML.
More examples
Real scenarios where this action shows up in automations and scripts. Copy any example and adapt it to your setup. In the visual editor, select the UI options listed in the example or paste the YAML code.
You don’t need to edit YAML to use these examples. Copy a YAML snippet from this page, open the visual automation editor in Home Assistant, and press Ctrl+V (or Cmd+V on Mac). Home Assistant automatically converts the pasted YAML into the visual editor format, whether it’s a full automation, a single trigger, a condition, or an action.
Automation: order a product every month
This automation orders a known product on a monthly schedule, with a comment for the pharmacist. Create a calendar first, for example with the Local Calendar integration, and add an event that repeats on the first day of every month at 09:00.
-
Trigger: Calendar event started
-
Calendar: Medication orders (
calendar.medication_orders)
-
Calendar: Medication orders (
-
Action: Mijn Farmad Apotheek: Order medication
- Product: 3093242
- Quantity: 2
- Pharmacy: 343602
- Comment: For monthly pickup
YAML example for ordering a product every month
alias: "Order a product every month"
description: "Orders two packages of a known product every month."
triggers:
- trigger: calendar.event_started
target:
entity_id: calendar.medication_orders
actions:
- action: mijn_farmad_apotheek.order_medication
data:
product: "3093242"
quantity: 2
apb: "343602"
comment: "For monthly pickup"
Automation: order a product when the supply runs low
This automation orders a known product when a supply you track in Home Assistant runs low. Create a number helperA helper is a virtual entity you create inside Home Assistant. It is not backed by a physical device. Helpers store values, track state, or do calculations that your automations and dashboards need. [Learn more] first, for example input_number.paracetamol_boxes, and set it to the number of packages you have left. Lower the number every time you take a package. When it reaches zero, the automation orders a new package. A condition keeps the automation from ordering again after a restart while the supply still reads zero.
- Trigger: Numeric state: Paracetamol boxes below 1
- Condition: The supply changed from a number, not from unavailable
-
Action: Mijn Farmad Apotheek: Order medication
- Product: 3093242
- Pharmacy: 343602
YAML example for ordering when the supply runs low
alias: "Order a product when the supply runs low"
description: "Orders a new package when the supply reaches zero."
triggers:
- trigger: numeric_state
entity_id: input_number.paracetamol_boxes
below: 1
conditions:
- >-
{{ trigger.from_state is not none
and is_number(trigger.from_state.state) }}
actions:
- action: mijn_farmad_apotheek.order_medication
data:
product: "3093242"
apb: "343602"
Still stuck?
To test the action on its own, run it in the automation editor with Run action, and check the message that it shows. To see what the action did when the automation ran, open the trace of that run. For details, refer to Testing automations. For common problems and their solutions, refer to Troubleshooting automations.
If that doesn’t help, the Home Assistant community is quick to help: join Discord for real-time chat, post on the community forum with the action you’re calling and what you expected to happen, or share on our subreddit /r/homeassistant.
AI assistants like ChatGPT or Claude can also explain actions or suggest the right one when you describe what you want in plain language.
Related actions
Explore related actions:
- Search medication: Searches the catalog of a Farmad pharmacy by product name or CNK and returns up to 25 matching products.