From 7a2e399e4f64cf7d422235137383bb18045f5f3a Mon Sep 17 00:00:00 2001 From: Paul Bottein Date: Tue, 24 Oct 2023 13:42:46 +0200 Subject: [PATCH] Add multiple condition types to conditional card (#29506) --- source/_dashboards/conditional.markdown | 148 ++++++++++++++++++++---- source/_dashboards/entities.markdown | 19 +-- 2 files changed, 126 insertions(+), 41 deletions(-) diff --git a/source/_dashboards/conditional.markdown b/source/_dashboards/conditional.markdown index d96fab1fbcf..d6349cd1e1e 100644 --- a/source/_dashboards/conditional.markdown +++ b/source/_dashboards/conditional.markdown @@ -2,16 +2,16 @@ type: card title: Conditional Card sidebar_label: Conditional -description: The Conditional card displays another card based on entity states. +description: The Conditional card displays another card based on conditions. --- -The Conditional card displays another card based on entity states. +The Conditional card displays another card based on conditions. -Note: Conditions with more than one entity are treated as an 'and' condition. This means that for the card to show, *all* entities must meet the state requirements set. +Note: if there are multiple conditions there will be treated as an 'and' condition. This means that for the card to show, _all_ conditions must be met. To add the Conditional card to your user interface, click the menu (three dots at the top right of the screen) and then **Edit Dashboard**. Click the **Add Card** button in the bottom right corner and select from the card picker. Note that while editing the dashboard, the card will always be shown, so be sure to exit editing mode to test the conditions. -All options for this card can be configured via the user interface. +Most options for this card can be configured via the user interface. ## YAML Configuration @@ -24,38 +24,28 @@ type: type: string conditions: required: true - description: List of entity IDs and matching states. + description: List of conditions to check. See [available conditions](/dashboards/conditional/#card-conditions). type: list - keys: - entity: - required: true - description: Entity ID. - type: string - state: - required: false - description: Entity state is equal to this value.* - type: string - state_not: - required: false - description: Entity state is unequal to this value.* - type: string card: required: true description: Card to display if all conditions match. type: map {% endconfiguration %} -*one is required (`state` or `state_not`) - -### Examples +## Examples ```yaml type: conditional conditions: - - entity: light.bed_light + - condition: state + entity: light.bed_light state: "on" - - entity: switch.decorative_lights + - condition: state + entity: light.bed_light state_not: "off" + - condition: user + users: + - 581fca7fdc014b8b894519cc531f9a04 card: type: entities entities: @@ -65,3 +55,115 @@ card: - lock.kitchen_door - light.bed_light ``` + +## Card conditions + +### State + +```yaml +condition: "state" +entity: climate.thermostat +state: heat +``` + +```yaml +condition: "state" +entity: climate.thermostat +state_not: "off" +``` + +Tests if an entity has a specified state. + +{% configuration %} +condition: + required: true + description: "`state`" + type: string +entity: + required: true + description: Entity ID. + type: string +state: + required: false + description: Entity state is equal to this value. Can contain an array of states.* + type: [list, string] +state_not: + required: false + description: Entity state is unequal to this value. Can contain an array of states.* + type: [list, string] +{% endconfiguration %} + +*one is required (`state` or `state_not`) + +### Numeric State + +Tests if an entity state matches the thresholds. + +```yaml +condition: "numeric_state" +entity: sensor.outside_temperature +above: 10 +below: 20 +``` + +{% configuration %} +condition: + required: true + description: "`numeric_state`" + type: string +entity: + required: true + description: Entity ID. + type: string +above: + required: false + description: Entity state is above this value.* + type: string +below: + required: false + description: Entity state is below to this value.* + type: string +{% endconfiguration %} + +*at least one is required (`above` or `below`) + +### Screen + +Specify the visibility of the card per screen size. Some screen size presets are available in the UI but you can use any CSS media query you want in YAML. + +```yaml +condition: screen +media_query: "(min-width: 1280px)" +``` + +{% configuration %} +condition: + required: true + description: "`screen`" + type: string +media_query: + required: true + description: Media query to check which screen size are allowed to display the card. + type: string +{% endconfiguration %} + +### User + +Specify the visibility of the card per user. + +```yaml +condition: "user" +users: + - 581fca7fdc014b8b894519cc531f9a04 +``` + +{% configuration %} +condition: + required: true + description: "`user`" + type: string +users: + required: true + description: User ID that can see the card (unique hex value found on the Users configuration page). + type: list +{% endconfiguration %} diff --git a/source/_dashboards/entities.markdown b/source/_dashboards/entities.markdown index 7973839a311..78085e5d088 100644 --- a/source/_dashboards/entities.markdown +++ b/source/_dashboards/entities.markdown @@ -292,31 +292,14 @@ type: type: string conditions: required: true - description: List of entity IDs and matching states. + description: List of conditions to check. See [available conditions](/dashboards/conditional/#card-conditions). type: list - keys: - entity: - required: true - description: Entity ID. - type: string - state: - required: false - description: Entity state is equal to this value.* - type: string - state_not: - required: false - description: Entity state is unequal to this value.* - type: string row: required: true description: Row to display if all conditions match. Can be any of the various supported rows described on this page. type: map {% endconfiguration %} -*one is required (`state` or `state_not`) - -Note: Conditions with more than one entity are treated as an 'and' condition. This means that for the card to show, *all* entities must meet the state requirements set. - ### Divider {% configuration %}