Skip to content

Commit

Permalink
Guarantee default value is available
Browse files Browse the repository at this point in the history
Without calculating a valid default value, template processing still generates errors, even when the availability template shows that the sensor value is unavailable.
  • Loading branch information
JRInge committed Jul 15, 2024
1 parent 20fe2d8 commit b6d4791
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/co2_sensors.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ co2_sensors:
availability: &avail_test |-
{{ value_json is not undefined and value_json.data is not undefined
and value_json.error is undefined }}
value_template: '{{ value_json.data }}'
value_template: '{{ value_json.data | default(0) }}'
- platform: rest
name: "Carbon Tracer Grid energy mix"
unique_id: 1677706464
Expand Down Expand Up @@ -78,6 +78,6 @@ co2_sensors:
+ state_attr('sensor.carbon_tracer_grid_energy_mix',
'Gas Turbine') | default(0, true)) / ns.sum) | round(2) }}
{% else %}
unknown
0
{% endif %}
...

0 comments on commit b6d4791

Please sign in to comment.