Hello everyone, I am new to the community. Please tell me if I create the post in a incorrect section/ missing anything/ any duplications. Thanks.
Recently I have created a Notice section in my dashboard. I would like to extend this section easily in the future, that I don’t need to have duplicated logic in the dashboard and the virtual sensors, etc. Also I want to dynamically show the notice cards only when certain conditions are fulfilled.
I did a tiny CSS hack for hiding the title when there is no siblings. This pseudo selector :has() is fairly new and some browser might not support. Please confirm your usage before using it.
/* It hides the mushroom-title-card if no non-hidden siblings.
*
* ~ hui-conditional-card:not([style*="display: none"])
* => any siblings who are not hidden
*
* :not(:has(~ hui-conditional-card:not([style*="display: none"])))
* => don't have any sibling who are not hidden
*/
mushroom-title-card:not(:has(~ hui-conditional-card:not([style*="display: none"]))) {
display: none;
}
Thanks for replying. I didn’t mean the built-in persistent notifications of Home Assistant, but some cards on the dashboard which “notify” me when certain conditions is fulfilled. They are basically the built-in conditional card.
Notifications or notices are one underestimated feature of HA.
@ccpk1 did something similar, I use it as the basis for the system I implemented for myself.
Take a look here, maybe you can find some inspiration for your own implementation.
One thing I’d note though: I wouldn’t work with conditional cards in the frontend, rather with auto-entities. That moves the “logic” into the backend, and you can use this logic in all places you want. Eg. in your case, you have the conditional logic in a frontend card. If you want that code shown in another place, you have to duplicate the logic.
Yes!! I wanted to prevent duplicated codes, so I hack the css to hide the title XD. Thanks for the recommendations. I will have a look of auto-entities.
If you want to have less duplication in your frontend, alerts are a wonderful way. Combine them with some nice binary_sensors and you have a great information system for your house.
This is an excerpt of one of my alerts:
# config/packages/alerts.yaml
input_boolean:
lampe_berger_on_fire_notify:
name: Lampe Berger is on fire
icon: mdi:alert
lampe_berger_on_fire:
name: Lampe Berger on fire
icon: mdi:fire
template:
- binary_sensor:
- name: lampe_berger_on_fire_alert_active
state: "{{ is_state('input_boolean.lampe_berger_on_fire', 'on') and is_state('input_boolean.lampe_berger_on_fire_notify', 'on') }}"
delay_on: '00:20:00'
alert:
lampe_berger_on_fire_critical_alert_active:
name: lampe_berger_on_fire_critical_alert_active
entity_id: binary_sensor.lampe_berger_on_fire_alert_active
state: 'on'
repeat:
- 3
can_acknowledge: false
skip_first: false
title: "Critical warning"
message: "Lampe Berger is still on!"
notifiers:
- NOTIFY_critical
data:
tag: lampe_berger
done_message: clear_notification
notify:
- name: NOTIFY_critical
platform: group
services:
- service: mobile_app_s
- service: mobile_app_p
- service: notification_tv
data:
data:
duration: 10
fontsize: medium
position: center
color: grey
transparency: 0%
And this is, how it is used in the frontend with auto-entities: