Entity ID insert into notification via UI/Lovelace?

I am attempting to setup an alert where when my printer toner is low, I’ll get a notification from HASS. I dont have experience in YAML, but everything I have found here for similar things I am getting an error when I attempt to use the same code from others in my notify block. See below:

service: notify.notify
metadata: {}
data:
  message: {{ trigger.to_state.attributes.friendly_name }} is at {{ trigger.to_state.state }}

When I do a run on this I get “Error rendering data template: UndefinedError: ‘trigger’ is undefined”. The trigger is setup as this when I view in yaml:

type: value
platform: device
device_id: b94dcb1ef35ac8982ca6500dd01c6ef8
entity_id: 5591abb46ca33f60a5be4fb3e307c9f2
domain: sensor
below: 10

There are 4 unique triggers on this (one for each entity on the printer). Ideally I’d like to see something like “Black toner is low” when the notification triggers.

Thanks!

I assume you are running the automation manually? This won’t work, as in this case there is no trigger. :slight_smile:

In general, you should avoid device_ids, please take a look here why:

If you have further problems, please post the complete code of that automation so we can see, what’s going on. :slight_smile:

That automations and scripts callout was a great starting point. This ended up getting me fixed. If anyone else stumbles on this in the future; here’s what worked:

alias: Low toner alert
description: ""
trigger:
  - platform: state
    entity_id:
      - sensor.hp_color_laserjet_m452dn_cyan_cartridge_hp_cf411a
      - sensor.hp_color_laserjet_m452dn_black_cartridge_hp_cf410a
      - sensor.hp_color_laserjet_m452dn_magenta_cartridge_hp_cf413a
      - sensor.hp_color_laserjet_m452dn_yellow_cartridge_hp_cf412a
condition:
  - condition: or
    conditions:
      - condition: numeric_state
        entity_id: sensor.hp_color_laserjet_m452dn_cyan_cartridge_hp_cf411a
        below: 10
      - condition: numeric_state
        entity_id: sensor.hp_color_laserjet_m452dn_magenta_cartridge_hp_cf413a
        below: 10
      - condition: numeric_state
        entity_id: sensor.hp_color_laserjet_m452dn_black_cartridge_hp_cf410a
        below: 10
      - condition: numeric_state
        entity_id: sensor.hp_color_laserjet_m452dn_yellow_cartridge_hp_cf412a
        below: 10
action:
  - service: notify.notify
    metadata: {}
    data:
      message: "{{ trigger.to_state.attributes.friendly_name }} is low"
mode: single

It looked like this in lovelace. Note that the message must be done via YAML apparently…


Which brings me back to the original question. Are we able to insert triggering entity ID’s into messages via lovelace or is that exclusively a YAML thing (for now)?

Thanks!

That should totally work if created in the UI. You could confirm that by migrating the automation back to the UI.

I think we are mixing notations here… :laughing:

TL;DR
No, it’s not possible to setup the message without using YAML as a language.

Lovelace is how the frontend in HA is called, aka your dashboards. YAML is a language, to describe things in a human readable way (sort of). UI is where you setup your automations, scripts, helpers and all these things. Let’s call it the backend.

In the backend you have two ways of writing things, one in YAML-mode, and one in UI-mode. Sometimes things aren’t available in the UI, so you have to add some YAML code in a field in the UI, in this case this is called “code editor” (that’s what the OP named YAML) versus the “visual editor” that people normally use in the UI. You can see the “code editor” part in the picture from the OP.

Normally, if people talk about YAML, it means that you have to write the complete automation (or whatever) in YAML, not only one part of it, to paste it into the code editor in the UI.

I know that the wording is sometimes complicated in HA. :slight_smile:

So, nope, there is no other way than using YAML in the code editor, and I doubt, that these template things will get some kind of visual editor, sorry to say! :slight_smile: