Next date sensor based on a day of a week

I’ve multiple input_select to indicate days and week for trash bin pickup:

input_select.monday can be YES or NO
one for each day of the week.

also I’ve input_select.week can be EVEN, ODD, ALL

In this scenario I can config at 100% days of trash bin pickup.

Now I’d like to create a sensor.date who tell me the next day in format: name-of-day YYYY-MM-DD for the next pickup day.

For example if i’ve set a pickup day only on saturday and today is friday, the sensor must be show me: Sat 2019-03-23 (example based on a real date, day after tomorrow).

Sensor must be based also for type of week odd or even.for example this week is n. 12 EVEN (18 to 24 march) so if I set week ODD, the next pickup day for the example above bust be on 30 March and NOT 24 march.

A next step (optional but ideally) woud be…if pickup day is saturday and today is saturday, sensor.date for the next pickup day must show me TODAY (if now is <= 12:00 a.m.) otherwhise like before (Sat YYYY-MM-DD) if now is Sat but time is > 12:00 a.m.

How can I create a next date calculation based only on my input_select YES/NO for each day (and type week)?

Sorry for the question but manipulate dates for me is hell :frowning:

You configure the trash dates by hand? Why not automate it? There are a lot of (custom) components for trash collectors already. Is yours not supported yet?

Although I like what you’re trying to achieve, that sounds like a very complicated setup
I can’t really work on a full solution right now (at work) but can at least give you a few pointers for your date calculations:
To get a date/time/week/weekday etc, you can use this formula:

{{ as_timestamp(now()) | timestamp_custom("%x")}}

Change the x to get the data you’re after. I’ve created a bit.ly link as I always forget the various formats: http://bit.ly/timstamp (without the ‘e’, timestamp was already taken)
Your date will become:

{{ as_timestamp(now()) | timestamp_custom("%Y-%m-%d")}}

Alternatively you can also use thinks like now().weekday(), now().hour etc
your odd/even week number can be calculated with

{{ as_timestamp(now()) | timestamp_custom("%W")| int  % 2}}

where 1 means odd, 0 means even

Actually I helped a fellow user with a similar request yesterday:

There’s no API service for Italy. I’m modifying the solution by user Skavala who has a good point to start from. And adapt it for me needs. At the end i hope to share my solution.

Hi, yes the user is… Me :slightly_smiling_face:
Thanks to your suggest i succesfully get what I want and now with this new request i hope to expand my project and then share it. Thanks a lot

LOL didn’t realise I was helping the same person :smiley:

I see… If the waste collector has a website with the dates, you could also use a scrape sensor.