I’ve added a new page with 10 gauge cards. Each gauge has 25 segments defined. This makes for a lot of code that is duplicated. I’d like to use an !include statement for the segment: section but ran into a wall getting the code to work. Footnote - I saw another post where the user was trying to put his code in the secrets file and was advised to use includes instead. He didn’t post any working code though.
I created a file with the segment code and placed it in my config/www/shared/ folder. Then I tried to do this:
type: gauge
entity: sensor.comfort_index_outside
name: Outside
needle: true
min: 0
max: 60
segments: !include /config/www/shared/hvac_ci.yaml
with this code in the included file:
################################################################################
# Comfort Index Color Scale for Gauge Card
################################################################################
- from: 0
color: '#0400ff'
- from: 7.5
color: '#004eff'
- from: 15
color: '#006fff'
- from: 16.5
color: '#0087ff'
- from: 18
color: '#009bff'
- from: 19.5
color: '#00abff'
- from: 21
color: '#00baff'
- from: 22.5
color: '#00c8ff'
- from: 24
color: '#00d5d9'
- from: 25.5
color: '#00e2ad'
- from: 27
color: '#00ed80'
- from: 28.5
color: '#00f751'
- from: 30
color: '#00ff00'
- from: 31.5
color: '#61f200'
- from: 33
color: '#86e400'
- from: 34.5
color: '#a0d600'
- from: 36
color: '#b6c700'
- from: 37.5
color: '#c7b700'
- from: 39
color: '#d7a700'
- from: 41.5
color: '#e39500'
- from: 44
color: '#ee8200'
- from: 45.5
color: '#f66d00'
- from: 47
color: '#fb5600'
- from: 53.5
color: '#fe3900'
- from: 60
color: '#ff0000'
#
So far I can’t get this code to work, so am I doing it wrong or is it simply not possible? I have tried as many variations of the code in the gauge card as I can think of, and also tried moving the included file to the config directory to see if that was the issue.
If anyone has the answer of is it possible, I would appreciate you sharing your code. If it just isn’t possible, I’ll add 10x of the hardcoded yaml to my graph cards and move on. Thanks!
some other variations that did not work:
segments: !include hvac_ci.yaml
segments: !include /config/www/shared/hvac_ci.yaml
segments: '!include /config/www/shared/hvac_ci.yaml'
segments: !include '/config/www/shared/hvac_ci.yaml'
segments:
!include /config/www/shared/hvac_ci.yaml
This works:
type: gauge
entity: sensor.comfort_index_outside
name: Outside
needle: true
min: 0
max: 60
segments:
- from: 0
color: '#0400ff'
- from: 7.5
color: '#004eff'
- from: 15
color: '#006fff'
[continuing on for all 25 segments] .......