That makes sense I think if you have a busy system. The template card is re-instatiating the card each time there is a state change if not restricted by the entities
option. So the card could have been āgoneā while you held it.
Well that question opens up a whole can of worms.
I donāt even know what a hui-sensor-entity-row
is except by experimentation and by inferring from the contents of this post.
I can find no reference to anything hui
anywhere and I did ask the question recently and was told,
in order to
So to me they are some undocumented āmagicā.
Which all means that I have no idea why this config-template-card
needs to use them or what syntax and options are available to use them natively.
So, cutting to the chase, to answer your question, I donāt know. But I have tried the following with the results shown. (Interestingly neither appears as a ācardā unless of course they default to a transparent background).
- type: custom:hui-sensor-entity-row
entity: sensor.bakerloo
secondary_info: last-changed
style:
--primary-text-color: yellow
- type: custom:hui-sensor-entity-row
entity: sensor.bakerloo
secondary_info: last-changed
A binary sensor has a state on
or off
. Your code has true
which it will never have so thatās why itās always showing āNot chargingā.
ALL core cards/row/elements have a prefix/suffix that follows this convention:
hui-<card/row/element name>-<type card/row/element>
e.g.
hui-shopping-list-card
hui-sensor-entity-row
You can look in the create
files here: https://github.com/home-assistant/home-assistant-polymer/tree/dev/src/panels/lovelace/common
Thatās a good point, thanks!
But, why the first part of the text is not beinbg show?
My plan was to have an output like:
OnePlus 5: 85% - Charging/Not Charging
But it is showing only the final part, beside the wrong binary_sensor value
EDIT: Tested with āonā, it still only say āNot Chargingā
Had some fun, used this card to do a temperature-based color weather icon with pop-up forecast and weather map (browser-commander), thanks again for this great card!!
- type: state-icon
entity: sensor.dark_sky_minutely_summary
tap_action:
action: none
service: python_script.browser_cmd
service_data:
cmd: 'popup'
data: 'weather'
hold_action:
action: call-service
service: python_script.browser_cmd
service_data:
cmd: 'popup'
data: 'weathermap'
style:
top: 50%
left: 50%
height: auto
width: 2.6vw
background-color: "${var colors=['#442299','#3b0cbd','#3311bb','#4444dd','#e6ffff','#ccffff','#ffffff','#11aabb','#12bdb9',
'#22ccaa','#69d025','#aacc22','#d0c310','#ccbb33','#feae2d','#ff9933','#ff6644','#ff4422',
'#ff3311','#ee1100','#f80c12'];
var temp=parseInt((parseInt(states['sensor.dark_sky_temperature'].state)-10)/(70/20));
if (20>=temp>=0) colors[temp];else if (temp<0) colors[0];else colors[20]}"
border-radius: 100%
Introducing Variables
You can now use the new variables
configuration to create a list of reusable variables to hopefully help clean up your templates. See the updated docs on the repo for an example.
Have fun templating!
Further to my previous answer it doesnāt look like I can. I had guessed I would be able to, following the example given above by @arsaboo where he,
and changes the colour behind an icon:
If the answer is not too complex for this post, why can paper-item-icon-color
be defined but not primary-text-color
and is there any way to discover that information?
Should I change config
to card
? Seems like it would be more consistent with other cards.
- Keep
config
- Breaking change to use
card
0 voters
2 quick questions on the new variables option:
-
whatās the scope of these declared variables? I have picture-elements card under config, will all cards inside that picture-elements āseeā the variables?
[Edit: Tested, all cards under config āseeā the variables] -
Is it possible to declare constants in variables option? Like:
type: 'custom:config-template-card' variables: - states['light.bed_light'].state - ('red') [Edit: Works, vars[1] will show 'red', thanks to Ian!! ]
TIA
Any feedback/help please?
There must be something stupid I am doing that stop all the rest of the static text to be showed.
Did you try states['binary_sensor.andrea_oneplus5_charging'].state === true ? 'Charging' : 'Not Charging'
?
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: