I want to show image based on nane of a template.
I try many different times, this format work in devo tools but showing nothing.
I donāt understand if i can use this mod
Read docs on Github, there are examples there.
Basically - whatever you use, you should read a manual first before using.
In short: your templates are written in jinjia, but this card accepts templates written in JS.
Must be smth like this:
type: custom:config-template-card
entities:
- ...
card:
type: picture
image: '${ your js code here }'
Also - please check this (not related to our issue, but anyway):
Sorry but Iām not software maker, maybe 20 years ago, and now there is little time for learn and the brain is like steel.
I did this and doesnāt work
Yes but not all itās of the same thinking.
Thanks to much, first code finally working.
This is only a first try, this evening I have to put as a background image in a very long picture element
But I have a sensor ( a TRV / climate sensor) with four states: Idle, Off, Heat & ERROR and Iād like to change the icon based on the state of the sensor. I tried this and variations of it - but Iām basically guessing (unsuccessfully) at the correct syntax:
Iāve blindly tried a bunch of other stuff - but nothing that gets me closer to a solution. Any ideas or nudges in the right direction appreciated and welcome.
You are using a mix of jinjia code and ā${}ā code.
You should only use JS code inside ā${}ā. Scroll up a bit, find an example with a weblink. It does not have conditions āif then elseā, add them by yourself - using JS.
Thanks @Ildar_Gabdullin - I was pretty sure I was doing something fundamentally wrong. I couldnāt find any examples dealing with icon change on multiple states. I did play with this kind of syntax:
Thanks @Ildar_Gabdullin Iām afraid I donāt know what JS code is Iām proficient at copy / paste and very little else. I tried this following your suggestion, but I have no idea why itās wrong:
Awesome, thanks for your patience with me - thereās no way Iād have got there without working examples to start with - I really appreciate your help
Hereās what worked for me eventually (I got caught out not knowing the difference between āelse ifā and āelifā). Thanks again for your help @Ildar_Gabdullin
- entity: switch.trv_02
icon: |-
${
if ((states['sensor.trv_02_status'].state) == 'ERROR')
'mdi:alert-circle';
else if ((states['sensor.trv_02_status'].state) == 'Off')
'mdi:mdi:power-off';
else if ((states['sensor.trv_02_status'].state) == 'Idle')
'mdi:sleep';
else if ((states['sensor.trv_02_status'].state) == 'Heat')
'mdi:fire';
else
'mdi:help-circle-outline';
}
Thank you for posting a working template. Here is a test template I just worked on that does a few things that werenāt working for you. Noticeably it uses named variables and I was able to escape the character colon : by surrounding it with backslashes \
This template is fully working (for me at least); Iām just posting it here in case it can help someone else. I find the original documentation could use a few more to demonstrate how certain things can be done.