- platform: template sensors: upcoming_events: value_template: >- {%- set holidays = [ { "date": "01-01", "name": "New Year's Day", "icon":"party-popper" }, { "date": "01-17", "name": "MLK Jr. Day", "icon":"microphone" }, { "date": "02-07", "name": "Super Bowl", "icon":"football" }, { "date": "02-14", "name": "Valentine's Day", "icon":"heart" }, { "date": "03-14", "name": "Daylight Saving", "icon":"history" }, { "date": "03-17", "name": "St Patrick's Day", "icon":"clover" }, { "date": "04-04", "name": "Easter", "icon":"egg-easter" }, { "date": "05-05", "name": "Cinco de Mayo", "icon":"taco" }, { "date": "05-09", "name": "Mother's Day", "icon":"mother-heart" }, { "date": "05-31", "name": "Memorial Day", "icon":"shield-star" }, { "date": "06-04", "name": "Anniversary", "icon":"heart-multiple" }, { "date": "06-19", "name": "Juneteenth", "icon":"star" }, { "date": "06-20", "name": "Father's Day", "icon":"mustache" }, { "date": "07-04", "name": "Independence Day", "icon":"flag" }, { "date": "09-06", "name": "Labor Day", "icon":"shovel" }, { "date": "10-31", "name": "Halloween", "icon":"halloween" }, { "date": "11-07", "name": "Daylight Saving", "icon":"history2" }, { "date": "11-11", "name": "Veterans Day", "icon":"shield-star" }, { "date": "11-25", "name": "Thanksgiving", "icon":"turkey" }, { "date": "12-25", "name": "Christmas", "icon":"pine-tree" } ] %} {% set birthdays = [ { "date": "02-09", "name": "MC's Birthday", "icon":"cake-variant" } ] %} {%- set data = namespace(events=[]) %} {%- set limit = 3 %} {%- for event in ((holidays + birthdays) | sort(attribute='date')) %} {%- if event.date >= now().strftime("%m-%d") %} {%- set data.events = data.events + [event | to_json] %} {%- endif %} {%- endfor %} {%- for event in ((holidays + birthdays) | sort(attribute='date')) %} {%- set data.events = data.events + [event | to_json] %} {%- endfor -%} [{{ data.events[:limit] | join(',') }}] upcoming_event_1_date: value_template: "{{ (states('sensor.upcoming_events') | from_json)[0].date }}" upcoming_event_1_name: value_template: "{{ (states('sensor.upcoming_events') | from_json)[0].name }}" upcoming_event_1_icon: value_template: "{{ (states('sensor.upcoming_events') | from_json)[0].icon }}" upcoming_event_2_date: value_template: "{{ (states('sensor.upcoming_events') | from_json)[1].date }}" upcoming_event_2_name: value_template: "{{ (states('sensor.upcoming_events') | from_json)[1].name }}" upcoming_event_2_icon: value_template: "{{ (states('sensor.upcoming_events') | from_json)[1].icon }}" upcoming_event_3_date: value_template: "{{ (states('sensor.upcoming_events') | from_json)[2].date }}" upcoming_event_3_name: value_template: "{{ (states('sensor.upcoming_events') | from_json)[2].name }}" upcoming_event_3_icon: value_template: "{{ (states('sensor.upcoming_events') | from_json)[2].icon }}" # Generates a string of 1s and 0s to indicate binary status epaper_notifications: value_template: >- {{ [ ((is_state("binary_sensor.garbage_type_trash", "on") and now().weekday() in [0,1]) | int), ((is_state("binary_sensor.garbage_type_bulky", "on") and now().weekday() in [0,1]) | int), ((is_state("binary_sensor.garbage_type_recycling", "on") and now().weekday() in [0,1]) | int), (is_state("input_boolean.vacuum_dustbin_full", "on")|int), (is_state("sensor.washing_machine", "Idle")|int), (is_state("sensor.dishwasher", "Clean")|int), (is_state("sensor.dog_bowl_level", "0")|int), (is_state("binary_sensor.internet_connectivity", "off")|int), ] | join('') }} # Weather condition number corresponds with icon array index in esphome current_weather_condition_num: value_template: >- {% set condition_map = { "clear-night": 0, "cloudy": 1, "exceptional": 2, "fog": 3, "hail": 4, "lightning-rainy": 5, "lightning": 6, "partlycloudy": 7 if is_state('sun.sun', 'above_horizon') else 8, "pouring": 9, "rainy": 10, "snowy-rainy": 11, "snowy": 12, "sunny": 13, "windy-variant": 14, "windy": 15 } %} {{ condition_map[states('weather.openweathermap')] }} # Map weather conditions to numbers and concatenate to get next 6 hours forecast_condition_nums: value_template: >- {% set condition_map = { "clear-night": "00", "cloudy": "01", "exceptional": "02", "fog": "03", "hail": "04", "lightning-rainy": "05", "lightning": "06", "partlycloudy": "07" if is_state('sun.sun', 'above_horizon') else "08", "pouring": "09", "rainy": "10", "snowy-rainy": "11", "snowy": "12", "sunny": "13", "windy-variant": "14", "windy": "15" } %} {%- set data = namespace(conditions=[]) %} {% for condition in (state_attr('weather.openweathermap', 'forecast')[1:7] | map(attribute="condition") | list) -%} {% set data.conditions = data.conditions + [condition_map[condition]] %} {% endfor %} {{ data.conditions | join('') }}