Created
March 16, 2026 14:22
-
-
Save qguv/2b5cd3c106bb69d1ea4d8c62bd95f8c2 to your computer and use it in GitHub Desktop.
Home Assistant: get source of all template sensors
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python3 | |
| ''' | |
| Get source of all template sensors. | |
| Assumes SSH to Home Assistant is set up as `Host homeassistant` on your local machine's SSH config. | |
| ''' | |
| from subprocess import check_call | |
| from tempfile import TemporaryDirectory | |
| from pathlib import Path | |
| import json | |
| def get_config_entries(): | |
| with TemporaryDirectory() as d: | |
| config_entries_path = Path(d) / 'core.config_entries' | |
| check_call(['scp', 'homeassistant:/root/config/.storage/core.config_entries', str(config_entries_path)]) | |
| with config_entries_path.open('r') as f: | |
| return json.load(f) | |
| def get_templates(config_entries): | |
| return [ | |
| [x["options"]["name"], x["options"]["state"]] | |
| for x in config_entries['data']['entries'] | |
| if x['domain'] == 'template' | |
| ] | |
| for name, state in get_templates(get_config_entries()): | |
| print('-' * len(name)) | |
| print(name) | |
| print('-' * len(name)) | |
| print(state) | |
| print() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment