[SOLVED] How can I refer to a sensor value in an automation?

I want to generate a message on the Home Assistant home page whenever the numeric value of a sensor is at or below a certain value. However, I can’t figure out how to tell the component in automation.yaml which sensor in configuration.yaml to test.

I’ve created a sensor in configuration.yaml as follows:
sensor:

- platform: command_line
  name: 'Test Command'
  unit_of_measurement: days
  scan_interval: 43200 # 12 Hours
  command: 'mycommand'

I also created this entity in automations.yaml:

- alias: 'Test Notification'
  trigger:
    platform: numeric_state
    entity_id: ??????
    below: 10
  action:
    service: notify.notify
      message: 'Test message'

What entity ID do I use to refer to the value generated by the sensor?

I tried specifying an entity_id for the sensor (this was shown in numerous examples), but I got this warning from Home Assistant:

Your configuration contains extra keys that the platform does not support.
Please remove [entity_id].  (See /home/homeassistant/.homeassistant/configuration.yaml,
line 34).

Both with and without the entity_id attribute, the Check Configuration function says everything is okay. Apparently, however, the entity_id attribute is no longer used to identify sensors after v0.88.

I’ve searched the documentation and looked at a bunch of examples in the Cookbook, but I can’t find anything that answers my question.

My platform: I installed Home Assistant on an Odroid C2 running Armbian Stretch in a virtual environment using the instructions at https://www.home-assistant.io/docs/installation/raspberry-pi/. I’ve installed an SSL certificate following the instructions at https://www.home-assistant.io/docs/ecosystem/certificates/lets_encrypt/.

One other question: Is there any significant difference between using single quotes or double quotes in the configuration files?

I’ll be grateful for any advice.

If you look at the states page on your installation, you will find every entity in your system. From there you should be able to scroll to find it. Comparing to my configuration, it should be lowercase with spaces replaced with underscores (i.e. “sensor.test_command”).

No difference between single and double quotes. It is important if you have a template with multiple arguments on the same line.

"{{ is_state('domain.entity_id','on') }}"

Having a double quote around domain would end the argument as “{{ is_state(” and error.

1 Like

Ding!Ding!Ding!Ding!Ding!

Thank you, @walrus_parka! You win today’s cookie!

So, to sum up, the system creates entity ids based on the “friendly” name: attribute, and all we have to do is look up the id that HA assigned on the States page (under the “<>” icon).

And, indeed, the entity_id that HA assigned for my test was “test_command”. I’ve tested it, and the automation now works. I’m grateful for your help!

1 Like