Search medication

The Search medication action searches the product catalog of a Farmad pharmacy by product name or CNK code. It returns up to 25 products with price and stock, as response data you can use in the rest of your automation or script. For example, you can look up the CNK code of a product before ordering it with the Order medication action.

This action does not support targets. You select the pharmacy through the Pharmacy field instead of choosing an area, device, entity, or label.

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 search the catalog from an automation or a script:

  1. Go to Settings > Automations & scenes.
  2. Open an existing automation or script, or select Create automation > Create new automation.
  3. 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.
  4. In the Then do section, select Add action.
  5. From the search box, search for and select Mijn Farmad Apotheek: Search medication.
  6. Under Search term, enter the product name or CNK code to search for.
  7. Under Pharmacy, enter the APB number of the pharmacy to search in, for example 343602.
  8. In the Response variable field, enter a name to store the results in, such as search_result. This field is required for this action.
  9. Select Save.

Options in the UI

Search term (Required)

The product name or CNK code to search for.

Pharmacy (Required)

The APB number of the pharmacy to search in, for example 343602.

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.search_medication. A basic example looks like this:

ActionAn action makes Home Assistant do something, for example, turn on a light, send a notification, or activate a scene. Automations and scripts run a list of actions. [Learn more]
action: mijn_farmad_apotheek.search_medication
data:
  query: "paracetamol 500 mg"
  apb: "343602"
response_variable: search_result

This searches for paracetamol at the pharmacy with APB number 343602 and stores the matching products in search_result.

Options in YAML

YAML sometimes provides additional options for more complex use cases that are not available through the UI.

query string Required

The product name or CNK code to search for.

apb string Required

The APB number of the pharmacy to search in.

Response data

The action returns a products list with up to 25 products. Each product has these fields:

  • cnk: The CNK code of the product.
  • description: The product name, in Dutch.
  • brand: The brand of the product.
  • package_quantity: The quantity in the package, such as the number of tablets in a box, or null when unknown.
  • price: The sales price at the pharmacy, or null when unknown.
  • stock: The number of items in stock, or null when unknown.
  • is_on_prescription: Whether the product requires a prescription.

An example response:

products:
  - cnk: "3093242"
    description: "Paracetamol EG 500 mg 120 tabl."
    brand: "EG"
    package_quantity: 120
    price: 3.15
    stock: 25
    is_on_prescription: false

Good to know

  • The search matches product names. A full CNK code matches its own product.
  • Product names in the results are in Dutch.

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.

Tip

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: check the price and stock of a product

Each week, this automation looks up a product at your pharmacy and sends the price and the stock of the first match to a phone. When the search returns no product, or when the price or the stock is unknown, the message says so. It uses a schedule 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]: create the helper with a weekly rule first.

  • Trigger: Schedule block started
    • Target: Weekly price check (schedule.weekly_price_check)
  • Action: Mijn Farmad Apotheek: Search medication
    • Search term: paracetamol 500 mg
    • Pharmacy: 343602
    • Response variable: search_result
  • Action: Send a notification message
    • Target: My Device (notify.my_device)
YAML example for a weekly price and stock notification
AutomationAutomations in Home Assistant allow you to automatically respond to things that happen in and around your home. [Learn more]
alias: "Check the price and stock of a product"
description: "Sends the price and the stock of the first match to a phone."
triggers:
  - trigger: schedule.block_started
    target:
      entity_id: schedule.weekly_price_check
actions:
  - action: mijn_farmad_apotheek.search_medication
    data:
      query: "paracetamol 500 mg"
      apb: "343602"
    response_variable: search_result
  - action: notify.send_message
    target:
      entity_id: notify.my_device
    data:
      message: >-
        {% if search_result.products %}
        {% set product = search_result.products[0] %}
        {{ product.description }} costs
        {{ product.price if product.price is not none else 'an unknown price' }}.
        Stock:
        {{ product.stock if product.stock is not none else 'unknown' }}.
        {% else %}
        No product found.
        {% endif %}

Automation: get a daily message when a product is in stock

Each day, this automation looks up a product at your pharmacy by its CNK code. When the product is in stock, it sends a message to a phone. The message repeats every day while the product stays in stock.

  • Trigger: Time: 09:00
  • Action: Mijn Farmad Apotheek: Search medication
    • Search term: 3093242
    • Pharmacy: 343602
    • Response variable: search_result
  • Action: If-then
    • If: The product has more than zero items in stock
    • Then: Send a notification message
      • Target: My Device (notify.my_device)
YAML example for a daily in-stock message
AutomationAutomations in Home Assistant allow you to automatically respond to things that happen in and around your home. [Learn more]
alias: "Get a message when a product is in stock"
description: "Sends a message when a product is in stock."
triggers:
  - trigger: time
    at: "09:00:00"
actions:
  - action: mijn_farmad_apotheek.search_medication
    data:
      query: "3093242"
      apb: "343602"
    response_variable: search_result
  - if:
      - >-
        {{ search_result.products | length > 0
        and search_result.products[0].stock | default(0, true) > 0 }}
    then:
      - action: notify.send_message
        target:
          entity_id: notify.my_device
        data:
          message: >-
            {{ search_result.products[0].description }} is in stock
            at your pharmacy.

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.

Tip

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:

  • Order medication: Places an order for one product at a Farmad pharmacy. The product is paid at pickup.