Yes, by itself it does work (and yes, I changed true to on)
If it is working by itself, the template should be fine. With variables
now possible, I would try putting in variables
.
Current status:
secondary_info: "${'OnePlus 5 Battery: ' + states['sensor.andrea_oneplus5_battery'].state + '%' + states['binary_sensor.andrea_oneplus5_charging'].state === 'on' ? ' - Charging' : ''}"
Result in:
While this:
secondary_info: "${states['binary_sensor.andrea_oneplus5_charging'].state === 'on' ? 'Charging' : ''}"
Correctly return:
You mean put the text in a variable?
What if you just try secondary_info: "${states['binary_sensor.andrea_oneplus5_charging'].state === 'on' ? 'Charging' : 'Not Charging'}"
?
Ehm, itâs my second example, which works correctly
Here is a other example i wanted to do that since a while, make the opacity of the lights on my 3D floor plan follow my real lights. thanks for that card!!!
Here is a little video demonstration:
https://youtu.be/qj2n5xoRNT0
The code is taken from the Lovelace editor
- type: 'custom:config-template-card'
config:
type: 'custom:card-modder'
card:
type: 'custom:hui-picture-elements-card'
image: /local/floorplan.png
elements:
- entity: light.kitchen
image: /local/fp_kitchen_off.png
style:
left: 66.9%
top: 26.7%
width: 17.88%
state_filter:
'off': opacity(0%)
'on': >-
${"opacity(" + (states['light.kitchen'].attributes.brightness /
2.55) + "%)"}
tap_action:
action: toggle
type: image
Awesome!
Iâm going to plan on adding updates only on attribute changes in the future as well which should improve performance for anyone using attributes
EDIT: Wait, Iâm already checking the full state object for the entityâŚnevermind Just restricting by entities
will work
Try this
secondary_info: "${'OnePlus 5 Battery: ' + states['sensor.andrea_oneplus5_battery'].state + '%' + (states['binary_sensor.andrea_oneplus5_charging'].state === 'on' ? ' - Charging' : '')}"
I believe the eval didnât like your ternary not being wrapped. I tested it here and is probably a good place to test your logic quickly:
Hi @iantrich, I tried your code but it actually returns a new error:
while parsing a block mapping in â/home/ha/.homeassistant/lovelace/views/test.yamlâ, line 28, column 23 expected <block end>, but found â<block mapping start>â in â/home/ha/.homeassistant/lovelace/views/test.yamlâ, line 32, column 24
I also tried to check the JS Bin site you posted but I am not sure how am I supposed to use it because also when I add the code you suggested it return an error
"SyntaxError: Invalid or unexpected token
Share you new config
You canât just copy that line into jsbin, if you see what I defined for states, it doesnât match yourâs exactly. You also need to not include the ${}
as I strip those out in my code before running eval
Oh I am sorry!
I didnât realize that the link was pointing to a pre-coded page, I tought the code was just example and I pasted the code in there , my bad!
Regarding the YAML error in HA I added an unnecessary additonal white space at the beginning, now it works!!!
Thank you so much!
Looking great, care to share your config of the card?
Sure thing, here it is:
- type: custom:config-template-card
config:
type: custom:hui-entities-card
title: House Members
show_header_toggle: false
entities:
- entity: person.andrea
type: "custom:secondaryinfo-entity-row"
secondary_info: "${'OnePlus 5 Battery: ' + states['sensor.andrea_oneplus5_battery'].state + '%' + (states['binary_sensor.andrea_oneplus5_charging'].state === 'on' ? ' - Charging' : '')}"
I tried variables:
card:
type: 'custom:hui-entities-card'
title: MQTT & Wifi Connections
show_header_toggle: false
variables:
- states['sensor.sonoff1_2914_status'].attributes['MqttCount']
- states['sensor.sonoff1_2914_status'].attributes['WiFi LinkCount']
entities:
- entity: sensor.sonoff1_2914_status
name: "${'Coffee' + '\xa0'.repeat(16) + 'MQTT ' + vars[0] + '\xa0'.repeat(4) + 'WiFi ' + vars[1]}"
But it shows unknown⌠did I do something wrong?
Also trying this:
- entity: sensor.sonoff1_2914_status
name: "${'Coffee' + '\xa0'.repeat(16) + 'MQTT ' + states['sensor.sonoff1_2914_status'].attributes['MqttCount'] + '\xa0'.repeat(4) + 'WiFi ' + states['sensor.sonoff1_2914_status'].attributes['WiFi LinkCount'] + states['sensor.sonoff1_2914_status'] >= 100 ? 'Excellent' : states['sensor.sonoff1_2914_status'] > 80 ? 'Good' : states['sensor.sonoff1_2914_status'] > 60 ? 'Fair' : 'Weak'}"
To append information about the WiFi RSSI strength⌠Excellent, Good, Fair or Weak to the end⌠but doesnât seem to like that either
Any ideas?
I got my variables: option before the config:/card: line of custom:config-template-card.
Ah that will be it for the error⌠but why isnât my conditional info showing?
- entity: sensor.sonoff1_2914_status
name: "${'Coffee' + '\xa0'.repeat(16) + 'MQTT ' + states['sensor.sonoff1_2914_status'].attributes['MqttCount'] + '\xa0'.repeat(4) + 'WiFi ' + states['sensor.sonoff1_2914_status'].attributes['WiFi LinkCount'] + states['sensor.sonoff1_2914_status'] >= 100 ? 'Excellent' : states['sensor.sonoff1_2914_status'] > 80 ? 'Good' : states['sensor.sonoff1_2914_status'] > 60 ? 'Fair' : 'Weak'}"
states[âsensor.sonoff1_2914_statusâ] probably is not giving you a number, maybe parseFloat(states[âsensor.sonoff1_2914_statusâ].state) ?
Depending on your states value, this works for me:
- type: custom:config-template-card
variables:
- states['device_tracker.a_phone'].attributes['battery']
- states['device_tracker.a_phone'].attributes['battery_charging']
config:
type: custom:hui-entities-card
title: TESTING
entities:
- entity: binary_sensor.carport
name: "${'Battery Level' + '\xa0'.repeat(16) + vars[0]}"
- entity: binary_sensor.carport
name: "${'Battery Level' + '\xa0'.repeat(16) + ((vars[0] >= 100) ? 'Excellent' : (vars[0] > 80) ? 'Good' : (vars[0] > 60) ? 'Fair' : 'Weak')}"
I screwed up the state.
This works:
- type: 'custom:config-template-card'
variables:
- states['sensor.sonoff1_2914_status'].attributes['MqttCount']
- states['sensor.sonoff1_2914_status'].attributes['WiFi LinkCount']
- states['sensor.sonoff1_2914_status'].state
- states['sensor.sonoff2_3110_status'].attributes['MqttCount']
- states['sensor.sonoff2_3110_status'].attributes['WiFi LinkCount']
- states['sensor.sonoff2_3110_status'].state
- states['sensor.sonoff5_1083_status'].attributes['MqttCount']
- states['sensor.sonoff5_1083_status'].attributes['WiFi LinkCount']
- states['sensor.sonoff5_1083_status'].state
- states['sensor.sonoff6_3719_status'].attributes['MqttCount']
- states['sensor.sonoff6_3719_status'].attributes['WiFi LinkCount']
- states['sensor.sonoff6_3719_status'].state
entities:
- sensor.sonoff1_2914_status
- sensor.sonoff2_3110_status
- sensor.sonoff5_1083_status
- sensor.sonoff6_3719_status
card:
type: 'custom:hui-entities-card'
title: MQTT & Wifi Connections
show_header_toggle: false
entities:
- entity: sensor.sonoff1_2914_status
name: "${'Coffee' + '\xa0'.repeat(16) + 'MQTT ' + vars[0] + '\xa0'.repeat(4) + 'WiFi ' + vars[1] + '\xa0'.repeat(2) + ( vars[2] >= 100 ? 'Excellent' : vars[2] >= 80 ? 'Good' : vars[2] >= 60 ? 'Fair' : 'Weak')}"
- entity: sensor.sonoff2_3110_status
name: "${'Toothbrush' + '\xa0'.repeat(7) + 'MQTT ' + vars[3] + '\xa0'.repeat(4) + 'WiFi ' + vars[4] + '\xa0'.repeat(2) + ( vars[5] >= 100 ? 'Excellent' : vars[5] >= 80 ? 'Good' : vars[5] >= 60 ? 'Fair' : 'Weak')}"
- entity: sensor.sonoff5_1083_status
name: "${'Garage' + '\xa0'.repeat(15) + 'MQTT ' + vars[6] + '\xa0'.repeat(4) + 'WiFi ' + vars[7] + '\xa0'.repeat(2) + ( vars[8] >= 100 ? 'Excellent' : vars[8] >= 80 ? 'Good' : vars[8] >= 60 ? 'Fair' : 'Weak')}"
- entity: sensor.sonoff6_3719_status
name: "${'Alarm' + '\xa0'.repeat(17) + 'MQTT ' + vars[9] + '\xa0'.repeat(4) + 'WiFi ' + vars[10] + '\xa0'.repeat(2) + ( vars[11] >= 100 ? 'Excellent' : vars[11] >= 80 ? 'Good' : vars[11] >= 60 ? 'Fair' : 'Weak')}"