Created
February 28, 2026 16:30
-
-
Save Flygenring/ce3098065f880cb2c0cff1898622cf84 to your computer and use it in GitHub Desktop.
Home Assistant: Sending, receiving, and using JSON data from a Template Sensor Helper
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
| {% set aggregate = namespace( | |
| id = None, | |
| class = None, | |
| state = None | |
| ) %} | |
| {% set aggregate.id = 'device id' %} | |
| {% set aggregate.class = 'device class' %} | |
| {% set aggregate.state = 'computed state' %} | |
| {% set ns = namespace(instance = { | |
| "id": aggregate.id, | |
| "class": aggregate.class, | |
| "state": aggregate.state | |
| }) %} | |
| {{ ns.instance | to_json(sort_keys=True) }} |
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
| {# Guard unavailable sensor #} | |
| {% if states('sensor.helper_sensor') == 'unavailable' %} | |
| {% set helper_sensor_data = {"id": None, "class": None, "state": None} %} | |
| {% else %} | |
| {% set helper_sensor_data = states('sensor.helper_sensor') | from_json %} | |
| {% endif %} | |
| {##} | |
| <center> | |
| <h3>Device <tt>{{ helper_sensor_data.id }}</tt></h3> | |
| <strong>Device class:</strong> <tt>{{ helper_sensor_data.class }}</tt> | |
| <strong>Device state:</strong> <tt>{{ helper_sensor_data.state }}</tt> | |
| </center> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment