Skip to content

Instantly share code, notes, and snippets.

@owenb321
Created February 5, 2021 16:36
Show Gist options
  • Save owenb321/3a1caad7bbbfdebaf21a7f56c705fa58 to your computer and use it in GitHub Desktop.
Save owenb321/3a1caad7bbbfdebaf21a7f56c705fa58 to your computer and use it in GitHub Desktop.
Home Assistant sensors used in epaper display
# Automation to publish sensor data to MQTT
- id: publish_epaper_sensors
alias: Publish epaper sensors
initial_state: true
mode: parallel
max: 50
trigger:
- platform: state
entity_id: input_boolean.waveshare_ota_mode
- platform: state
entity_id: input_boolean.waveshare_sleep_mode
- platform: state
entity_id: input_boolean.waveshare_show_qr_code
- platform: state
entity_id: input_boolean.waveshare_show_indoor_temp
- platform: state
entity_id: sensor.openweathermap_temperature
- platform: state
entity_id: sensor.openweathermap_humidity
- platform: state
entity_id: sensor.forecast_high
- platform: state
entity_id: sensor.forecast_low
- platform: state
entity_id: sensor.openweathermap_wind_bearing
- platform: state
entity_id: sensor.openweathermap_wind_speed
- platform: state
entity_id: sensor.rain_daily
- platform: state
entity_id: sensor.current_weather_condition_num
- platform: state
entity_id: sensor.upstairs_average_temperature
- platform: state
entity_id: sensor.downstairs_average_temperature
- platform: state
entity_id: sensor.basement_temperature_sensor
- platform: state
entity_id: sensor.bedroom_humidity_sensor
- platform: state
entity_id: sensor.family_room_humidity_sensor
- platform: state
entity_id: sensor.basement_humidity_sensor
- platform: state
entity_id: sensor.upcoming_event_1_date
- platform: state
entity_id: sensor.upcoming_event_1_name
- platform: state
entity_id: sensor.upcoming_event_1_icon
- platform: state
entity_id: sensor.upcoming_event_2_date
- platform: state
entity_id: sensor.upcoming_event_2_name
- platform: state
entity_id: sensor.upcoming_event_2_icon
- platform: state
entity_id: sensor.upcoming_event_3_date
- platform: state
entity_id: sensor.upcoming_event_3_name
- platform: state
entity_id: sensor.upcoming_event_3_icon
- platform: state
entity_id: sensor.forecast_condition_nums
- platform: state
entity_id: sensor.epaper_notifications
action:
- service: mqtt.publish
data:
topic: 'waveshare_display/input/{{ trigger.entity_id | replace(".","/") }}'
payload_template: '{{ trigger.to_state.state }}'
retain: true
- 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('') }}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment