mirror of
https://github.com/house-of-abbey/GarminHomeAssistant.git
synced 2025-04-30 20:52:27 +00:00
Update Templates.md
Examples now up to date with schema changes.
This commit is contained in:
@ -16,7 +16,6 @@ In this example we get the battery level of the device and add the percent sign.
|
|||||||
|
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
"entity": "sensor.<device>_battery_level",
|
|
||||||
"name": "Phone",
|
"name": "Phone",
|
||||||
"type": "template",
|
"type": "template",
|
||||||
"content": "{{ states('sensor.<device>_battery_level') }}%"
|
"content": "{{ states('sensor.<device>_battery_level') }}%"
|
||||||
@ -29,19 +28,16 @@ The first two keep to the simple proposal above. The last combines them into a s
|
|||||||
|
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
"entity": "sensor.hallway_temperature",
|
|
||||||
"name": "Hall Temp",
|
"name": "Hall Temp",
|
||||||
"type": "template",
|
"type": "template",
|
||||||
"content": "{{ states('sensor.hallway_temperature') }}°C"
|
"content": "{{ states('sensor.hallway_temperature') }}°C"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"entity": "sensor.hallway_humidity",
|
|
||||||
"name": "Hall Humidity",
|
"name": "Hall Humidity",
|
||||||
"type": "template",
|
"type": "template",
|
||||||
"content": "{{ states('sensor.hallway_humidity') }}%"
|
"content": "{{ states('sensor.hallway_humidity') }}%"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"entity": "sensor.hallway_temperature",
|
|
||||||
"name": "Hallway",
|
"name": "Hallway",
|
||||||
"type": "template",
|
"type": "template",
|
||||||
"content": "{{ states('sensor.hallway_temperature') }}°C {{ states('sensor.hallway_humidity') }}%"
|
"content": "{{ states('sensor.hallway_temperature') }}°C {{ states('sensor.hallway_humidity') }}%"
|
||||||
@ -61,16 +57,16 @@ In order to keep the formatting of floating point numbers under control, you mig
|
|||||||
Where your device supports unicode characters these example may work.
|
Where your device supports unicode characters these example may work.
|
||||||
|
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
"name": "Charge",
|
"name": "Charge",
|
||||||
"type": "template",
|
"type": "template",
|
||||||
"content": "☎ {{ states('sensor.my_phone_battery_level') }}%{% if is_state('binary_sensor.my_phone_is_charging', 'on') %}⚡{% endif %}, ⏳ {{ '%.0f'|format(states('sensor.my_watch_battery_level') | float) }}%{% if is_state('binary_binary_sensor.my_watch_battery_is_charging', 'on') %}⚡{% endif %}"
|
"content": "☎ {{ states('sensor.my_phone_battery_level') }}%{% if is_state('binary_sensor.my_phone_is_charging', 'on') %}⚡{% endif %}, ⏳ {{ '%.0f'|format(states('sensor.my_watch_battery_level') | float) }}%{% if is_state('binary_binary_sensor.my_watch_battery_is_charging', 'on') %}⚡{% endif %}"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "Hallway",
|
"name": "Hallway",
|
||||||
"type": "template",
|
"type": "template",
|
||||||
"content": "🌡{% if is_state('sensor.hallway_temperature', 'unavailable') %}-{% else %}{{ '%.1f'|format(states('sensor.hallway_temperature')|float) }}°C{% if is_state_attr('climate.hallway', 'hvac_action', 'heating') or is_state_attr('climate.hallway', 'hvac_action', 'preheating') -%}🔥{%- endif %}{% endif %}, 💧{% if is_state('sensor.hallway_humidity', 'unavailable') %}-{% else %}{{ '%.1f'|format(states('sensor.hallway_humidity')|float) }}%{% endif %}"
|
"content": "🌡{% if is_state('sensor.hallway_temperature', 'unavailable') %}-{% else %}{{ '%.1f'|format(states('sensor.hallway_temperature')|float) }}°C{% if is_state_attr('climate.hallway', 'hvac_action', 'heating') or is_state_attr('climate.hallway', 'hvac_action', 'preheating') -%}🔥{%- endif %}{% endif %}, 💧{% if is_state('sensor.hallway_humidity', 'unavailable') %}-{% else %}{{ '%.1f'|format(states('sensor.hallway_humidity')|float) }}%{% endif %}"
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||

|

|
||||||
@ -83,7 +79,6 @@ In this example we get the battery level of the device and add the percent sign.
|
|||||||
|
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
"entity": "sensor.<device>_battery_level",
|
|
||||||
"name": "Phone",
|
"name": "Phone",
|
||||||
"type": "template",
|
"type": "template",
|
||||||
"content": "{{ states('sensor.<device>_battery_level') }}%{% if is_state('binary_sensor.<device>_is_charging', 'on') %}+{% endif %}"
|
"content": "{{ states('sensor.<device>_battery_level') }}%{% if is_state('binary_sensor.<device>_is_charging', 'on') %}+{% endif %}"
|
||||||
@ -94,13 +89,32 @@ Here we also use the else clause as well to give proper text instead of just `on
|
|||||||
|
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
"entity": "binary_sensor.garage_doors",
|
|
||||||
"name": "Garage Doors",
|
"name": "Garage Doors",
|
||||||
"type": "template",
|
"type": "template",
|
||||||
"content": "{% if is_state('binary_sensor.<door-0>', 'on') %}Open{% else %}Closed{% endif %} {% if is_state('binary_sensor.<door-1>', 'on') %}Open{% else %}Closed{% endif %}"
|
"content": "{% if is_state('binary_sensor.<door-0>', 'on') %}Open{% else %}Closed{% endif %} {% if is_state('binary_sensor.<door-1>', 'on') %}Open{% else %}Closed{% endif %}"
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
> [!IMPORTANT]
|
||||||
|
> We advise users against adding security devices.
|
||||||
|
|
||||||
|
However, users are doing this **against our advice** and asking how to operate 'covers'. This is an example of toggling a garage door open and closed with confirmation. *Do this at your own risk*.
|
||||||
|
|
||||||
|
Note: Only when you use the `tap_action` field do you also need to include the `entity` field. This is a change to a previous version of the application, hence the presence of the `entity` field will be ignored for backwards compatibility, and the schema will provide a warning only.
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"entity": "cover.garage_door",
|
||||||
|
"name": "Garage Door",
|
||||||
|
"type": "template",
|
||||||
|
"content": "{% if is_state('binary_sensor.garage_connected', 'on') %}{{state_translated('cover.garage_door')}} - {{state_attr('cover.garage_door', 'current_position')}}%{%else%}Unconnected{% endif %}",
|
||||||
|
"tap_action": {
|
||||||
|
"service": "cover.toggle",
|
||||||
|
"confirm": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
## Advanced
|
## Advanced
|
||||||
|
|
||||||
Here we generate a bar graph of the battery level. We use the following steps to do this:
|
Here we generate a bar graph of the battery level. We use the following steps to do this:
|
||||||
@ -114,7 +128,6 @@ Here we generate a bar graph of the battery level. We use the following steps to
|
|||||||
|
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
"entity": "sensor.<device>_battery_level",
|
|
||||||
"name": "Phone",
|
"name": "Phone",
|
||||||
"type": "template",
|
"type": "template",
|
||||||
"content": "{{ states('sensor.<device>_battery_level') }}%{% if is_state('binary_sensor.<device>_is_charging', 'on') %}+{% endif %} {{ '#' * (((states('sensor.<device>_battery_level') | int) / 100 * <width>) | int) }}{{ '_' * (<width> - (((states('sensor.<device>_battery_level') | int) / 100 * <width>) | int)) }}"
|
"content": "{{ states('sensor.<device>_battery_level') }}%{% if is_state('binary_sensor.<device>_is_charging', 'on') %}+{% endif %} {{ '#' * (((states('sensor.<device>_battery_level') | int) / 100 * <width>) | int) }}{{ '_' * (<width> - (((states('sensor.<device>_battery_level') | int) / 100 * <width>) | int)) }}"
|
||||||
@ -125,11 +138,10 @@ An example of a dimmer light with 4 brightness settings 0..3. Here our light wor
|
|||||||
|
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
"$schema": "./schema.json",
|
"$schema": "https://raw.githubusercontent.com/house-of-abbey/GarminHomeAssistant/main/config.schema.json",
|
||||||
"title": "Home",
|
"title": "Home",
|
||||||
"items": [
|
"items": [
|
||||||
{
|
{
|
||||||
"entity": "light.green_house",
|
|
||||||
"name": "LEDs",
|
"name": "LEDs",
|
||||||
"type": "template",
|
"type": "template",
|
||||||
"content": "{% if not (is_state('light.green_house', 'off') or is_state('light.green_house', 'unavailable')) %}{{ (((state_attr('light.green_house', 'brightness') | float) / 255 * 100) | round(0)) | int }}%{% else %}Off{% endif %}"
|
"content": "{% if not (is_state('light.green_house', 'off') or is_state('light.green_house', 'unavailable')) %}{{ (((state_attr('light.green_house', 'brightness') | float) / 255 * 100) | round(0)) | int }}%{% else %}Off{% endif %}"
|
||||||
@ -187,4 +199,4 @@ An example of a dimmer light with 4 brightness settings 0..3. Here our light wor
|
|||||||
|
|
||||||
## Warnings
|
## Warnings
|
||||||
|
|
||||||
Just remember, **you have the ability to crash the application by creating an excessive menu definition**. Templates can require significant definition for highly customised text. Don't be silly.
|
Just remember, on older smaller memory devices **you have the ability to crash the application by creating an excessive menu definition**. Templates can require significant definition for highly customised text. Don't be silly.
|
||||||
|
Reference in New Issue
Block a user