I have a sensor that has an attribute with hyphens:
I want to parse that value into a template sensor to use as a trigger for an automation. But the code I usually use for doing this doesn’t work:
Do I have to to it another way?
I have a sensor that has an attribute with hyphens:
I want to parse that value into a template sensor to use as a trigger for an automation. But the code I usually use for doing this doesn’t work:
Do I have to to it another way?
{{ state_attr('sensor.unifi_gateway_firmware_upgradable', 'USG-PRO-4') }}
or
{{ states.sensor.unifi_gateway_firmware_upgradable.attributes['USG-PRO-4'] }}
state_attr('sensor.unifi_gateway_firmware_upgradable', 'USG-PRO-4')
EDIT: what he said
Verify that the entity_id is correct. We both went off your image. No idea if it’s correct.
Post a screenshot of the sensor as it appears in Developer tools > States.
In the screenshot you posted of the Template Editor, the one where you made a red mark, it is not presenting results the way it’s done by recent versions of Home Assistant. For example, here is how version 2021.01.1 presents results:
The value of the attribute called code_armed_required
is true
and it is presented in a gray box along with other information indicating which entity is monitored (alarm_control_panel.our_home). I see nothing like that in your screenshot … which is odd.
That’s weird indeed, I’m also on 2021.1.1
Does anyone know?
try freshing that page & clearing the cache (CTRL+F5) and verify that your system actually has the lastest update.
Done and done. Still no result. Other templates works fine and gives the expected output.
take screenshot of
{{ states.sensor.unifi_gateway_firmware_upgradable.attributes }}
in template editor.
and
{{ states.sensor.unifi_gateway_firmware_upgradable.attributes['USG-PRO-4'] }}
{{ state_attr('sensor.unifi_gateway_firmware_upgradable', 'USG-PRO-4') }}
The only explanation is that USG-PRO-4 has hidden characters in it. What integration is creating this entity?
This one.
Write an issue against it. The attribute should be usable. For the time being try this:
{% set key, value = states.sensor.unifi_gateway_firmware_upgradable.attributes.items() | list | first %}
{{ state_attr('sensor.unifi_gateway_firmware_upgradable', key) }}
Thank you, I will do that.