Moved from esphome's sun integration to ha's sun integration.

This is Commander1024 doing awful string / time fuckerey full of
desperation to format sunrise / sunset times.
Don't be like Commander1024
This commit is contained in:
Marcus Scholz 2021-10-09 00:24:20 +02:00
parent 313037040e
commit 42cc970a41
1 changed files with 47 additions and 32 deletions

View File

@ -107,32 +107,32 @@ text_sensor:
id: sun_state
internal: True
# - platform: homeassistant
# entity_id: sun.sun
# id: sun_rise
# attribute: next_rising
# internal: True
# - platform: homeassistant
# entity_id: sun.sun
# id: sun_set
# attribute: next_setting
# internal: True
- platform: sun
name: "Nächster Sonnenaufgang"
- platform: homeassistant
entity_id: sun.sun
id: sun_rise
type: sunrise
format: "%H:%M"
attribute: next_rising
internal: True
- platform: sun
name: "Nächster Sonnenuntergang"
- platform: homeassistant
entity_id: sun.sun
id: sun_set
type: sunset
format: "%H:%M"
attribute: next_setting
internal: True
# - platform: sun
# name: "Nächster Sonnenaufgang"
# id: sun_rise
# type: sunrise
# format: "%H:%M"
# internal: True
# - platform: sun
# name: "Nächster Sonnenuntergang"
# id: sun_set
# type: sunset
# format: "%H:%M"
# internal: True
- platform: homeassistant
entity_id: sensor.moon
id: moonphase
@ -265,11 +265,29 @@ display:
float livingroom_temp = id(temp_livingroom).state;
int livingroom_humid = int(id(humid_livingroom).state);
int livingroom_pm25 = int(id(pm25_livingroom).state);
// Format: 2021-10-08T05:40:47.467076+00:00
//struct tm tm;
//strptime(id(sun_rise).state.c_str(), '%Y-%m-%dT%H:%M:%S.%f%z');
//std::string sunrise = printf("%d:%d", tm.tm_hour, tm.tm_min);
char sunrise[5] = "";
char sunset[5] = "";
// This is Commander1024 doing awful string / time fuckerey full of
// desperation to format sunrise / sunset times.
// Don't be like Commander1024
// Format: 2021-10-08T05:40:47.467076+00:00 -> 7:40 (dst)
int dst = id(homeassistant_time).now().is_dst; // returns 1 for dst, otherwise 0
struct tm tm;
memset (&tm, 0, sizeof (tm));
strptime(id(sun_rise).state.c_str(), "%Y-%m-%dT%H:%M:%S", &tm);
time_t rawtime = mktime(&tm);
struct tm* ltm = localtime(&rawtime);
sprintf(sunrise, "%d:%d", ltm->tm_hour + dst, ltm->tm_min);
memset (&tm, 0, sizeof (tm));
strptime(id(sun_set).state.c_str(), "%Y-%m-%dT%H:%M:%S", &tm);
rawtime = mktime(&tm);
ltm = localtime(&rawtime);
sprintf(sunset, "%d:%d", ltm->tm_hour + dst, ltm->tm_min);
/* OUTSIDE */
it.print(10, 10, id(big_sensor_unit), "Umwelt");
@ -277,17 +295,14 @@ display:
it.filled_rectangle(86, 21, 297, 3);
if(id(sun_state).has_state()) {
ESP_LOGI("Sun", "State of the sun: %s", id(sun_state).state.c_str());
ESP_LOGD("Sun", "Sunset: %s", id(sun_set).state.c_str());
ESP_LOGD("Sun", "Sunrise ESPHOME: %s", id(sun_rise).state.c_str());
//ESP_LOGD("Sun", "Sunrise ESPHOME: %s, Sunrise HA: %s", id(sun_rise).state.c_str(), sunrise.c_str());
//ESP_LOGD("Location", "Latitude: %f, Longitude: %f", id(home_lat).state, id(home_long).state);
ESP_LOGD("Sun", "Sunrise: %s", sunrise);
ESP_LOGD("Sun", "Sunset: %s", sunset);
//if(id(sun_state).state == "above_horizon") {
it.print(10, 75, id(mdi_small), TextAlign::BASELINE_LEFT, "󰖜"); //sun-up
it.printf(50, 75, id(big_sensor_unit), TextAlign::BASELINE_LEFT, "%s", id(sun_rise).state.c_str());
it.printf(50, 75, id(big_sensor_unit), TextAlign::BASELINE_LEFT, "%s", sunrise);
it.print(135, 75, id(mdi_small), TextAlign::BASELINE_LEFT, "󰖛"); //sun-down
it.printf(175, 75, id(big_sensor_unit), TextAlign::BASELINE_LEFT, "%s", id(sun_set).state.c_str());
//it.strftime(50, 75, id(footer_font), TextAlign::BASELINE_LEFT, "Nächster Sonnenuntergang %d.%m.%Y %H:%M", id(sun_set).state.c_str());
it.printf(175, 75, id(big_sensor_unit), TextAlign::BASELINE_LEFT, "%s", sunset);
//}
//else {
//it.print(10, 75, id(mdi_small), TextAlign::BASELINE_LEFT, "󰖛"); //sun-down