How to use sensor entity attributes in widget definition

Edit 2:

Well…looking closer at widget definitions I realize sensor widgets don’t have icons. So, I believe the better way to solve my problem is going to be to find/build a sensor-with-icon widget type, and I imagine i’ll be solving these attribute-reference problems through different means. Still curious if what I was trying to do with at least the friendly name would work, but it’s now less important.

#

Like what seem like half the questions here I’m currently working on a weather app, but I think this question is simple, I just can’t seem to get to the bottom of it…

Very simply, I have sensors that are working in home assistant with a value, icon, and friendly_name.

I want to use these same values in hadashboard.

So, for instance, a sensor named sensor.forecast_4 has the attributes:

friendly_name: Saturday
icon: mdi:weather-pouring

I believe I should be able to use these attributes in my hadashboard widget definition like so:

forecast_4:
    title: {{ states.sensor.forecast_4.attributes.friendly_name }}
    widget_type: sensor
    entity: sensor.forecast_4
    icon: {{ states.sensor.forecast_4.attributes.icon|replace(':','-') }}

I’ve tried lots of variations
{{ states.sensor.forecast_4.attributes.friendly_name }}
“{{ states.sensor.forecast_4.attributes.friendly_name }}”
{{ sensor.forecast_4.attributes.friendly_name }}
{{ states.sensor.forecast_4.friendly_name }}

And I’m not positive about that |replace(’:’,’-’) to use the mdi icon in the hadashboard format, but just one problem at a time. Most of these variations are throwing:

found unhashable key while constructing a mapping

Is this something I should be able to do?

Thank you!

edit: typo

no you cant use templates in a dashboard.
so you need to give the title yourself.

you could use the icons from homeassistant
you just need this in your dashboard

global_parameters:
    use_hass_icon: 1

but as you see yourselve there are no icons for a sensor widget.
so because you probably want to see an icon change based on the state you want to use the “icon widget”
http://appdaemon.readthedocs.io/en/latest/DASHBOARD_CREATION.html#icon
with that you can have an icon for every state.

1 Like