@ -9,12 +9,21 @@ esphome:
priority : 200.0
then:
- component.update : eink_display
- wait_until:
condition:
lambda : 'return id(data_updated) == true;'
# Wait a bit longer so all the items are received
- delay : 5s
- logger.log : "Initial sensor data received: Refreshing display..."
- lambda : 'id(initial_data_received) = true;'
- script.execute : update_screen
esp32:
board : esp32dev
framework:
type : arduino
# Enable logging
logger:
@ -23,6 +32,19 @@ api:
ota:
button:
- platform : shutdown
name : "Weatherman - Shutdown"
- platform : restart
name : "Weatherman - Restart"
- platform : template
name : "Weatherman - Refresh Screen"
entity_category : config
on_press:
- script.execute : update_screen
# Global variables for detecting if the display needs to be refreshed. (Thanks @paviro!)
globals:
- id : data_updated
@ -33,7 +55,21 @@ globals:
type : bool
restore_value : no
initial_value : 'false'
- id : recorded_display_refresh
type : int
restore_value : yes
initial_value : '0'
# Script for updating screen - Refresh display and publish refresh count and time. (Thanks @paviro!)
script:
- id : update_screen
then:
- lambda : 'id(data_updated) = false;'
- component.update : eink_display
- lambda : 'id(recorded_display_refresh) += 1;'
- lambda : 'id(display_last_update).publish_state(id(homeassistant_time).now().timestamp);'
# Check whether the display needs to be refreshed every minute,
# based on whether new data is received or motion is detected. (Thanks @paviro!)
@ -48,15 +84,13 @@ time:
condition:
lambda : 'return id(data_updated) == true;'
then:
- lambda : 'id(initial_data_received) = true;'
- if:
condition:
binary_sensor.is_on : motion_detected
then:
- logger.log : "Sensor data updated and activity in home detected: Refreshing display..."
- component.update : eink_display
- lambda : 'id(data_updated) = false;'
else:
- script.execute : update_screen
else:
- logger.log : "Sensor data updated but no activity in home - skipping display refresh."
else:
- logger.log : "No sensors updated - skipping display refresh."
@ -155,21 +189,36 @@ binary_sensor:
id : motion_detected
# Call Subway and Weather sensors from HA.
sensor:
- platform : template
name : "Weatherman - Display Last Update"
device_class : timestamp
entity_category : "diagnostic"
id : display_last_update
- platform : template
name : "Weatherman - Recorded Display Refresh"
accuracy_decimals : 0
unit_of_measurement : "Refreshs"
state_class : "total_increasing"
entity_category : "diagnostic"
lambda : 'return id(recorded_display_refresh);'
# Call Subway and Weather sensors from HA.
- platform : homeassistant
entity_id : sensor.gtfs_mta_subway_manhattan
id : train_manhattan_due_in
on_value:
then:
- lambda : 'id(data_updated) = true;'
- lambda : 'id(data_updated) = true;'
- platform : homeassistant
entity_id : sensor.gtfs_mta_subway_canarsie
id : train_canarsie_due_in
on_value:
then:
- lambda : 'id(data_updated) = true;'
- lambda : 'id(data_updated) = true;'
- platform : homeassistant
entity_id : sensor.gtfs_mta_subway_manhattan
@ -177,7 +226,7 @@ sensor:
id : train_manhattan_next_train_due_in
on_value:
then:
- lambda : 'id(data_updated) = true;'
- lambda : 'id(data_updated) = true;'
- platform : homeassistant
entity_id : sensor.gtfs_mta_subway_canarsie
@ -185,7 +234,7 @@ sensor:
id : train_canarsie_next_train_due_in
on_value:
then:
- lambda : 'id(data_updated) = true;'
- lambda : 'id(data_updated) = true;'
- platform : homeassistant
entity_id : weather.hourly
@ -193,7 +242,7 @@ sensor:
id : weather_temperature
on_value:
then:
- lambda : 'id(data_updated) = true;'
- lambda : 'id(data_updated) = true;'
- platform : homeassistant
entity_id : sensor.weatherman_data
@ -201,7 +250,7 @@ sensor:
id : weather_temperature_0
on_value:
then:
- lambda : 'id(data_updated) = true;'
- lambda : 'id(data_updated) = true;'
- platform : homeassistant
entity_id : sensor.weatherman_data
@ -209,7 +258,7 @@ sensor:
id : weather_temperature_1
on_value:
then:
- lambda : 'id(data_updated) = true;'
- lambda : 'id(data_updated) = true;'
- platform : homeassistant
entity_id : sensor.weatherman_data
@ -217,7 +266,7 @@ sensor:
id : weather_temperature_2
on_value:
then:
- lambda : 'id(data_updated) = true;'
- lambda : 'id(data_updated) = true;'
- platform : homeassistant
entity_id : sensor.weatherman_data
@ -225,11 +274,12 @@ sensor:
id : weather_temperature_3
on_value:
then:
- lambda : 'id(data_updated) = true;'
- lambda : 'id(data_updated) = true;'
- platform : wifi_signal
name : "WiFi Signal Sensor"
id : wifisignal
entity_category : "diagnostic"
update_interval : 60s
@ -240,7 +290,7 @@ text_sensor:
id : train_manhattan_due_at
on_value:
then:
- lambda : 'id(data_updated) = true;'
- lambda : 'id(data_updated) = true;'
- platform : homeassistant
entity_id : sensor.gtfs_mta_subway_canarsie
@ -248,7 +298,7 @@ text_sensor:
id : train_canarsie_due_at
on_value:
then:
- lambda : 'id(data_updated) = true;'
- lambda : 'id(data_updated) = true;'
- platform : homeassistant
entity_id : sensor.gtfs_mta_subway_manhattan
@ -256,7 +306,7 @@ text_sensor:
id : train_manhattan_next_train_due_at
on_value:
then:
- lambda : 'id(data_updated) = true;'
- lambda : 'id(data_updated) = true;'
- platform : homeassistant
entity_id : sensor.gtfs_mta_subway_canarsie
@ -264,14 +314,14 @@ text_sensor:
id : train_canarsie_next_train_due_at
on_value:
then:
- lambda : 'id(data_updated) = true;'
- lambda : 'id(data_updated) = true;'
- platform : homeassistant
entity_id : weather.valhalla_hourly
id : weather_state
on_value:
then:
- lambda : 'id(data_updated) = true;'
- lambda : 'id(data_updated) = true;'
- platform : homeassistant
entity_id : sensor.weatherman_data
@ -279,63 +329,63 @@ text_sensor:
id : weather_condition_now
on_value:
then:
- lambda : 'id(data_updated) = true;'
- lambda : 'id(data_updated) = true;'
- platform : homeassistant
entity_id : sensor.weatherman_data
attribute : weather_condition_0
id : weather_condition_0
on_value:
then:
- lambda : 'id(data_updated) = true;'
- lambda : 'id(data_updated) = true;'
- platform : homeassistant
entity_id : sensor.weatherman_data
attribute : weather_timestamp_0
id : weather_timestamp_0
on_value:
then:
- lambda : 'id(data_updated) = true;'
- lambda : 'id(data_updated) = true;'
- platform : homeassistant
entity_id : sensor.weatherman_data
attribute : weather_condition_1
id : weather_condition_1
on_value:
then:
- lambda : 'id(data_updated) = true;'
- lambda : 'id(data_updated) = true;'
- platform : homeassistant
entity_id : sensor.weatherman_data
attribute : weather_timestamp_1
id : weather_timestamp_1
on_value:
then:
- lambda : 'id(data_updated) = true;'
- lambda : 'id(data_updated) = true;'
- platform : homeassistant
entity_id : sensor.weatherman_data
attribute : weather_condition_2
id : weather_condition_2
on_value:
then:
- lambda : 'id(data_updated) = true;'
- lambda : 'id(data_updated) = true;'
- platform : homeassistant
entity_id : sensor.weatherman_data
attribute : weather_timestamp_2
id : weather_timestamp_2
on_value:
then:
- lambda : 'id(data_updated) = true;'
- lambda : 'id(data_updated) = true;'
- platform : homeassistant
entity_id : sensor.weatherman_data
attribute : weather_condition_3
id : weather_condition_3
on_value:
then:
- lambda : 'id(data_updated) = true;'
- lambda : 'id(data_updated) = true;'
- platform : homeassistant
entity_id : sensor.weatherman_data
attribute : weather_timestamp_3
id : weather_timestamp_3
on_value:
then:
- lambda : 'id(data_updated) = true;'
- lambda : 'id(data_updated) = true;'
- platform : homeassistant
entity_id : sensor.weatherman_data
@ -343,21 +393,21 @@ text_sensor:
id : train_status
on_value:
then:
- lambda : 'id(data_updated) = true;'
- lambda : 'id(data_updated) = true;'
- platform : homeassistant
entity_id : sensor.weatherman_data
attribute : train_status_manhattan
id : train_status_manhattan
on_value:
then:
- lambda : 'id(data_updated) = true;'
- lambda : 'id(data_updated) = true;'
- platform : homeassistant
entity_id : sensor.weatherman_data
attribute : train_status_canarsie
id : train_status_canarsie
on_value:
then:
- lambda : 'id(data_updated) = true;'
- lambda : 'id(data_updated) = true;'
# Define colors
@ -481,6 +531,13 @@ display:
it.printf(330, 652, id(font_medium_bold), color_text, TextAlign::TOP_CENTER, "%2.0f MIN", id(train_canarsie_next_train_due_in).state);
it.printf(150, 684, id(font_small_book), color_text, TextAlign::TOP_CENTER, "%s", id(train_manhattan_next_train_due_at).state.c_str());
it.printf(330, 684, id(font_small_book), color_text, TextAlign::TOP_CENTER, "%s", id(train_canarsie_next_train_due_at).state.c_str());
// Refresh Timestamp
// Code by EnsconcE from https://community.home-assistant.io/t/esphome-show-time/348903
char str[17];
time_t currTime = id(homeassistant_time).now().timestamp;
strftime(str, sizeof(str), "%H:%M", localtime(&currTime));
it.printf(240, 710, id(font_small_book), color_text, TextAlign::TOP_CENTER, "REFRESHED AT %s", str);
}
captive_portal: