Moved sunrise/set calculation to HA via template sensor. Get rid of that (non-working) dirty workaround.
This commit is contained in:
parent
9aa7d9e693
commit
6d740d7383
@ -121,21 +121,16 @@ sensor:
|
|||||||
|
|
||||||
text_sensor:
|
text_sensor:
|
||||||
- platform: homeassistant
|
- platform: homeassistant
|
||||||
entity_id: sun.sun
|
name: "Sun Rising ESP"
|
||||||
id: sun_state
|
entity_id: sensor.sun_rising_template
|
||||||
internal: True
|
id: sun_rising
|
||||||
|
internal: true
|
||||||
|
|
||||||
- platform: homeassistant
|
- platform: homeassistant
|
||||||
entity_id: sun.sun
|
name: "Sun Setting ESP"
|
||||||
id: sun_rise
|
entity_id: sensor.sun_setting_template
|
||||||
attribute: next_rising
|
id: sun_setting
|
||||||
internal: True
|
internal: true
|
||||||
|
|
||||||
- platform: homeassistant
|
|
||||||
entity_id: sun.sun
|
|
||||||
id: sun_set
|
|
||||||
attribute: next_setting
|
|
||||||
internal: True
|
|
||||||
|
|
||||||
- platform: homeassistant
|
- platform: homeassistant
|
||||||
entity_id: sensor.moon
|
entity_id: sensor.moon
|
||||||
@ -325,33 +320,9 @@ display:
|
|||||||
int sleepingroom_pm25 = int(id(pm25_sleepingroom).state);
|
int sleepingroom_pm25 = int(id(pm25_sleepingroom).state);
|
||||||
float sleepingroom_co2 = id(co2_sleepingroom).state;
|
float sleepingroom_co2 = id(co2_sleepingroom).state;
|
||||||
float serverroom_temp = id(temp_serverroom).state;
|
float serverroom_temp = id(temp_serverroom).state;
|
||||||
char sunrise[5] = "";
|
|
||||||
char sunset[5] = "";
|
|
||||||
int offsetX = 0;
|
int offsetX = 0;
|
||||||
int offsetY = 0;
|
int offsetY = 0;
|
||||||
|
|
||||||
/*
|
|
||||||
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:%02d", 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:%02d", ltm->tm_hour + dst, ltm->tm_min);
|
|
||||||
|
|
||||||
|
|
||||||
/* OUTSIDE */
|
/* OUTSIDE */
|
||||||
it.print(10, 10, id(sensor_unit), "Umwelt");
|
it.print(10, 10, id(sensor_unit), "Umwelt");
|
||||||
/*
|
/*
|
||||||
@ -598,15 +569,14 @@ display:
|
|||||||
it.print(80 + offsetX, 200, id(big_sensor_font), TextAlign::BASELINE_LEFT, "Lüften!");
|
it.print(80 + offsetX, 200, id(big_sensor_font), TextAlign::BASELINE_LEFT, "Lüften!");
|
||||||
}
|
}
|
||||||
|
|
||||||
if(id(sun_state).has_state()) {
|
/* ESP_LOGI("Sunrise: %s, Sunset: %s",
|
||||||
ESP_LOGI("Sun", "State of the sun: %s, sunrise: %s, sunset: %s",
|
id(sun_rising).state.c_str(), id(sun_setting).state.c_str());
|
||||||
id(sun_state).state.c_str(), sunrise, sunset);
|
*/
|
||||||
|
|
||||||
it.print(10 + offsetX, 250, id(mdi_small), TextAlign::BASELINE_LEFT, ""); // sun-up
|
it.print(10 + offsetX, 250, id(mdi_small), TextAlign::BASELINE_LEFT, ""); // sun-up
|
||||||
it.printf(50 + offsetX, 250, id(sensor_unit), TextAlign::BASELINE_LEFT, "%s", sunrise);
|
it.printf(50 + offsetX, 250, id(sensor_unit), TextAlign::BASELINE_LEFT, "%s", id(sun_rising).state.c_str());
|
||||||
it.print(135 + offsetX, 250, id(mdi_small), TextAlign::BASELINE_LEFT, ""); // sun-down
|
it.print(135 + offsetX, 250, id(mdi_small), TextAlign::BASELINE_LEFT, ""); // sun-down
|
||||||
it.printf(175 + offsetX, 250, id(sensor_unit), TextAlign::BASELINE_LEFT, "%s", sunset);
|
it.printf(175 + offsetX, 250, id(sensor_unit), TextAlign::BASELINE_LEFT, "%s", id(sun_setting).state.c_str());
|
||||||
}
|
|
||||||
|
|
||||||
/* Serverroom */
|
/* Serverroom */
|
||||||
offsetY = 247;
|
offsetY = 247;
|
||||||
|
13
sensors.yaml
13
sensors.yaml
@ -2,6 +2,7 @@
|
|||||||
- platform: time_date
|
- platform: time_date
|
||||||
display_options:
|
display_options:
|
||||||
- 'time'
|
- 'time'
|
||||||
|
- 'date'
|
||||||
# Raspberry Pi CPU temp
|
# Raspberry Pi CPU temp
|
||||||
- platform: command_line
|
- platform: command_line
|
||||||
name: "CPU Temp"
|
name: "CPU Temp"
|
||||||
@ -56,3 +57,15 @@
|
|||||||
- platform: statistics
|
- platform: statistics
|
||||||
name: 'WAN Traffic Out'
|
name: 'WAN Traffic Out'
|
||||||
entity_id: sensor.internet_speed_out
|
entity_id: sensor.internet_speed_out
|
||||||
|
|
||||||
|
- platform: template
|
||||||
|
sensors:
|
||||||
|
sun_rising_template:
|
||||||
|
friendly_name: "Sun Rising Template"
|
||||||
|
value_template: "{{ as_timestamp(states.sun.sun.attributes.next_rising) | timestamp_custom ('%H:%M') }}"
|
||||||
|
|
||||||
|
- platform: template
|
||||||
|
sensors:
|
||||||
|
sun_setting_template:
|
||||||
|
friendly_name: "Sun Setting Template"
|
||||||
|
value_template: "{{ as_timestamp(states.sun.sun.attributes.next_setting) | timestamp_custom ('%H:%M') }}"
|
||||||
|
Loading…
Reference in New Issue
Block a user