Markdown numbers and replace

Hi there,

I’m running waste collection schedule and it’s working great. However, when I integrate it into my Dashboard I want it to display “tomorrow” (“morgen”) or “today” (“heute”) instead of (for example) “in one day”.

So I’m doing this in markdown with replace functions. All goes well, except: When the number of days is >= 10 it shows it as (for example) “1(tomorrow)” (see German language screenshot below).
It seems the markdown generates the “tomorrow” or “today” from the “1” or “0” that comes second in the “10”, “11”, “12”, …

I think it’s because “in 1 Tag(e)” is supposed to turn into “morgen” (tomorrow), whereas “in 11 Tag(e)” should be translated to “in 11 Tagen”).

Anybody know how this can be fixed?

Thanks!

Frontend (Dashboard):

YAML code for the Dashboard portion above:

Config.YAML entry for waste collection schedule (there’s a second entry for organic waste below the “Restmuell” entry, it’s formated/written identically to the “Restmuell” entry):

Just a couple of remarks:

  1. To help a person with an issue, sometimes a source code is required. And sometimes this code must be checked locally to solve the issue. And posting a “photo of the code” instead of the code itself does not help.
  2. Large code is more difficult to understand. That is why people usually provide a short MWE - just to localize an issue.
2 Likes

such a helpful remark. thanks.

¯\_(ツ)_/¯

That was a right remark))

You should really take such remarks into account. It is up to others to help you, so if you want that help, you should be able to follow the rules, that are set up to make it a little smoother to help. Don’t forget, you want an answer, so somebody has to give it. If you p*** off people right upfront, it will not be helpful for your question. :wink:

Especially this thread would be a good starting point, so you can avoid faults like this in the future. :slight_smile:

See here:

Especially #14

That being said, you shouldn’t do that conversion in your markdown, it is way easier in the sensor itself.

sensor:
  - platform: waste_collection_schedule
    name: waste_collection_waste
    details_format: upcoming
    add_days_to: true
    value_template: >-
      {% if value.daysTo == 0 %}
      HEUTE
      {% elif value.daysTo == 1 %}
      MORGEN
      {% else %}
      in {{value.daysTo}} Tagen
      {% endif %} 
    types:
      - Restmuelltonne

Same goes for the customization entries, do it at the global level:

homeassistant:
  customize:
    sensor.waste_collection_waste:
      friendly_name: Restmüll
      icon: 'mdi:trash-can'
2 Likes

Thanks!

Re p*** ppl of/help desk: I know. But it goes both ways. A quick “could you copy/paste the code” would have been helpful. But that reply was entirely unhelpful imo. If I can’t help or don’t want to help I just don’t say anything. No need to lecture.

See the way you handled it was great. Info about how I should have done something and then still provided an insight. People here (at least that goes for me) don’t als questions because they are lazy (ok. Maybe some do, but I actually did try and figure this out myself before asking.) And also: how many threads have the first reply as: “please show your code”. So yeah…

Vielen Dank!! :slight_smile:

1 Like
  1. My advise for you was not a lecture. It was a real advise.
  2. Looking at your reaction - I conclude that you really need neither a lecture nor an advice, absolutely self-sufficient person, and what are you doing here then?

I never said I was “self-sufficient” (w/ regards to HA) = I never claimed to be an expert. I only tried to convey that I did infact do some research ahead of posting here and did not come here right from the start and treated this as a “service hotline” for HA (which this is not).

Perhaps a misunderstanding. It just seemed as if you were trying to only say how I should have posted the question differently without actually looking if you could help with the problem at hand. If you’re only looking to tell people how to post differently, OK but not really 100% helpful (in that precise/specific circumstance). If one says “hey, it’s better to copy/paste the code directly, but that said, here’s a bit of info that might actually help solve your problem”, then that’s much, much more helpful and - I think - will also help more people.

That said: I do appreciate that you (and many others) are so active on the forum. It’s what makes HA work so great (the community “support”) (in quotation marks, because this obv. is not a “support” hotline as such)

To help you - people sometimes need additional info.
In many cases people need a code - like me - because I usually have to reproduce a case on my HA setup. And for this I take a person’s code, adapt it for my test sensors & test it.
So I told you very clear - “you should provide A & B”. W/o any aggression.
Before getting the needed info - sometimes it is not possible to give you a solution.
So, if someone does not provide all needed info - it works like this:
1 . Provide additional info.
2 . Here is the additional info.
3 . Here is the solution.

These are very simple things actually. And they are not worth to spend much time to discuss.

I know these advises seems often to be rude, but I can asure you, @Ildar_Gabdullin isn’t one of the guys here, that is picking on others - he is one of the really helpful people here. And not knowing him (at least I think him, not her) personally, I can still asure you, he didn’t mean to take it personally.

But I can as well see, that people like you can get this the wrong way (“in den falschen Hals bekommen” :smiley: ).

So guys, it’s a nice midsommer Sunday and we all have bigger fish to fry, than getting involved in discussions like this. Be nice to each other, we need to be united against all the shit that is going on in this world. :slight_smile:

Moving on - did my code work for you and did it help? :slight_smile: It did cost me some nerves to get the waste_collection_schedule running like I wanted it, so if I can be of assistance, let me know!

And now, I wish both of you a nice and not to warm Sunday! :slight_smile: Stay safe! :wink:

2 Likes

