klogg
(Klogg)
October 5, 2019, 9:10am
1
I’d like to use the type: conditional
in the picture-elements
card to display (or not) an element based on whether a persistent_notification
exists.
However, despite being able to test for unknown
in the States page,
it doesn’t work in the conditional card, and this,
- type: conditional
conditions:
- entity: persistent_notification.weather_warning
state_not: 'unknown'
elements:
- type: image
image: /local/panel/weather_warning.png
will display the image even if the notification does not exist.
Is there a way to make this work as intended?
klogg
(Klogg)
October 5, 2019, 10:29am
3
Thanks but neither of those worked.
(And for what it’s worth nor did 'none'
or None
)
finity
October 6, 2019, 3:57am
4
I just put the following into my config and it seemed to be working correctly for me:
- type: conditional
conditions:
- entity: persistent_notification.weather_warning
state: 'unknown'
card:
type: entities
entities:
- device_tracker.life360_me
I can change the condition back and forth from “state:” to “state_not:” and the card changes from not displayed to being displayed. And I don’t have an existing “persistent_notification.weather_warning” entity right now either.
I’m not using a picture elements card but the basic functionality should work either way.
klogg
(Klogg)
October 6, 2019, 8:02pm
5
hhmmm, strange. I ended up creating a sensor to get around this but I’ll take another look…
EDIT: Nope… it doesn’t work for me. Maybe something to do with it being a picture-entity
card?
This always shows the image
, weather_warning.png
.
- type: horizontal-stack
cards:
- type: picture-elements
image: /local/panel/main_section.svg
elements:
#=== Weather Warning Icon
- type: conditional
conditions:
- entity: persistent_notification.weather_warning
state_not: 'unknown'
elements:
- type: image
image: /local/panel/weather_warning.png
tap_action:
action: call-service
service: browser_mod.command
service_data:
command: popup
auto_close: true
card:
type: markdown
title: ' '
content: >
{% if states('persistent_notification.weather_warning') != 'unknown' %}
{% set colour = state_attr('persistent_notification.weather_warning', 'message' ).split('##')[1] | trim %}
{% set message = state_attr('persistent_notification.weather_warning', 'message' ).split('</font>')[1] | trim %}
## <font color={{ colour }}> {{ colour }}</font> Weather Warning ##
{{ message }}
{% endif %}
finity
October 7, 2019, 1:38am
6
Agin, i’m not sure why your config isn’t working.
I put you exact code from above into my lovelace (I only changed the image file names/location) and it still works fine for me. If I change the state from state_not to state then the image disappears.
But one thing that does seem strange is I would have expected state_not to not display the image since I don’t have an existing “persistent_notification.weather_warning”. That seems backwards to me.
Have you tried switching the state_not to state and seeing if the image stops being displayed?
klogg
(Klogg)
October 7, 2019, 7:47am
7
Well, well, well.
Yes that works. Although technically it doesn’t because as you say it is completely round the wrong way…
I’ll need to wait for (or create) a persitant notification to check it works (wrongly ) when one exists but
thanks for spotting that!