Consider these template sensors (examples are synthetic):
template:
- binary_sensor:
- name: testing_availability_from_attributes_3
state: on
attributes:
monitored_entity_id: 'sensor.processor_use'
some_attr: >-
{% set MONITORED_ENTITY_ID = state_attr('binary_sensor.testing_availability_from_attributes_3','monitored_entity_id') -%}
{{ MONITORED_ENTITY_ID is not none }}
- name: testing_availability_from_attributes_4
state: on
attributes:
monitored_entity_id: 'sensor.processor_use'
some_attr: &ref_availability_full_4 >-
{% set MONITORED_ENTITY_ID = state_attr('binary_sensor.testing_availability_from_attributes_4','monitored_entity_id') -%}
{{ MONITORED_ENTITY_ID is not none }}
availability: *ref_availability_full_4
- name: testing_availability_from_attributes_5
state: on
attributes:
monitored_entity_id: 'sensor.processor_use'
some_attr: &ref_availability_this >-
{{ this.attributes['monitored_entity_id'] is defined }}
- name: testing_availability_from_attributes_6
state: on
attributes:
monitored_entity_id: 'sensor.processor_use'
some_attr: *ref_availability_this
availability: *ref_availability_this
And these output:
Seems that I cannot use neither “this.attributes” nor “state_attr()” for the same entity.
In both cases the “availability” becomes “false”.
Is it an expected behaviour?
As I said, these are synthetic examples.
I may not refer to “state_attr()” or “this.attributes” in “availability” - instead I should use a “sensor.processor_use” explicitly for processing (like “if a state of that entity is not a number → then unavailable”).
I faced the issue when I tried to define “availability” using “this.attributes[…]” - for using this expression as a yaml anchor for other sensors.
It always gave “false” for “availability”, so I tested with “state_attr()” and got same results as well.