Home Assistant has always silently ignored non-existent entities in automations and scripts. This behavior has allowed one to create automations containing so-called “dummy entities” that are quietly ignored by Home Assistant.
For example, this data_template returns lock.door only if it’s unlocked otherwise it supplies the name of a non-existent entity called lock.nothing.
service: lock.lock
data_template:
entity_id: >
{% if is_state('lock.door', 'unlocked') %}
lock.door
{% else %}
lock.nothing
{% end if }
Similar techniques have been used to call non-existent switches and scripts. The practice is fairly common and usually done in order to simplify the automation. The example I’ve shown could be rewritten using a condition but there are other situations where it’s not so simple.
I’ve offered the use of “dummy entities” as a solution in several posts:
In the last linked post (dated August 2019) I wrote:
Home Assistant will not (currently) complain about non-existent entities.
My inclusion of the word “currently” was prescient because that’s about to change. Be advised that the following PR will make Home Assistant report non-existent entities (initially as a warning):
If you don’t want warning messages in your system log, you may need to revise automations or scripts that use non-existent entities.
UPDATE
The PR was modified and will now permit the use of none to represent a valid “dummy entity”.
service: lock.lock
data_template:
entity_id: >
{% if is_state('lock.door', 'unlocked') %}
lock.door
{% else %}
none
{% end if }
i dont even think there is a service to set_state.
and AD already reports when you use services for none existing entities (or at least HA complains if i remember correct)
This one annoys me as I’ve been using this a lot in my scripts. A much better “solution” to this (imho) would be to ONLY include the warnings during a manual call to homeassistant.check_config and maybe at startup. Another way to handle this would be to have a config setting that turns this off (this would be my preference).
I’ll propose something that I fully admit sounds like a kludge but it’s a simple way to avoid warning messages without re-writing automations and scripts that use “dummy entities”.
Formalize dummy entities.
Allow each domain to have one valid dummy entity called null (or some other name the community prefers).
light.null
switch.null
script.null
cover.null
etc
If Home Assistant encounters an automation using lock.null it will behave the way it always has with a non-existent entity: it silently ignores it.
Can you elaborate on how it works? I added this to my lights.yaml file:
- name: 'null'
platform: demo
then ran Config Check with no errors, restarted, and no new entity appears in the States page. I reviewed the system log and the startup messages say nothing about loading the demo platform.
Obviously I’ve misunderstood how this works. How does one use the demo platform?
demo platform will create demo entities. I don’t believe name is an option. ‘light’ demo creates 3 lights:
light.light_1 Bed Light
light.light_2 Ceiling Lights
light.light_3 Kitchen Lights
Each have different supporting features. I created a custom_component of demo where I changed the names to what I want instead of stepping on the toes of my current libraries.
The created entities might have different entity_id’s that light.light_1.
EDIT:
Maybe later tonight i’ll make a custom null entity component and add it to HACS that does this with single features instead of these crazy demo ones.
EDIT 2:
These entities are really good for the testing that you always do btw… It’s what I use them for.
Anyone who feels strongly about this should probably comment on the PR. That’s the whole point of the PR and why it’s named “RFC: …” (i.e., Request For Comment.)
FWIW, I’ve suggested a new keyword, similar to all, that means “no entity.” But that’s just one idea.
By all means, add a comment to the PR. balloob is asking for input. Now’s your chance.
Yes, that’s the idea, to add it to the central service processing method. The only problem with none is that is a YAML keyword, which results in Python None instead of a string 'none', but I suspect that would be easy enough to deal with in the schema.
I think none is ok, and is the most appropriate. Yes, it’s a YAML keyword, and YAML will convert it to Python’s None, but again, I think that’s an implementation detail that is not difficult to deal with. So either of these could be made to be acceptable and equivalent:
entity_id: none
entity_id: 'none'
Remember, templates always return strings anyway, so in general this wouldn’t even be a problem. I doubt anyone would write:
I understand where you are going with this but how will this (the warning of ‘other’ non-existent entities) interfere with : -
a) people here helping on the forum ? (I write all sorts of sruff into a package file to help with solutions that don’t actually exist on my system, just to check the yaml and basic HA Syntax).
b) it’s also fairly common (due to the package concept but also possible without) to (say) write code for bedroom 01, test it decide that’s okay, then say okay I’ll copy this for bedroom02 and… BUT … I’ve not installed the devices yet
I think I agree with @code-in-progress to have a config setting to enable / disable
What have I missed ?
I’m not blaming Phil. I’m trying to gain more understanding of consequences and possible options before I weigh in on github with an irrelevant comment