Customizing message for printer ink automation

My printer has 6 inks and I want the ink level message to tell me which ink is low. If the message entry is just text like “Ink level low” the automation runs fine. But I cannot find how to get the friendly name of the ink for the message. I’ve tried many combinations I’ve found on the forum but I can’t get any to work. In the example pasted below the trace error is “Error: Error rendering data template: UndefinedError: ‘dict object’ has no attribute ‘to_state’”. Thanks for your help!

- id: '1677521074352'
  alias: Epson ink level
  description: ''
  trigger:
  - platform: numeric_state
    entity_id: sensor.epson_xp_960_series_black_ink
    below: 20
  condition: []
  action:
  - service: persistent_notification.create
    data:
      message: ' {{ trigger.to_state.attributes.friendly_name }} '
  mode: single

How are you testing this automation?

If the testing procedure does anything other than allowing the Numeric State Trigger to trigger, then the trigger variable will be undefined.

From the Automations list I click the 3 … and select the Run in order to test it. So you’re saying this won’t work and I would have to wait for it to trigger on its own?

That won’t work.

Reference: Testing your automation

There’s nothing wrong with your automation. The problem is your testing procedure is incorrect. The Run command simply executes the automation’s actions (and because it doesn’t actually trigger the automation, the trigger variable is undefined).

  1. Go to Developer Tools > States
  2. Click on sensor.epson_xp_960_series_black_ink
  3. The selected sensor should now appear at the top of the page in a form.
  4. If the sensor’s current value is above 20, set its State to a value below 20 then click the Set State button.
  5. This is sufficient to trigger your automation.
  6. If the sensor’s current value is already below 20, set its State to a value above 20 and click the Set State button. Then set it to a value below 20 and click the Set State button.

After you are finished testing, set the sensor’s state value back to its original value or wait until its integration updates it with the latest value (the amount of time that may require depends on how the sensor’s integration operates).

1 Like

Thank you much for teaching me to fish. I found a rather cryptic version of this on the forum but didn’t understand it. All is well now!

1 Like