damianeickhoff / HaCasa

Custom theme and cards for Home Assistant
https://damianeickhoff.github.io/HaCasa/
MIT License
60 stars 6 forks source link

Conditional Card #14

Open drashish87 opened 5 months ago

drashish87 commented 5 months ago

Hi, Thanks for releasing this theme really like it and waiting for a more generic code to be able to add additional cards.

In the meantime, I have been trying to add the garbage collection card. Can you advise how to make this card conditional? I have created 2 sensors refuse and recycling as both as both collections are on alternate weeks wednesday.

I want the collection which is less than 7 days away aka next up for collection, card to display rather than display both all the time.

This is my current code so far, I have tried conditions but it doesn't seem to work, can you advise if i need to add any another template ? Many Thanks for your help

  - type: "custom:button-card"
    template:
      - custom_card_garbage_collection
    variables:
      label: Days until next<br>refuse collection
      counter: |
        [[[ return states['sensor.refuse'].state ]]]
    entity: input_boolean.toggle_button_notify_garbage

  - type: "custom:button-card"
    template:
      - custom_card_garbage_collection
    variables:
      label: Days until next<br> Recycling & garden collection
      counter: |
        [[[ return states['sensor.recycling'].state ]]]
    entity: input_boolean.toggle_button_notify_garbage

With condition which is not working

  - type: conditional
    conditions:
      - condition: state
        entity: sensor.recycling
        state: < 7
    card:
      type: entity
      entity: sensor.recycling
      name: Days to Recycling Collection
      icon: mdi:recycle-variant
damianeickhoff commented 5 months ago

Its not really in the scope of this project, but I'll try to help you anyway.

So, I would guess the conditional card should work if the sensor.recyling is reporting back a number. Did you check that? Also, you probably would want to use the below statement in the numeric_state from the conditional card.

For example:

type: conditional
conditions:
  - condition: numeric_state
    entity: sensor.recycling
    below: 7
card:
  type: entity
  entity: sensor.recycling
  name: Days to Recycling Collection
  icon: mdi:recycle-variant

Did this work for you?

drashish87 commented 5 months ago

Thank you for your reply and apologies for the late reply. I have tried this as well but the card doesn't appear for some reason, even though 1 day is remaining to collection.

damianeickhoff commented 5 months ago

Share me your code and share me the what the sensor outputs through dev > states.

drashish87 commented 5 months ago

This is my sensor code in configurations.yaml, as you will appreciate, I have put the collection dates in calendars and created a sensor.

template:
  - sensor:
      - name: "refuse"
        state: >-
          {{ ((state_attr('calendar.refuse', 'start_time') | as_timestamp - today_at('00:00') | as_timestamp) / 86400) | int }} days
      - name: "recycling"
        state: >-
          {{ ((state_attr('calendar.recycling_and_garden', 'start_time') | as_timestamp - today_at('00:00') | as_timestamp) / 86400) | int }} days

dev<states

Screenshot 2024-02-02 at 18 51 22

The conditional card codes dont work for some reason, tried the code you suggested as well.

Many thanks for looking into it