Conditional Card String

So I implemented a custom weather sensor. Part of the weather component is a sensor.warning.

Currently we have a Special weather Statement in our area. I figures this was a great time to implement a conditional card with a weblink to the weather statement if the sensor returned a Special Weather Statement, Watch, or Warning.

I have the card setup, I know the sensor state right now is - SPECIAL WEATHER STATEMENT

My conditional card code is:

#Weather Warning Card
      - type: conditional
        conditions:
          - entity: sensor.ec_warning
            state: 'SPECIAL WEATHER STATEMENT'
        card:
          type: entities
          entities:
            - weblink.weather_alerts

So with this the card doesnā€™t show up. But if I set the state to be SPECIAL WEATHER STATEMENT using the Set State option on the dev-state page the card appears until the sensor is updated.
The kicker is Iā€™m getting SPECIAL WEATHER STATEMENT from the state column next to the sensor.ec_warning entry.

Iā€™m not sure why the card appears when I manually set it.

Oh, Iā€™ve also tried the state: with double quotes with no difference in the outcome.

Are you sure there arenā€™t any extra spaces, or tab characters, or something like that in the state? Did you try the following in the Template Editor:

{{ states('sensor.ec_warning') == 'SPECIAL WEATHER STATEMENT' }}

And maybe:

X{{ states('sensor.ec_warning') }}X

which would help show if there are extra spaces before or after.

1 Like

@pnbruckner Thanks for the tip! It looks like there was a lead and trailing space.
Weird as now the sensor is saying 'Wind Warning , Special Weather Statement ā€™ (without the ā€™ ')
Not sure why the Wind Warning has only a trailing space and the Special Weather Statement has Leading and trailing.

Anyways the card is now appearing, do you know if I can use wild cards for the condition?

I donā€™t know as much about the frontend in general, and Lovelace in particular, but according to the docs, no.

yah, I just tried a few and nothing worked, looks like itā€™s a yaml thing, seems short sighted on yamlā€™s end so Iā€™ll have to figure something out, there are 23 possible warnings that could be issued, I havenā€™t looks at watches yet, too many variables to handle with wild cards

Anyways thanks for your help!

Iā€™m not trying to dissuade you from getting your sensor alerts working but if you want a (at least for now) working drop in set up for US national weather service alerts there is always this:

that link is to the post that links to the latest working code on gist.

I donā€™t know if would be useful to read the whole thing but you might get something out of it.

That looks great, unfortunately I am not located in the USā€¦

Maybe a template binary sensor that looks at the alert state is not blank then binary on.
Conditional card looks at the binary sensor.

Temporarily I am using the state_not function. When there are no alerts the sensor state is ā€˜unknownā€™ I can use that and make the card appear for all alerts, not ideal but itā€™s something right now.

Ok, sorry for my bad assumption. :slightly_smiling_face:

No worries, may not help me but maybe someone else will see it and help them! :slight_smile: