Code of Template #2 for "mini-graph-card"
(inside a "decluttering_templates"
section):
decl_graph_tmpl:
default: &decl_graph_tmpl_default
- tmpl_VALUE_GRAPH_TYPE: line
- tmpl_VALUE_SHOW_NAME: true
- tmpl_VALUE_SHOW_FILL: true
- tmpl_INPUT_SHOW_POINTS: input_boolean.service_false_value
- tmpl_INPUT_SHOW_EXTREMA: input_boolean.service_false_value
- tmpl_INPUT_SHOW_AVERAGE: input_boolean.service_false_value
- tmpl_VALUE_SHOW_LABELS: true
- tmpl_VALUE_TITLE: ''
- tmpl_VALUE_STATE_ADAPTIVE_COLOR: false
- tmpl_VALUE_HEIGHT: 100
- tmpl_VALUE_POINTS_PER_HOUR: 60
- tmpl_VALUE_UPDATE_INTERVAL: 0
- tmpl_VALUE_AGGREGATE_FUNC: last
- tmpl_VALUE_GROUP_BY: interval
- tmpl_VALUE_STATE_MAP: []
- tmpl_VALUE_LOWER_BOUND: ~0
- tmpl_VALUE_SHOW_LEGEND: false
- tmpl_INPUT_REALTIME: input_boolean.service_true_value
- tmpl_VALUE_COLOR_THRESHOLDS: []
- tmpl_VALUE_COLOR_THRESHOLDS_TRANSITION: smooth
- tmpl_VALUE_COMPACT_MIN_MAX_AVG_INFO: false
############################################################
- tmpl_VALUE_SHOW_GRAPH: true
- tmpl_VALUE_SHOW_STATE: true
- tmpl_VALUE_LINE_COLOR: green
############################################################
- tmpl_SENSOR_2: sensor.service_zero_value
- tmpl_VALUE_NAME_2: ''
- tmpl_VALUE_SHOW_GRAPH_2: false
- tmpl_VALUE_SHOW_STATE_2: false
- tmpl_VALUE_LINE_COLOR_2: orange
############################################################
- tmpl_SENSOR_3: sensor.service_zero_value
- tmpl_VALUE_NAME_3: ''
- tmpl_VALUE_SHOW_GRAPH_3: false
- tmpl_VALUE_SHOW_STATE_3: false
- tmpl_VALUE_LINE_COLOR_3: magenta
############################################################
- tmpl_SENSOR_4: sensor.service_zero_value
- tmpl_VALUE_NAME_4: ''
- tmpl_VALUE_SHOW_GRAPH_4: false
- tmpl_VALUE_SHOW_STATE_4: false
- tmpl_VALUE_LINE_COLOR_4: blue
############################################################
- tmpl_SENSOR_5: sensor.service_zero_value
- tmpl_VALUE_NAME_5: ''
- tmpl_VALUE_SHOW_GRAPH_5: false
- tmpl_VALUE_SHOW_STATE_5: false
- tmpl_VALUE_LINE_COLOR_5: pink
############################################################
- tmpl_SENSOR_6: sensor.service_zero_value
- tmpl_VALUE_NAME_6: ''
- tmpl_VALUE_SHOW_GRAPH_6: false
- tmpl_VALUE_SHOW_STATE_6: false
- tmpl_VALUE_LINE_COLOR_6: violet
############################################################
- tmpl_SENSOR_BACK: sensor.service_zero_value
- tmpl_VALUE_NAME_BACK: ''
- tmpl_INPUT_SHOW_GRAPH_BACK: input_boolean.service_false_value
- tmpl_VALUE_LINE_COLOR_BACK: 'rgba(50,73,92,0.5)'
############################################################
- tmpl_SENSOR_BACK_2: sensor.service_zero_value
- tmpl_VALUE_NAME_BACK_2: ''
- tmpl_INPUT_SHOW_GRAPH_BACK_2: input_boolean.service_false_value
- tmpl_VALUE_LINE_COLOR_BACK_2: 'rgba(255,0,0,0.5)'
############################################################
- tmpl_SENSOR_X_AXIS: sensor.servicewithhistory_zero_value
- tmpl_VALUE_SHOW_GRAPH_X_AXIS: false
- tmpl_VALUE_LINE_COLOR_X_AXIS: 'rgb(255,0,0)'
card: &decl_graph_tmpl_card
type: custom:config-template-card
variables: &decl_graph_variables
varTHEME_DARK_MODE: 'states[''input_boolean.theme_dark_mode''].state'
varINPUT_HOURS_TO_SHOW: 'states[''[[tmpl_INPUT_HOURS_TO_SHOW]]'']'
varINPUT_SHOW_EXTREMA: 'states[''[[tmpl_INPUT_SHOW_EXTREMA]]'']'
varINPUT_SHOW_AVERAGE: 'states[''[[tmpl_INPUT_SHOW_AVERAGE]]'']'
varINPUT_SHOW_POINTS: 'states[''[[tmpl_INPUT_SHOW_POINTS]]'']'
varSENSOR: >-
states['[[tmpl_INPUT_REALTIME]]'].state === "on" ? '[[tmpl_SENSOR]]' :
"sensor.service_zero_value"
varINPUT_SHOW_GRAPH_BACK: 'states[''[[tmpl_INPUT_SHOW_GRAPH_BACK]]'']'
varINPUT_SHOW_GRAPH_BACK_2: 'states[''[[tmpl_INPUT_SHOW_GRAPH_BACK_2]]'']'
varSENSOR_BACK: >-
states['[[tmpl_INPUT_REALTIME]]'].state === "on" ?
'[[tmpl_SENSOR_BACK]]' : "sensor.service_zero_value"
varSENSOR_BACK_2: >-
states['[[tmpl_INPUT_REALTIME]]'].state === "on" ?
'[[tmpl_SENSOR_BACK_2]]' : "sensor.service_zero_value"
varSENSOR_2: >-
states['[[tmpl_INPUT_REALTIME]]'].state === "on" ? '[[tmpl_SENSOR_2]]'
: "sensor.service_zero_value"
varSENSOR_3: >-
states['[[tmpl_INPUT_REALTIME]]'].state === "on" ? '[[tmpl_SENSOR_3]]'
: "sensor.service_zero_value"
varSENSOR_4: >-
states['[[tmpl_INPUT_REALTIME]]'].state === "on" ? '[[tmpl_SENSOR_4]]'
: "sensor.service_zero_value"
varSENSOR_5: >-
states['[[tmpl_INPUT_REALTIME]]'].state === "on" ? '[[tmpl_SENSOR_5]]'
: "sensor.service_zero_value"
varSENSOR_6: >-
states['[[tmpl_INPUT_REALTIME]]'].state === "on" ? '[[tmpl_SENSOR_6]]'
: "sensor.service_zero_value"
entities: &decl_graph_tmpl_entities
- '[[tmpl_INPUT_HOURS_TO_SHOW]]'
- '[[tmpl_INPUT_SHOW_EXTREMA]]'
- '[[tmpl_INPUT_SHOW_AVERAGE]]'
- '[[tmpl_INPUT_SHOW_POINTS]]'
- '[[tmpl_INPUT_REALTIME]]'
- '${varSENSOR}'
- '${varSENSOR_2}'
- '${varSENSOR_3}'
- '${varSENSOR_4}'
- '${varSENSOR_5}'
- '${varSENSOR_6}'
- '${varSENSOR_BACK}'
- '[[tmpl_INPUT_SHOW_GRAPH_BACK]]'
- '${varSENSOR_BACK_2}'
- '[[tmpl_INPUT_SHOW_GRAPH_BACK_2]]'
card:
type: custom:decluttering-card
template: decl_graph
variables: &decl_graph_tmpl_call_variables
- VALUE_GRAPH_TYPE: '[[tmpl_VALUE_GRAPH_TYPE]]'
- VALUE_TITLE: '[[tmpl_VALUE_TITLE]]'
- VALUE_HOURS_TO_SHOW: '${varINPUT_HOURS_TO_SHOW.state}'
- VALUE_UPDATE_INTERVAL: '[[tmpl_VALUE_UPDATE_INTERVAL]]'
- VALUE_POINTS_PER_HOUR: '[[tmpl_VALUE_POINTS_PER_HOUR]]'
- VALUE_SHOW_POINTS: '${varINPUT_SHOW_POINTS.state === ''on'' ? true : false}'
- VALUE_SHOW_EXTREMA: '${varINPUT_SHOW_EXTREMA.state === ''on'' ? true : false}'
- VALUE_SHOW_AVERAGE: '${varINPUT_SHOW_AVERAGE.state === ''on'' ? true : false}'
- VALUE_SHOW_LABELS: '[[tmpl_VALUE_SHOW_LABELS]]'
- VALUE_SHOW_NAME: '[[tmpl_VALUE_SHOW_NAME]]'
- VALUE_SHOW_FILL: '[[tmpl_VALUE_SHOW_FILL]]'
- VALUE_STATE_ADAPTIVE_COLOR: '[[tmpl_VALUE_STATE_ADAPTIVE_COLOR]]'
- VALUE_HEIGHT: '[[tmpl_VALUE_HEIGHT]]'
- VALUE_LOWER_BOUND: '[[tmpl_VALUE_LOWER_BOUND]]'
- VALUE_AGGREGATE_FUNC: '[[tmpl_VALUE_AGGREGATE_FUNC]]'
- VALUE_GROUP_BY: '[[tmpl_VALUE_GROUP_BY]]'
- VALUE_STATE_MAP: '[[tmpl_VALUE_STATE_MAP]]'
- VALUE_SHOW_LEGEND: '[[tmpl_VALUE_SHOW_LEGEND]]'
- VALUE_COLOR_THRESHOLDS: '[[tmpl_VALUE_COLOR_THRESHOLDS]]'
- VALUE_COLOR_THRESHOLDS_TRANSITION: '[[tmpl_VALUE_COLOR_THRESHOLDS_TRANSITION]]'
- VALUE_COMPACT_MIN_MAX_AVG_INFO: '[[tmpl_VALUE_COMPACT_MIN_MAX_AVG_INFO]]'
##################################################################
- SENSOR: '[[tmpl_SENSOR]]'
- VALUE_NAME: '[[tmpl_VALUE_NAME]]'
- VALUE_SHOW_GRAPH: '[[tmpl_VALUE_SHOW_GRAPH]]'
- VALUE_SHOW_STATE: >-
${varINPUT_SHOW_POINTS.state === 'on' ? true :
[[tmpl_VALUE_SHOW_STATE]]}
- VALUE_LINE_COLOR: '[[tmpl_VALUE_LINE_COLOR]]'
##################################################################
- SENSOR_2: '[[tmpl_SENSOR_2]]'
- VALUE_NAME_2: '[[tmpl_VALUE_NAME_2]]'
- VALUE_SHOW_GRAPH_2: '[[tmpl_VALUE_SHOW_GRAPH_2]]'
- VALUE_SHOW_STATE_2: >-
${[[tmpl_VALUE_SHOW_GRAPH_2]] === true ?
(varINPUT_SHOW_POINTS.state === 'on' ? true :
[[tmpl_VALUE_SHOW_STATE_2]]) : false}
- VALUE_LINE_COLOR_2: '[[tmpl_VALUE_LINE_COLOR_2]]'
##################################################################
- SENSOR_3: '[[tmpl_SENSOR_3]]'
- VALUE_NAME_3: '[[tmpl_VALUE_NAME_3]]'
- VALUE_SHOW_GRAPH_3: '[[tmpl_VALUE_SHOW_GRAPH_3]]'
- VALUE_SHOW_STATE_3: >-
${[[tmpl_VALUE_SHOW_GRAPH_3]] === true ?
(varINPUT_SHOW_POINTS.state === 'on' ? true :
[[tmpl_VALUE_SHOW_STATE_3]]) : false}
- VALUE_LINE_COLOR_3: '[[tmpl_VALUE_LINE_COLOR_3]]'
##################################################################
- SENSOR_4: '[[tmpl_SENSOR_4]]'
- VALUE_NAME_4: '[[tmpl_VALUE_NAME_4]]'
- VALUE_SHOW_GRAPH_4: '[[tmpl_VALUE_SHOW_GRAPH_4]]'
- VALUE_SHOW_STATE_4: >-
${[[tmpl_VALUE_SHOW_GRAPH_4]] === true ?
(varINPUT_SHOW_POINTS.state === 'on' ? true :
[[tmpl_VALUE_SHOW_STATE_4]]) : false}
- VALUE_LINE_COLOR_4: '[[tmpl_VALUE_LINE_COLOR_4]]'
##################################################################
- SENSOR_5: '[[tmpl_SENSOR_5]]'
- VALUE_NAME_5: '[[tmpl_VALUE_NAME_5]]'
- VALUE_SHOW_GRAPH_5: '[[tmpl_VALUE_SHOW_GRAPH_5]]'
- VALUE_SHOW_STATE_5: >-
${[[tmpl_VALUE_SHOW_GRAPH_5]] === true ?
(varINPUT_SHOW_POINTS.state === 'on' ? true :
[[tmpl_VALUE_SHOW_STATE_5]]) : false}
- VALUE_LINE_COLOR_5: '[[tmpl_VALUE_LINE_COLOR_5]]'
##################################################################
- SENSOR_6: '[[tmpl_SENSOR_6]]'
- VALUE_NAME_6: '[[tmpl_VALUE_NAME_6]]'
- VALUE_SHOW_GRAPH_6: '[[tmpl_VALUE_SHOW_GRAPH_6]]'
- VALUE_SHOW_STATE_6: >-
${[[tmpl_VALUE_SHOW_GRAPH_6]] === true ?
(varINPUT_SHOW_POINTS.state === 'on' ? true :
[[tmpl_VALUE_SHOW_STATE_6]]) : false}
- VALUE_LINE_COLOR_6: '[[tmpl_VALUE_LINE_COLOR_6]]'
##################################################################
- SENSOR_BACK: '[[tmpl_SENSOR_BACK]]'
- VALUE_NAME_BACK: '[[tmpl_VALUE_NAME_BACK]]'
- VALUE_SHOW_GRAPH_BACK: '${varINPUT_SHOW_GRAPH_BACK.state === ''on'' ? true : false}'
- VALUE_LINE_COLOR_BACK: '[[tmpl_VALUE_LINE_COLOR_BACK]]'
##################################################################
- SENSOR_BACK_2: '[[tmpl_SENSOR_BACK_2]]'
- VALUE_NAME_BACK_2: '[[tmpl_VALUE_NAME_BACK_2]]'
- VALUE_SHOW_GRAPH_BACK_2: '${varINPUT_SHOW_GRAPH_BACK_2.state === ''on'' ? true : false}'
- VALUE_LINE_COLOR_BACK_2: '[[tmpl_VALUE_LINE_COLOR_BACK_2]]'
##################################################################
- SENSOR_X_AXIS: '[[tmpl_SENSOR_X_AXIS]]'
- VALUE_SHOW_GRAPH_X_AXIS: '[[tmpl_VALUE_SHOW_GRAPH_X_AXIS]]'
- VALUE_LINE_COLOR_X_AXIS: '[[tmpl_VALUE_LINE_COLOR_X_AXIS]]'
Notes:
- For some boolean values (which are supposed to be managed by
"input_boolean"
) the default value is specified -"input_boolean.service_false_value"
:
input_boolean:
service_false_value:
name: "Service: false value"
icon: mdi:null
initial: false
This entity must not be changed via GUI, must be always "false"
.
- For some boolean values (which are supposed to be managed by
"input_boolean"
) the default value is specified -"input_boolean.service_true_value"
:
input_boolean:
service_true_value:
name: "Service: true value"
icon: mdi:plus-one
initial: true
This entity must not be changed via GUI, must be always "true"
.
-
Most of the input variables for the Template #2 are repeating the input variables for the Template #1 with same default values.
-
Explanations for
"tmpl_INPUT_REALTIME"
are provided below. -
YAML anchors are used, do not delete them - they may be useful if you decide to create new templates based on this one (like it is described for reduced templates).
-
Some input variables have a
"VALUE_"
prefix in a name - that means this variable is a constant “some value” (a string, a number, a boolean value, a dictionary) - these values are defined on creation. Some input variables have an"INPUT_"
prefix in a name - that means that this variable is an input helper ("input_select"
for the"hours_to_show"
,"input_boolean"
for properties like"show_extrema"
) - these values may be changed online.
Simple rules how to set a value for these "INPUT_"
input variables when using a template:
-
"tmpl_INPUT_SHOW_EXTREMA"
,"tmpl_INPUT_SHOW_AVERAGE"
"tmpl_INPUT_SHOW_POINTS"
"tmpl_INPUT_REALTIME"
-
"tmpl_INPUT_SHOW_GRAPH_BACK"
,"tmpl_INPUT_SHOW_GRAPH_BACK_2"
-
If some value is
"false"
by default (i.e."input_boolean.service_false_value"
) - then there is no sense to specify this explicitly:
"- tmpl_INPUT_SHOW_EXTREMA: input_boolean.service_false_value"
You should specify:
"- tmpl_INPUT_SHOW_EXTREMA: input_boolean.service_true_value"
- means “always true regardless of GUI settings”,
or
"- tmpl_INPUT_SHOW_EXTREMA: input_boolean.graph_show_extrema_test"
- means “managed by GUI settings”. -
If some value is
"true"
by default (i.e."input_boolean.service_true_value"
) - then there is no sense to specify this explicitly:
"tmpl_INPUT_REALTIME: input_boolean.service_true_value"
You should specify:
"- tmpl_INPUT_REALTIME: input_boolean.service_false_value"
- means “always false regardless of GUI settings”,
or
"- tmpl_INPUT_REALTIME: input_boolean.graph_realtime_test"
- means “managed by GUI settings”.