Quick Links:
Discussion Communities:
Reference:
Main docs: https://www.home-assistant.io/docs
Useful:
Split Configuration - File structure options to keep config data organized: splitting_configuration
Store Secrets - how to keep PII out of the configuration: create a secrets file
Templating: https://www.home-assistant.io/docs/configuration/templating/
Database Mgmt:
SELECT
date_trunc('hour', last_updated),
count(1)
FROM
states
WHERE
last_updated > now() - interval '3 day'
GROUP BY
1
events
& states
tables to confirm HA is purging the DB as per the purge_keep_days
value:
SELECT
event_id,
created
FROM
events
ORDER BY
created
LIMIT 10;
SELECT nspname || '.' || relname AS "relation",
pg_size_pretty(pg_total_relation_size(C.oid)) AS "total_size"
FROM pg_class C
LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace)
WHERE nspname NOT IN ('pg_catalog', 'information_schema')
AND C.relkind <> 'i'
AND nspname !~ '^pg_toast'
ORDER BY pg_total_relation_size(C.oid) DESC
LIMIT 5;
SELECT
relname,
indexrelname,
idx_scan,
idx_tup_read,
idx_tup_fetch,
pg_size_pretty(pg_relation_size(indexrelname::regclass)) as size
FROM
pg_stat_all_indexes
WHERE
schemaname = 'public'
AND indexrelname NOT LIKE 'pg_toast_%'
AND idx_scan = 0
AND idx_tup_read = 0
AND idx_tup_fetch = 0
ORDER BY
pg_relation_size(indexrelname::regclass) DESC;
Components used in default config: https://www.home-assistant.io/integrations/default_config/
Reference Configs:
Templating in Home Assistant
To automatically generate a list of all existing entities (drop this into /developer-tools/template):
{%- for state in states -%}
{{state.entity_id}}
{% endfor %}
Formatting: Currency (US) - to display ex. $10.00
in HA lovalace
- platform: template
sensors:
weekly_allowance:
friendly_name: "allowance"
value_template: >-
{% set amt = states("input_number.allowance_total") | float %}
{% if amt >0 %}
{% set total = amt %}
{% else %}
{% set total = 0 %}
{% endif %}
{{ '${:,.2f}'.format(float(total)) }}
Formatting: Time - to display the length of time something has been on, ex. 1h 23m
- platform: template
sensors:
office_tv_time_today:
friendly_name: "Office TV"
value_template: >-
{% set duration = states("sensor.office_tv_time_on") | float %}
{%- set seconds = (duration * 3600) %}
{%- set minutes = ((seconds % 3600) // 60) | int %}
{%- set minutes = '{}m'.format(minutes) if minutes > 0 else '' %}
{%- set hours = ((seconds % 86400) // 3600) | int %}
{%- set hours = '{}h '.format(hours) if hours > 0 else '' %}
{{ '0m' if seconds < 60 else hours + minutes }}
HA’s sun integration uses your location to calulate sunrise & sunset times each day. This can be used to calculate daylight hours. Note each calendar day (24hrs.) has 86400 seconds.
- platform: template
sensors:
daylight_hours_today:
friendly_name: 'Daylight hours today'
value_template: >
{% set sunrise = as_timestamp(state_attr('sun.sun','next_rising')) %}
{% set sunset = as_timestamp(state_attr('sun.sun','next_setting')) %}
{% set midnight = as_timestamp(state_attr('sun.sun','next_midnight')) %}
{% if midnight < sunset %}
{% set sunrise = (sunrise - 86328.5) %}
{% set sunset = (sunset - 86471.5) %}
{% endif %}
{% if sunrise > sunset %}
{% set sunrise = (sunrise - 86328.5) %}
{% endif %}
{{ (sunset - sunrise)|timestamp_custom('%H:%M',false) }}
icon_template: mdi:weather-sunny
My Environment:
I am using a QNAP TS-253A NAS with 4GB RAM to run Home Assistant Core in Docker along with 12+ other containers (the available RAM is just enough). A list of the other containers I am using is here or more information can be found on other pages of this site.
HA Inventory - current integrations & other packages