Madelena / hass-config-public

My Dashboards for Home Assistant - Advanced data visualizations, responsive design, a neat maximalist Metro Live Tile layout, and an ultraminimal tablet layout!
712 stars 57 forks source link

Chore Tracker configuration error #3

Closed szethh closed 2 years ago

szethh commented 2 years ago

Hi! I tried setting up the chore tracker but I ran into an issue. I'm at this point in your guide:

Double check that the chores are loaded in the States tab of Developer Tools by searching for the entity group.chores. There should be a list of your chores in the attributes of the entity. However, I do not see any entities of type `input_button or input_text. Here is my configuration.yaml:


# Loads default set of integrations. Do not remove.
default_config:

Text to speech

tts:

automation: !include automations.yaml script: !include scripts.yaml scene: !include scenes.yaml

lovelace: mode: yaml resources:

http: use_x_forwarded_for: true trusted_proxies:

FOR SOME REASON REQUIRED OTHERWISE GROUPS IS NOT DEFINED

DUMMY GROUP

binary_sensor:

input_button: # FOR SOME REASON REQUIRED OTHERWISE INPUT BUTTON IS NOT DEFINED input_button chores: !include chores.yaml

input_text: # FOR SOME REASON REQUIRED OTHERWISE INPUT TEXT IS NOT DEFINED input_text chores: !include chores.yaml



As you can see there is not much that could interfere. I did find that, if I don't include the `input_button:` line, I get errors while parsing the configuration. This is a fresh install of HaOS (2022.6.7).
Likewise, I needed to create a "dummy" group, or the automation would complain that the service "group.get" was not defined.

I'm really new to HomeAssistant so I don't really know how it works. Can you help me?
Madelena commented 2 years ago

You are correct that the input_button: line is needed if you don't have any other input buttons defined. Thank you for the report and let me add it to the tutorial.

Does it work otherwise?

Madelena commented 2 years ago

Also, did you type "group.get" or "group.set"?

szethh commented 2 years ago

Also, did you type "group.get" or "group.set"?

Yes, sorry, it was group.set.

If I don't include the input_button: line the check configuration hangs forever (does not raise any errors), but when I run ha core check it does flag it as an error.

Even with that line included, and after reloading the input_buttons and input_texts, they still don't show up in the list of entities. The automation seems to run fine, but since there are no entities named chore_x it does not fill the list.

Maybe clicking reload does not expand !includes or read from files?

Also, I had some doubts with the whole !include thing. From my understanding, the line input_button chores: !include chores.yaml is:

  1. Taking the dictionary input_button (which needs to be created beforehand, hence the "dummy" line input_button:) and modifying/adding the key chores
  2. The value of input_button[chores] is set to whatever the chores.yaml file returns
  3. Which is another dictionary of input_buttons, with their corresponding name and icon properties.

So if we "expand" the !include directive, we would end up with:

input_button.chores:  --> these are not picked up by the entity explorer?
  chore_clean_kitchen_sink: # A unique ID for the chore
    name: Clean Kitchen Sink # The name of the chore to be shown on the Chore List
    icon: mdi:water-pump # The icon of the chore to be shown on the Chore List
  ... (more chores)

Is this how it works? As I said I'm really new to this. Thanks.

Madelena commented 2 years ago

I just double checked the tutorial and thanks for your analysis.

Would it work if you try:

input_button: !include chores.yaml
input_text: !include chores.yaml

Make sure chores.yaml and configurations.yaml are in the same folder.

For some reason the input_button chores: alias doesn't work, so removing it to just input_button: should work.

szethh commented 2 years ago

Yes, that worked! Now I don't need the dummy lines anymore. The automation also worked perfectly, now group.chores shows up with a list of entities.

However, I now have problems with the UI...

For reference, this is my ui-lovelace.yaml

title: Home
views:
  - path: default_view
    title: Home
    cards:
      - type: weather-forecast
        entity: weather.buienradar
        show_forecast: false
      - type: "custom:auto-entities"
        filter:
          include:
            - group: group.chore_plants
              options:
                type: "custom:button-card"
                template: chore_card
        card:
          type: entities
          title: Plants

button_card_templates:
  chore_card:
    variables:
      now: [[[return new Date()]]]  # ' --> removed this quote
      last_done: [[[return new Date(entity.state)]]]  # ' --> and this one as well
      diff: >-
        [[[ return Math.round((new Date() - new Date(entity.state)) / 1000 /
        60 / 60 / 24 ) ]]]
      due: >-
        [[[ return states[entity.entity_id.replace("input_button",
        "input_text")].state ]]]
    triggers_update: all
    show_label: true
    layout: icon_name_state2nd
    size: 24px
    label: |
      [[[
        var doneStr
        if (variables.diff < 2) {
          if (variables.last_done.getDay() == variables.now.getDay()) { doneStr = 'today' } else { doneStr = 'yesterday' }
        } else if (isNaN(variables.diff)) {
          doneStr = 'unknown'
        } else {
          doneStr = variables.diff + ' days ago'
        }
        if (variables.due > 0) {
          return 'Every ' + variables.due + ' days &bull; Last done ' + doneStr
        } else { return 'As needed &bull; Last done ' + doneStr }
      ]]]
    custom_fields:
      badge: |
        [[[
          if ((variables.diff < 2) && (variables.last_done.getDay() == variables.now.getDay())) { return 'Done' }
          if (variables.due > 0) {
            if (variables.due < variables.diff) { return 'Overdue' }
            if (variables.due < variables.diff + (variables.due / 4)) { return 'To do soon' }
          }
        ]]]
    styles:
      card:
        - margin: 4px 0
        - padding: 4px 12px
        - background-color: |
            [[[
              if ((variables.diff < 2) && (variables.last_done.getDay() == variables.now.getDay())) { return 'rgba(var(--rgb-success-color), .33)' }
              if ((variables.due > 0) && (variables.due < variables.diff)) { return 'rgba(var(--rgb-error-color), .33)' } else {return 'transparent'}
            ]]]
      grid:
        - grid-template-columns: min-content 1fr min-content
        - grid-template-areas: '"i n badge" "i s badge" "i l badge"'
      img_cell:
        - align-self: middle
        - text-align: start
        - padding: 8px 24px 8px 4px
      icon:
        - color: |
            [[[
              if ((variables.diff < 2) && (variables.last_done.getDay() == variables.now.getDay())) { return 'var(--success-color)' }
              if (variables.due > 0) {
                if (variables.due < variables.diff) { return 'var(--error-color)' }
                if (variables.due < variables.diff + (variables.due / 4)) { return 'var(--warning-color)' }
              } else { return 'var(--primary-text-color)' }
            ]]]
      name:
        - align-self: middle
        - justify-self: start
        - font-size: var(--body-font-size)
      label:
        - align-self: middle
        - justify-self: start
        - font-size: var(--body-font-size)
        - opacity: 0.66
      custom_fields:
        badge:
          - background: |
              [[[
                if ((variables.diff < 2) && (variables.last_done.getDay() == variables.now.getDay())) { return 'var(--success-color)' }
                if (variables.due < variables.diff) { return 'var(--error-color)' } else { return 'var(--warning-color)' }
              ]]]
          - padding: 2px
          - line-height: 1
          - font-size: var(--h6-font-size)
          - font-weight: 900
          - text-transform: uppercase
          - border-radius: 2px
          - color: var(--accent-text-color)
    tap_action:
      action: call-service
      service: input_button.press
      service_data:
        entity_id: entity
    hold_action:
      action: more-info
      entity: >-
        [[[ return entity.entity_id.replace("input_button", "input_text")
        ]]]

(Notice how it is basically a copy-paste from the tutorial). I did remove two quotes ' since they were unmatched and VSCode was complaining about invalid yaml.

In the dashboard I see a card with the title "Plants" but no content.

P.S.: Is there a way to debug the UI components? Can we set breakpoints in the python code? I feel lost trying to understand and debug these monolithic yamls.

Madelena commented 2 years ago

My bad. It should be:

      - type: "custom:auto-entities"
        filter:
          include:
            - group: group.chores     # <--- not chore_plants

Thanks for bearing with all the errors in this first draft of the tutorial. 😅 Hope this has been a useful learning experience for you.

szethh commented 2 years ago

Hey, that worked as well (kinda). Now I was getting JS errors, saying that variables.last_date.getDay() was not a function. I found the solution purely by chance, and it is really bizarre. I don't really know why it happens:

now: [[[ return new Date() ]]]  # --> for some reason home assistant parses this line as:
now: - - - return new Date()   # --> which is not valid JS so it gives an error

I'll include a picture to illustrate what I mean (see bottom):

Screenshot 2022-07-03 at 02 15 18

No other variables were giving errors, and the thing they all had in common was that they were defined with yml line breaks. I replaced the line with this (just adding a line break, no actual code change) and it works...

variables:
  now: >-
    [[[ return new Date() ]]]
  last_done: >-
    [[[return new Date(entity.state)]]]

I honestly have no idea why this is the case, my javascript knowledge is basic at best. This has definitely been a learning experience hahah.

But hey, now they render, and they look great!

Now I just need to figure out how to set the frequency... But thank you very much for the tutorial and for the help!

I hope those who come across this issue find it helpful as well.

Madelena commented 2 years ago

In my original version of the tutorial, it's missing a ' for the now and last_done variables, so the way you fixed it is correct! 👍

Now I just need to figure out how to set the frequency...

To do that, long press an item, or go to Settings -> Integrations -> Helpers and find the Input Text for that chore to edit the number. It's in the amount the days.

I'm glad it all works out! Enjoy!