amaximus / garbage-collection-card

Custom Lovelace card for Garbage Collection custom component
MIT License
125 stars 24 forks source link

Need to use with sensors not created by the original intergration #113

Closed bschatzow closed 1 year ago

bschatzow commented 1 year ago

Is your feature request related to a problem? Please describe. I'm sure everyone is knows by now the original integration has been discontinued. I recreated all my sensors via templates and tried to use them in the app. Not working for me. It only shows the days. No icons.

Describe the solution you'd like Let users create their own garbage sensors and use your excellent card.

Describe alternatives you've considered Finding a different card.

Additional context image

amaximus commented 1 year ago

While the repo was removed from HACS, it is still accessible on GitHub (https://github.com/bruxy70/Garbage-Collection) so you can install it from there. You may also fork it to under your GitHub account so you'll have a copy of it until you need it. Of course it won't get updated to work with the latest HA in the future.

If you try to mimic the behaviour of the Garbage Collection custom integration you'll have to make sure it uses the same logic for sensor state and have the same attributes for it. The following attrbiutes of the sensor are used in the card: next_date, days, friendly_name, icon and last_collection. Beyond the attributes it also uses the collect_garbage service of the custom integration when hide_on_click = true is used.

bschatzow commented 1 year ago

Thank you for the explanation. Right now I don't have the knowledge on how to add these attributes to my template sensors. If I figure it out, I will post for others. Do the icons come from your card?

amaximus commented 1 year ago

You may check out the example from another integration's FAQ how they use it with this card: https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/faq.md

amaximus commented 1 year ago

The icon itself is not set by the card, it uses whatever icon the entity has.

bschatzow commented 1 year ago

Thanks for your help. I am trying to understand the setup of the waste_collection you linked above.

bschatzow commented 1 year ago

@amaximus Have you tried the waste collection schedule integration with multiple static sensors? I can never get more than one to load from my yaml file. They show up in HA as unknown.

amaximus commented 1 year ago

@bschatzow setting two waste collection schedule sensors like this:

(ha_venv3_10) pi@raspberrypi:~/homeassistant_test/sensors $more waste*.yaml
::::::::::::::
waste0.yaml
::::::::::::::
platform: waste_collection_schedule
name: next_collection
details_format: 'generic'
value_template: '{{ value.daysTo }}'
add_days_to: true
leadtime: 20
::::::::::::::
waste1.yaml
::::::::::::::
platform: waste_collection_schedule
name: next_collection1
details_format: 'generic'
value_template: '{{ value.daysTo }}'
add_days_to: true
leadtime: 20
(ha_venv3_10) pi@raspberrypi:~/homeassistant_test/sensors $

and using lovelace config like this:

(ha_venv3_10) pi@raspberrypi:~/homeassistant_test $tail -20  ui-lovelace.yaml
      - type: custom:garbage-collection-card
        source: 'hacs_waste_collection_schedule'
        entity: sensor.next_collection
        icon_color: black
        icon_size: 35px
        hide_date: false
        hide_days: true
        due_txt: true
        hide_dow: false
        hass_lang_priority: true
      - type: custom:garbage-collection-card
        source: 'hacs_waste_collection_schedule'
        entity: sensor.next_collection1
        icon_color: black
        icon_size: 35px
        hide_date: false
        hide_days: true
        due_txt: true
        hide_dow: false
        hass_lang_priority: true
(ha_venv3_10) pi@raspberrypi:~/homeassistant_test $

shows cards for both sensors (the last two ones): waste

bschatzow commented 1 year ago

I didn't understand your code above and when I tried it I got "Cannot read properties of undefined".

In any case I got all of my 4 sensors working in the waste integration. Now I am having difficulties getting them into the garbage card.

All of my yaml code:

waste_collection_schedule:
  sources:
    - name: static
      calendar_title: Garbage-Pickup
      args:
        type: Garbage
        frequency: WEEKLY
        weekdays: {MO, TH}
    - name: static
      calendar_title: Yard-Pickup
      args:
        type: Yard
        frequency: WEEKLY
        weekdays: MO
    - name: static
      calendar_title: Recycle-Pickup
      args:
        type: Recycle
        frequency: WEEKLY
        weekdays: WE
    - name: static
      calendar_title: Branches-Pickup
      args:
        type: Branches
        frequency: WEEKLY
        weekdays: TU
sensor:
# next garbage collection
  - platform: waste_collection_schedule
    name: garbage_col
    details_format: generic
    source_index: 0
    details_format: appointment_types
    value_template: "{{ value.daysTo }}"
    types:
      - Garbage
# next yard waste collection
  - platform: waste_collection_schedule
    name: yard_waste_col
    details_format: generic
    source_index: 1
    details_format: appointment_types
    value_template: "{{ value.daysTo }}"
    types:
      - Yard
# next recycle_collection
  - platform: waste_collection_schedule
    name: recycle_col
    details_format: generic
    source_index: 2
    details_format: appointment_types
    value_template: "{{ value.daysTo }}"
    types:
      - Recycle

# next branches collection
  - platform: waste_collection_schedule
    name: branches_col
    details_format: generic
    source_index: 3
    details_format: appointment_types
    value_template: "{{ value.daysTo }}"
    types:
      - Branches

  - platform: template
    sensors:
      garbage:
        value_template: >
          {% if states('sensor.garbage_col')|int > 2 %}
            2
          {% else %}
            {{ states('sensor.garbage_col')|int }}
          {% endif %}
        attribute_templates:
          next_date: "{{ state_attr('sensor.garbage_col', 'Garbage') }}"
          days: "{{ states('sensor.garbage_col')|int }}"

# next yard waste collection
  - platform: template
    sensors:
      yard:
        value_template: >
          {% if states('sensor.yard_waste_col')|int > 2 %}
            2
          {% else %}
            {{ states('sensor.yard_waste_col')|int }}
          {% endif %}
        attribute_templates:
          next_date: "{{ state_attr('yard_waste_col', 'Yard') }}"
          days: "{{ states('sensor.yard_waste_col')|int }}"
#recycle_collection, Recycle
  - platform: template
    sensors:
      recycle:
        value_template: >
          {% if states('sensor.recycle_col')|int > 2 %}
            2
          {% else %}
            {{ states('sensor.recycle_col')|int }}
          {% endif %}
        attribute_templates:
          next_date: "{{ state_attr('recycle_col', 'Recycle') }}"
          days: "{{ states('sensor.recycle_col')|int }}"
# branches collection, Branches
  - platform: template
    sensors:
      branches:
        value_template: >
          {% if states('sensor.branches_col')|int > 2 %}
            2
          {% else %}
            {{ states('sensor.branches_col')|int }}
          {% endif %}
        attribute_templates:
          next_date: "{{ state_attr('branches_col', 'Branches') }}"
          days: "{{ states('sensor.branches_col')|int }}"

My lovelace card as I used before:

  -
    cards:
      - entity: sensor.garbage
        icon_color: brown
        due_1_color: brown
        due_color: red
        icon_size: 35px
        title: Garbage
        type: 'custom:garbage-collection-card'
      - entity: sensor.yard
        icon_color: yellow
        due_1_color: yellow
        due_color: red
        icon_size: 35px
        type: 'custom:garbage-collection-card'  
      - entity: sensor.recycle
        icon_color: blue
        due_1_color: blue
        due_color: red
        icon_size: 35px
        type: 'custom:garbage-collection-card'  
      - entity: sensor.branches
        icon_color: green
        due_1_color: green
        due_color: red
        icon_size: 35px
        type: 'custom:garbage-collection-card'
    type: vertical-stack

How it is displaying in Lovelace

image

I'm sure I am confusing something?

The garbage sensors which works the others are similar to the recycle. I have no idea why they are coming in differently?

image

![image](https://github.com/amaximus/garbage-collection-card/assets/36886571/571262c2-ad5f-4746-b5f1-aab774cde7c7)

image


Before the icons showed in color.
I can't see what I am doing wrong.  Thanks again for your help.
amaximus commented 1 year ago

You may try setting details_format to generic and add add_days_to: true for one of the sensors (e.g. yard_waste_col) and use that sensor in one of your cards. If that works, you may set the others in the similar way and get rid of the template sensors.

bschatzow commented 1 year ago

Tried the following:

sensor:
# next garbage collection
  - platform: waste_collection_schedule
    name: garbage_col
    source_index: 0
    details_format: generic
    add_days_to: true
    value_template: "{{ value.daysTo }}"
    types:
      - Garbage
# next yard waste collection
  - platform: waste_collection_schedule
    name: yard_waste_col
    source_index: 1
    details_format: generic
    add_days_to: true
    value_template: "{{ value.daysTo }}"
    types:
      - Yard
# next recycle_collection
  - platform: waste_collection_schedule
    name: recycle_col
    source_index: 2
    details_format: generic
    add_days_to: true
    value_template: "{{ value.daysTo }}"
    types:
      - Recycle

# next branches collection
  - platform: waste_collection_schedule
    name: branches_col
    source_index: 3
    details_format: generic
    add_days_to: true
    value_template: "{{ value.daysTo }}"
    types:
      - Branches

And changed the card to:

  -
    cards:
      - entity: sensor.garbage
        icon_color: brown
        due_1_color: brown
        due_color: red
        icon_size: 35px
        title: Garbage
        type: 'custom:garbage-collection-card'
      - entity: sensor.yard_waste_col
        icon_color: yellow
        due_1_color: yellow
        due_color: red
        icon_size: 35px
        type: 'custom:garbage-collection-card'  

and the output to lovelace is:

image

The sensor now shows: image

amaximus commented 1 year ago

Setting up your yard_waste_col and the card for it:

(ha_venv3_10) pi@raspberrypi:~/homeassistant_test $cat sensors/waste2.yaml
platform: waste_collection_schedule
name: yard_waste_col
details_format: 'generic'
source_index: 1
value_template: '{{ value.daysTo }}'
add_days_to: true
leadtime: 20
(ha_venv3_10) pi@raspberrypi:~/homeassistant_test $tail -10  ui-lovelace.yaml
      - type: custom:garbage-collection-card
        source: 'hacs_waste_collection_schedule'
        entity: sensor.yard_waste_col
        icon_color: black
        icon_size: 35px
        hide_date: false
        hide_days: true
        due_txt: true
        hide_dow: false
        hass_lang_priority: true
(ha_venv3_10) pi@raspberrypi:~/homeassistant_test

it appears fine for me: waste

bschatzow commented 1 year ago

Thank you!!!!!

The fix for me was the line above of:

source: 'hacs_waste_collection_schedule'

Now they all work with no template sensors needed. I'll post my complete setup in the forums for others. Hopefully they can update the documentation on the waste integration as this is much easier and less confusing.

https://community.home-assistant.io/t/garbage-collection-recommendations-for-replacement-of-bruxy-integration/566964/11?u=bschatzow

oksakoor commented 1 year ago

Tried also to add this line: source: 'hacs_waste_collection_schedule' But it gives this error in DD dashboard 2023-06-05 17_43_34-Dwains Dashboard – Home Assistant

amaximus commented 1 year ago

This issue is closed. Could you please open a new issue? Please also include output on the console that would help troubleshooting. Please also make sure the sensor has the needed data. A sensor definition would also help to reproduce the fault. Thanks,