Printer Low Ink Notification Help

I am getting an error with the message portion of the code. Not sure if my formatting is not correct or what.

alias: Ink Alert
description: ''
trigger:
  - platform: numeric_state
    entity_id:
      - sensor.hp_envy_5660_series_tri_color_ink
      - sensor.hp_envy_5660_series_black_ink
    below: '20'
condition:
action:
  - service: notify.mobile_app_jeremys_iphone
    message: "{{ trigger.to_state.attributes.friendly_name }} is at {{ trigger.to_state.state }}"
mode: single
ERROR = Message malformed: extra keys not allowed @ data['action'][0]['message']
action:
  - service: notify.mobile_app_jeremys_iphone
    data:
      message: "{{ trigger.to_state.attributes.friendly_name }} is at {{ trigger.to_state.state }}"
mode: single
1 Like

Updated and get the following error:

Error rendering data template: UndefinedError: 'dict object' has no attribute 'to_state

That’s out of my knowledge capacity, maybe someone other can help :wink:

1 Like

I could reproduce the “to_state” error and resolved it using the entity_id instead. like this:

   message: >-
        {{ state_attr('trigger.entity_id','friendly_name')}} is at {{
        states('trigger.entity_id') }}

But I am not sure what output you receive when you have two entities defined as entity_id
Hopefully it only takes the entity that did actually trigger the automation having its value less than 20.

Try it and let med know what you observe :slight_smile:
’

1 Like

I appreciate the help! I think we are getting there. Not throwing any errors, but all I get when I run the automation is “None is at unknown” (on my phone)

alias: Ink Alert
description: ''
trigger:
  - platform: numeric_state
    entity_id:
      - sensor.hp_envy_5660_series_tri_color_ink
      - sensor.hp_envy_5660_series_black_ink
    below: '20'
condition: []
action:
  - service: notify.mobile_app_jeremys_iphone
    data:
      message: >-
        {{ state_attr('trigger.entity_id','friendly_name')}} is at {{
        states('trigger.entity_id') }}
mode: single

I tried commenting out one of the entity_id’s and made sure the ink level was below threshold under “States”

The first suggestion looked correct the to_state error is because you are manually triggering it. Use dev tools states to temporarily change the state to a value that would trigger and it should work … it’s looking for the entity that changed state… and none did when click run actions

1 Like

Yep, right you are. Thanks, everyone!

2 Likes

Thanks for this, it helped me implement a working autmation, but I have a question: I got a notification message every few minutes since the ink goes below a threshold, while I tought the mode: single would send it only once. Are you getting multiple notification every few minutes with this as well?