How to create a template sensor that reads an attribute from a sensor?


i am using an integration that reports weather alerts. It gives the details to the alert in its attributes. I want to create a template sensor that reads the attributes…that way i can display it a number of ways…i have tried several things, but nothing is working…im sure it is very simple…still kinda new with HA… the sensor is called ‘sensor.wichita’ and the attribute is called ‘alerts’… can someone help me whip this up?..thank you :slight_smile:

  - sensor:
      - name: "weatheralerts.wichita"
       ???-not sure what to put here
       ???-not sure what to be here
        icon: "mdi:alert-circle-outline" 

Weatheralerts integration repository if you want to check it out :slight_smile:

  - sensor:
      - name: "weatheralerts.wichita"
        state: "{{ state_attr('sensor.wichita', 'alerts') }}
        icon: "mdi:alert-circle-outline" 
1 Like

awesome :)…

      - name: "weatheralerts.wichita"
        state: "{{ state_attr('sensor.wichita', 'alerts') }}"
        icon: "mdi:alert-circle-outline" 

it made a sensor… but it is just returning ‘unknown’…shouldn’t it display the attribute text?

sensor.wichita is reporting and the attribute is called ‘alerts’:

That depends…

states are only limited to 255 characters so if the text is longer than that you will probably get the “unknown” you are seeing.

Maybe…or it could be something unrelated if the alerts text is less than 255 characters.

right on… i bet that is the deal…

is there a way to capture that attribute text and display it? I have also tried card-mod… i can adjust the font size, weight, color, padding… but not the text-align is not working… if i could align it center or left i could increase the font size…

Sorry I have no idea.

I don’t really use card-mod for anything that doesn’t just need it installed as a requirement for a custom plug-in. I’ve never done any coding with it myself.

Hey, this is not really an answer to your question but, since you are working on a template warnings card I can suggest a better solution. I’m the author of MeteoalarmCard which supports weatheralerts integration. After downloading it you can configure it like so:

type: custom:meteoalarm-card
integration: weatheralerts
  - entity: weatheralerts.wichita

You can read more about this project here: