-
Star
(165)
You must be signed in to star a gist -
Fork
(25)
You must be signed in to fork a gist
-
-
Save EverythingSmartHome/13f14c328669f72eee717752069a0398 to your computer and use it in GitHub Desktop.
| {{ states.binary_sensor | |
| | selectattr('attributes.device_class', 'in', ['door','window']) | |
| | selectattr('state', 'equalto', 'on') | |
| | list | count }} |
| {% set AREAS = ['kitchen','office','bedroom','living room'] %} | |
| {% set DOMAIN = 'light' %} | |
| {% set ns = namespace(ids=[]) %} | |
| {% for a in AREAS %} | |
| {% set ns.ids = ns.ids + area_entities(a) %} | |
| {% endfor %} | |
| {{ expand(ns.ids|unique) | |
| | selectattr('domain','equalto', DOMAIN) | |
| | selectattr('state','equalto','on') | |
| | list | count }} |
| # Security 🔏 | |
| {% if states.sensor.open_doors_and_windows.state | int > 0 %} | |
| You have {{states.sensor.open_doors_and_windows.state}} doors/windows open. | |
| {% else %} | |
| All windows and doors are closed. | |
| {% endif %} |
| ## Lights 💡 | |
| You have {{states.sensor.kitchen_light_count.state}} lights on currently. |
| {% set area_id = 'kitchen' %} | |
| {% set ents = expand(area_entities(area_id)) %} | |
| {% set lights = ents | |
| | selectattr('domain', 'equalto', 'media_player') | |
| | selectattr('state', 'equalto', 'playing') %} | |
| {{ lights | list | count }} |
| {% set area_id = 'kitchen' %} | |
| {% set ents = expand(area_entities(area_id)) %} | |
| {% set switch = ents | |
| | selectattr('domain', 'equalto', 'switch') | |
| | selectattr('state', 'equalto', 'on') %} | |
| {{ switch | list | count }} |
| {% set time = now().hour %} | |
| {% if time >= 5 and time < 12 %} | |
| {% set greeting = 'Good morning' %} | |
| {% elif time >= 12 and time < 17 %} | |
| {% set greeting = 'Good afternoon' %} | |
| {% elif time >= 17 and time < 24 %} | |
| {% set greeting = 'Good evening' %} | |
| {% elif time >= 0 and time < 5 %} | |
| {% set greeting = 'You should be sleeping' %} | |
| {% endif %} | |
| # {{greeting}}, {{user}}! |
| {% set time = now().hour %} | |
| {% if time >= 5 and time < 12 %} | |
| {% set greeting = 'Good morning' %} | |
| {% elif time >= 12 and time < 17 %} | |
| {% set greeting = 'Good afternoon' %} | |
| {% elif time >= 17 and time < 24 %} | |
| {% set greeting = 'Good evening' %} | |
| {% elif time >= 0 and time < 5 %} | |
| {% set greeting = 'You should be sleeping' %} | |
| {% endif %} | |
| {% if state_attr('calendar.lewis_s_calendar', 'start_time') == None %} | |
| {% set cal_message = "you have no upcoming events, enjoy 🥳"%} | |
| {% else %} | |
| {% set start_time = state_attr('calendar.lewis_s_calendar', 'start_time') | as_timestamp | timestamp_custom("%H:%M", false) %} | |
| {% set cal_message = "your next event is at " + start_time %} | |
| {% endif %} | |
| # {{greeting}}, {{user}}! | |
| It's {{now().hour}}:{{now().minute}} and {{cal_message}}. |
I'd like to share a small change I made to the "light on count template"
In my version, I simply use all available areas via areas(). Since I don't have that many devices yet, iterating over the whole house is fine for my setup.
Most of my devices are connected via Zigbee2MQTT, and I added an availability check there. We sometimes turn off lights using the physical wall switch, which means Home Assistant may still think the light is "on" even though it is actually off.
Without the additional line, the counter is always wrong (in my case)
I also added the Line of @ccitro
For the Light On Count, you can exclude hidden entities like this ...
| rejectattr('entity_id', 'is_hidden_entity')
My updated Code:
{% set AREAS = areas() %}
{% set DOMAIN = 'light' %}
{% set ns = namespace(ids=[]) %}
{% for a in AREAS %}
{% set ns.ids = ns.ids + area_entities(a) %}
{% endfor %}
{{ expand(ns.ids|unique)
| selectattr('domain','equalto', DOMAIN)
| selectattr('state','equalto','on')
| rejectattr('entity_id', 'is_hidden_entity')
| rejectattr('state', 'equalto', 'unavailable')
| list
| count
}}
Replacing line 21 of Welcome message with calendar event solves the issue where minute values < 10 are displayed as single integers with no leading 0:
It's {{ now().strftime("%H:%M") }} and {{ cal_message }}.
Thank you!
or state_attr('calendar.lewis_s_calendar', 'start_time') | as_datetime | as_local > today_at('00:00:00') %}
Thank you!
@reubendowle man, that saved the day. took my home assistant from using 20 % cpu and 20 GB of ram and crashing intermittently and sluggish to fast again, using 3.9% cpu and 9 GB of ram. Thanks!