Agreed :slight_smile: - we’re all in the same community (HA) here.

Anyways didn’t get around to testing your code yet (sitting at home with a newborn, so my schedule isn’t always as I’d like it to be :wink: ). I’ll let you know, once I get around to testing it.

Thanks!!

2 Likes

Well, this is definitely much more important than HA ))

1 Like

indeed :slight_smile:

Also sleep deprivation probably didn’t help with my reaction earlier …

Well, come back any time when you are ready for HA-tainment ))

Hi there, just tried your code and it works like a charm. Had to do some finagling with the brackets (just because of where I want them vs. where I don’t want them to appear, but that was purely stylistic.

Thanks!!

1 Like

Thanks for the feedback and glad to hear it works for you! :slight_smile: :+1:

1 Like

@paddy0174 By any chance, are you working with multiple sources (aka using the “source_index” line)? If so, any idea how two sources could be mixed in a “nächste abholung” type of sensor? With only one source it works flawlessly (listing first my “Restmüll”, then my “Biomüll”, and so on). However, once I add in a second source, it shows either the first source (Rest- / Biomüll) or (when specified) the second source (Wertstoff). (I’d like to add the Wertstoffmüll into the “die nächste abholung ist XYZ”- line for trash pickups shown in my screenshot above. Right now that does not work, as it’s either bio and rest or wertstoff in that markdown line at least. (individually the sensors work fine and show the required information)

Thanks!!

waste_collection_schedule:
  sources:
    - name: bsr_de
      args:
        abf_strasse: <XXX>
        abf_hausnr: <XXX>
      customize:
        - type: "Abholung Hausmüll"
          alias: Hausabfall
          icon: mdi:trash-can
        - type: "Abholung Biogut"
          alias: Biogut
          icon: mdi:recycle
    - name: abfall_io
      args:
        key: "9583a2fa1df97ed95363382c73b41b1b"
        f_id_kommune: 3227
        f_id_strasse: <XXX>
        f_id_strasse_hnr: <XXX>
        f_abfallarten:
          - 127
      customize:
        - type: "127"
          alias: Wertstofftonne
          icon: mdi:recycle-variant
  fetch_time: "04:00"
  day_switch_time: "08:00"

sensor:
  - platform: waste_collection_schedule
    source_index: 1
    name: Wertstoff
    details_format: "upcoming"
    value_template: >-
      {% if value.daysTo == 0 %}
      HEUTE
      {% elif value.daysTo == 1 %}
      MORGEN
      {% else %}
      in {{value.daysTo}} Tagen
      {% endif %}
    types:
      - Wertstofftonne

  - platform: waste_collection_schedule
    source_index: 0
    name: Restmuell
    details_format: "upcoming"
    value_template: >-
      {% if value.daysTo == 0 %}
      HEUTE
      {% elif value.daysTo == 1 %}
      MORGEN
      {% else %}
      in {{value.daysTo}} Tagen
      {% endif %}
    types:
      - Hausabfall

  - platform: waste_collection_schedule
    source_index: 0
    name: Biomuell
    details_format: "upcoming"
    value_template: >-
      {% if value.daysTo == 0 %}
      HEUTE
      {% elif value.daysTo == 1 %}
      MORGEN
      {% else %}
      in {{value.daysTo}} Tagen
      {% endif %}
    types:
      - Biogut

  - platform: waste_collection_schedule
    name: abfallnaechster
    details_format: "upcoming"
    value_template: >-
      {% if value.daysTo == 0 %}
      HEUTE
      {% elif value.daysTo == 1 %}
      MORGEN
      {% else %}
      in {{value.daysTo}} Tagen
      {% endif %}

Not sure if I get you right. :slight_smile: You have two different collections on one day and want to show them both, not only one of them, right?

Funny enough, I have this too. :smiley: I have “paper” and “gelber Sack” at the same day, mostly. But if there is a bank holiday, they sometimes differ. :face_with_raised_eyebrow:

I don’t have anything in place for this, because I’m displaying the sensors one by one and just have these funny little badges, that show there is a collection coming up. But for the voice assistant I have a list in place, that just get read. Imagine it like this: "Morgen ist Restmüll" 'if length > 1' + " und " + "Papier".

What exactly would you like to have? Do you want it shown “only” in lovelace/dashboard as one sentence? Then I’d just go the route to combine them in a template for a markdown card. Or do you need to work with that sensor state in any way?

not quite - luckily enough for me pickups are (mostly) at least one day apart.

What I have is that two types of waste (bio + rest) are picked up by BSR, while Wertstoff (Gelber Sack) is picked up by ALBA. This means that in Waste Collection Schedule I need to “import” two sources. However the markup that references the sensor that shows the next pickup only works across a single sensor. Does that make sense? see one of my screenshots for a picture of how I (currently) display the next pickup in the dashboard. :slight_smile:
Thanks!

Where does the value.daysTo come from please?

I would like to create an automation that triggers based on value.daysTo equalling 1 but I’m not sure how to reference that attribute/property.

The sensor template is…

- platform: waste_collection_schedule
  name: whc_waste_collection
  details_format: upcoming
  value_template: '{{value.types|join(" + ")}} {% if value.daysTo == 0 %}Today{% elif value.daysTo == 1 %}Tomorrow{% else %}in {{value.daysTo}} days ({{value.date.strftime("%a %d")}}){% endif %}|{{value.daysTo}}'