bruxy70 / Garbage-Collection

🗑 Custom Home Assistant sensor for scheduling garbage collection (or other regularly re-occurring events - weekly on given days, semi-weekly or monthly)
MIT License
382 stars 90 forks source link

How to input large set of dates - exceeds 255 character #385

Closed stu1811 closed 2 years ago

stu1811 commented 2 years ago

Before you submit a new bug report, please check that

Write your question here

My town has yard pickup. In May, June, Sept, and Oct it's every week. The rest of the summer it's every other week. My thought was to use the input file but it exceeds 255 character. Any suggestions?

2022-04-06
2022-04-13
2022-04-20
2022-04-27
2022-05-04
2022-05-11
2022-05-18
2022-05-25
2022-06-08
2022-06-22
2022-07-06
2022-07-20
2022-08-03
2022-08-17
2022-08-31
2022-09-14
2022-09-28
2022-10-06
2022-10-12
2022-10-19
2022-10-26
2022-11-02
2022-11-09
2022-11-16
2022-11-23
2022-11-30
2022-12-07
bruxy70 commented 2 years ago

Did you try using the include blueprint?

stu1811 commented 2 years ago

HA Core throws an error stating it cannot store an entity with more then 255 character

bruxy70 commented 2 years ago

Ok. There is nothing I can do about the HA limit. So you probably need to make the list shorter. Unless you find some logic in the dates and can fix it with some exceptions.

stu1811 commented 2 years ago

Do you know if you can you use multiple blueprints simultaneously? ie split the txt file in half and read from both?

Is there a template to set multiple rules? ie every week for May, June, Oct, Nov and every other July, Aug, Sept?

bruxy70 commented 2 years ago

You can either create own automation to add dates from multiple lists sequentially. There is no such template. Or you can use different entities and then merge them with a group type.

stu1811 commented 2 years ago

One follow-up question. I cut my date list in half for now and I'm trying to use the import text bluerprint but I cannot select the command line templte.

sensor:
  - platform: command_line
    command: "cat /share/yard_waste.txt"
    name: yard_waste_pickup

image

image

image

bruxy70 commented 2 years ago

Not sure why is that. The import selector uses a comand_line integration, so that should work IMHO. You can remove the integration specification from the blueprint. Then it will show all entities.

stu1811 commented 2 years ago

That worked. Thanks.

stu1811 commented 2 years ago

@bruxy70 I came up with a new solution. Cat the file, remove any dates older than today, and echo the 20 newest dates. I created a script in share with following and called the script from my configuration.yaml.

#!/bin/bash                                                                                                                                                                                                                              
new_dates=$(for x in $(cat /share/import_dates.txt); do
                if [[ $(date -d $x +"%y%m%d") -ge $(date +"%y%m%d") ]]; then
                    echo $x
                fi
            done)
echo "$new_dates" | head -n20
bruxy70 commented 2 years ago

This is excellent. Thank you. Will add that to the documentation