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

View File

@ -107,32 +107,32 @@ text_sensor:
id: sun_state id: sun_state
internal: True internal: True
# - platform: homeassistant - platform: homeassistant
# entity_id: sun.sun 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"
id: sun_rise id: sun_rise
type: sunrise attribute: next_rising
format: "%H:%M"
internal: True internal: True
- platform: sun - platform: homeassistant
name: "Nächster Sonnenuntergang" entity_id: sun.sun
id: sun_set id: sun_set
type: sunset attribute: next_setting
format: "%H:%M"
internal: True 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 - platform: homeassistant
entity_id: sensor.moon entity_id: sensor.moon
id: moonphase id: moonphase
@ -265,11 +265,29 @@ display:
float livingroom_temp = id(temp_livingroom).state; float livingroom_temp = id(temp_livingroom).state;
int livingroom_humid = int(id(humid_livingroom).state); int livingroom_humid = int(id(humid_livingroom).state);
int livingroom_pm25 = int(id(pm25_livingroom).state); int livingroom_pm25 = int(id(pm25_livingroom).state);
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);
// 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);
/* OUTSIDE */ /* OUTSIDE */
it.print(10, 10, id(big_sensor_unit), "Umwelt"); it.print(10, 10, id(big_sensor_unit), "Umwelt");
@ -277,17 +295,14 @@ display:
it.filled_rectangle(86, 21, 297, 3); it.filled_rectangle(86, 21, 297, 3);
if(id(sun_state).has_state()) { if(id(sun_state).has_state()) {
ESP_LOGI("Sun", "State of the sun: %s", id(sun_state).state.c_str()); 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: %s", sunrise);
ESP_LOGD("Sun", "Sunrise ESPHOME: %s", id(sun_rise).state.c_str()); ESP_LOGD("Sun", "Sunset: %s", sunset);
//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);
//if(id(sun_state).state == "above_horizon") { //if(id(sun_state).state == "above_horizon") {
it.print(10, 75, id(mdi_small), TextAlign::BASELINE_LEFT, "󰖜"); //sun-up 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.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.printf(175, 75, id(big_sensor_unit), TextAlign::BASELINE_LEFT, "%s", sunset);
//it.strftime(50, 75, id(footer_font), TextAlign::BASELINE_LEFT, "Nächster Sonnenuntergang %d.%m.%Y %H:%M", id(sun_set).state.c_str());
//} //}
//else { //else {
//it.print(10, 75, id(mdi_small), TextAlign::BASELINE_LEFT, "󰖛"); //sun-down //it.print(10, 75, id(mdi_small), TextAlign::BASELINE_LEFT, "󰖛"); //sun-down