sagined
December 24, 2020, 10:43am
1
Hello I trying to get the next 4 days after today in oder to display the next 3 weekdays in my nextion.
i have got the current day of the week:
auto weekday_1 = id(sntp_time).now().strftime("%a");
it.set_component_text("fc_day_1", weekday_1.c_str());
But how can I get the next day? I need something like this but this is not working:
auto weekday_2 = id(sntp_time).now() + 86400;
weekday_2 = weekday_2. strftime("%a");
it.set_component_text("fc_day_2", weekday_2.c_str());
Do you have an hint for me how to do this?
Thanks
Ingo
Mutt
(Muttley)
December 24, 2020, 11:18am
2
Can you give an example case (say of today) and what you would desire as an output ?
Today is ‘Thur’, do you just want ‘Fri’ ???
And I assume you want this in local time ?
Do you have access to the datetime library? If so you can use timedelta.
id(sntp_time).now() + timedelta(days=1)
sagined
December 25, 2020, 10:09am
4
Thanks for the answers. for the time delta I have it not available in Esp.
Errrormessage:
src/main.cpp:880:57: error: 'days' was not declared in this scope
auto weekday_2 = sntp_time->now() + timedelta(days=1);
^
src/main.cpp:880:63: error: 'timedelta' was not declared in this scope
auto weekday_2 = sntp_time->now() + timedelta(days=1);
Probably I will do it via an sensor in HA and deliver it to ESP?
You can use the timestamp option of the time object to get the time in seconds since 01.01.1970 and then add 86400:
auto weekday_2 = id(sntp_time).now().timestamp + 86400;
Here are more infos about the time object:
sagined
December 25, 2020, 2:04pm
6
Thanks a lot for your answers.
Solved it now in HA with a dedicated sensor. Then I have also the possibility to take my native locale
sensors:
dayoftheweek:
value_template: >
{{ ['Mo','Di','Mi','Do','Fr','Sa','So'][now().weekday()] }}
dayoftheweek_plus_1:
value_template: >
{{ ['Di','Mi','Do','Fr','Sa','So','Di'][now().weekday()] }}
dayoftheweek_plus_2:
value_template: >
{{ ['Mi','Do','Fr','Sa','So','Mo','Di'][now().weekday()] }}