need help. Not sure the best way to submit.
I got API response for the Sunset time as “Sunset” = “06:39” and I have local time in ESP32 as “01:32:23”. I am not expert on software coding but can carry your instructions. Please help me how to code logical test of these two time and turn a port in ESP32. Thanks
Can you try to better explain your issue?
How do you get the local time with the ESP32? Do you want to compare two times to trigger something?
I guess you’re getting the sunset time as a String, right?
You can split the string to get the hour and the minute in two separate strings and then convert them to a number.
You can use the substring() method to split the string: https://www.arduino.cc/reference/en/language/variables/data-types/string/functions/substring/
Then, you can use the toInt() method to convert the string to a number: https://www.arduino.cc/reference/en/language/variables/data-types/string/functions/toint/
After this, you just need to compare the sunset hour with the current hour. This tutorial shows how to get time (hour and minutes separately): https://randomnerdtutorials.com/esp32-date-time-ntp-client-server-arduino/
You can also use the epoch time (unix time) if the API can get the sunset time in that format (that would be easier because you would only need to compare one variable).
I hope this helps.