Source: https://spooly.eu/en/docs/home-assistant/examples

# Examples and use cases

What you can do with Spooly in Home Assistant, with examples to copy. Replace the entities with your own.

## Use cases

- A message on your phone when a spool runs low.
- A message as soon as maintenance on a printer is due, with the buttons Done and Remind me in 7 days.
- A scale that writes the weight of a spool to Spooly.
- A card on the wall tablet that reports maintenance as done.
- The remaining weight as a history graph on the dashboard.

## Spool almost empty

As soon as Spooly reports a spool as low, a message arrives with its name and remaining weight. The automation covers every spool, new ones included, so you do not list any of them.

Replace notify.mobile_app_your_phone with the service of your phone from the Home Assistant app.

YAML:

```
alias: Spool almost empty
triggers:
  - trigger: event
    event_type: state_changed
conditions:
  - condition: template
    value_template: >-
      {% set e = trigger.event.data %}
      {{ e.entity_id.startswith('binary_sensor.')
         and e.entity_id in integration_entities('spooly')
         and e.old_state is not none and e.old_state.state == 'off'
         and e.new_state is not none and e.new_state.state == 'on' }}
actions:
  - variables:
      weight: "{{ device_entities(device_id(trigger.event.data.entity_id)) | select('match', 'sensor') | first }}"
  - action: notify.mobile_app_your_phone
    data:
      title: Spool almost empty
      message: "{{ device_attr(trigger.event.data.entity_id, 'name') }}, remaining {{ states(weight) | float(0) | round(0) | int }} g"
```

## Maintenance due

When maintenance falls due, a message arrives with two buttons. Done marks the task as done in Spooly, Remind me in 7 days postpones it by a week. The Home Assistant app shows the buttons on iPhone and Android.

The second automation carries out what you tap and needs the permission to change. If you tap Done by mistake, undo it in Spooly under Settings, Devices & keys.

YAML:

```
alias: Maintenance due
triggers:
  - trigger: event
    event_type: state_changed
conditions:
  - condition: template
    value_template: >-
      {% set e = trigger.event.data %}
      {{ e.entity_id.startswith('sensor.')
         and e.entity_id in integration_entities('spooly')
         and e.old_state is not none and e.old_state.state in ['ok', 'soon']
         and e.new_state is not none and e.new_state.state == 'due' }}
actions:
  - action: notify.mobile_app_your_phone
    data:
      title: Maintenance due
      message: "{{ trigger.event.data.new_state.name }}"
      data:
        actions:
          - action: "SPOOLY_DONE {{ trigger.event.data.entity_id }}"
            title: Done
            authenticationRequired: true
          - action: "SPOOLY_SNOOZE {{ trigger.event.data.entity_id }}"
            title: Remind me in 7 days
```

YAML:

```
alias: Answer to maintenance
triggers:
  - trigger: event
    event_type: mobile_app_notification_action
conditions:
  - condition: template
    value_template: "{{ trigger.event.data.action is string and trigger.event.data.action.startswith('SPOOLY_') }}"
actions:
  - variables:
      task: "{{ trigger.event.data.action.split(' ')[1] }}"
  - if:
      - condition: template
        value_template: "{{ trigger.event.data.action.startswith('SPOOLY_DONE ') }}"
    then:
      - action: spooly.complete_maintenance
        data:
          task: "{{ task }}"
    else:
      - action: spooly.snooze_maintenance
        data:
          task: "{{ task }}"
          days: 7
```

## Scale reports gross weight

Spooly does not read a scale itself, Home Assistant has to know it already. The automation waits five seconds until the weight is steady, and applies to one fixed spool.

It needs the permission to change and a known tare. Spooly allows 60 changes a minute per connection, so do not let it write on every reading.

YAML:

```
alias: Scale reports gross weight
triggers:
  - trigger: state
    entity_id: sensor.scale_weight
    for: "00:00:05"
conditions:
  - condition: numeric_state
    entity_id: sensor.scale_weight
    above: 100
actions:
  - action: spooly.set_weight
    data:
      device_id: 9f2c4e7a1b3d5f60718293a4b5c6d7e8
      gross_grams: "{{ states('sensor.scale_weight') | float }}"
```

## Card with confirmation

There is deliberately no ready-made button per task, so nothing is marked as done by accident. You build a card with a confirmation like this.

YAML:

```
type: button
name: Nozzle replaced
entity: sensor.x1_carbon_von_tobi_nozzle_0_4_mm
tap_action:
  action: perform-action
  perform_action: spooly.complete_maintenance
  data:
    task: sensor.x1_carbon_von_tobi_nozzle_0_4_mm
    action: replace
  confirmation:
    text: Really report the maintenance as done?
```

## Remaining weight as a history graph

Shows how the remaining weight of a spool dropped over the last week.

YAML:

```
type: history-graph
title: Remaining weight
hours_to_show: 168
entities:
  - sensor.1_jade_white_remaining_weight
```
