maurizio53
(Maurizio Fabiani)
April 23, 2024, 6:31pm
1
Can somebody tell me why this template doesn’t work?
- variables:
person: person.fha
bg: |
[[[
if (states['person.fha'].state == 'home' )
return 'url(/local/lovelace/images/Casa.png)';
if (states['person.fha'].state == 'Vino Di Sup' )
return 'url(/local/lovelace/images/vino_di_sup.png)';
if (states['person.fha'].state == 'Maxi Tigre' )
return 'url(/local/lovelace/images/Maxi_Tigre.png)';
if (states['person.fha'].state == 'Tody's' )';
return 'url(/local/lovelace/images/Todys.png)';
return 'url(/local/lovelace/images/Fha_away.jpg)'
]]]
jchh
(my username is my initials (and my first name isn't John))
April 23, 2024, 6:36pm
2
Try putting ‘else’ in front of the last return and also in front of every ‘if’ after the first one.
maurizio53
(Maurizio Fabiani)
April 23, 2024, 6:40pm
3
This way:
- variables:
person: person.fha
bg: |
[[[
if (states['person.fha'].state == 'home' )
return 'url(/local/lovelace/images/Casa.png)';
else if (states['person.fha'].state == 'Vino Di Sup' )
return 'url(/local/lovelace/images/vino_di_sup.png)';
else if (states['person.fha'].state == 'Maxi Tigre' )
return 'url(/local/lovelace/images/Maxi_Tigre.png)';
else if (states['person.fha'].state == 'Todis' )';
return 'url(/local/lovelace/images/Todys.png)';
else return 'url(/local/lovelace/images/Fha_away.jpg)'
]]]
EDIT: no, it still doesn’t work
kbrown01
(Kbrown01)
April 23, 2024, 6:47pm
4
states['person.fha'].state
I think you mean:
states('person.fha').state
( ) and not [ ]
Assuming of course person.fha
is some entity. I also cannot see why you have a variable.
maurizio53
(Maurizio Fabiani)
April 23, 2024, 6:50pm
5
I read that using the custom button-card i must use [ ].
and those variables are used by custom button card.
I noticed that if i use only these lines it works…
if (states['person.fha'].state == 'home' )
return 'url(/local/lovelace/images/Casa.png)';
if (states['person.fha'].state == 'Vino Di Sup' )
return 'url(/local/lovelace/images/vino_di_sup.png)';
return 'url(/local/lovelace/images/Fha_away.jpg)'
If i add more lines it stops working.
kbrown01
(Kbrown01)
April 23, 2024, 6:56pm
6
If this is custom button then post everything in the entire button_card_template.
Because at the very least variables doesn not need a “-” and you need triple [[[ ]]]].
Like this for example:
button_card_templates:
patio_vizio:
triggers_update: all
variables:
tv: patio_vizio
ip: >-
[[[ return states['sensor.vizio_tvs'].attributes.tvs.find(x=>x.name ==
'patio_vizio').ip ]]]
port: >-
[[[ return states['sensor.vizio_tvs'].attributes.tvs.find(x=>x.name ==
'patio_vizio').port ]]]
auth: >-
[[[ return states['sensor.vizio_tvs'].attributes.tvs.find(x=>x.name ==
'patio_vizio').auth ]]]
clientaddr: >-
[[[ return states['sensor.vizio_tvs'].attributes.tvs.find(x=>x.name ==
'patio_vizio').clientAddr ]]]
tom_l
April 23, 2024, 9:25pm
8
That is important information you should have included in your original post. We’re not privy to your full configuration or mind readers.
Also choosing the correct category would have helped slightly (Configuration Frontend == dashboards and cards).
1 Like
Troon
(Troon)
April 24, 2024, 6:36am
9
Extra quote mark in your second post; two in your first with the apostrophe as well:
else if (states['person.fha'].state == 'Todis' )';
----------------------------------------------------------^
return 'url(/local/lovelace/images/Todys.png)';
else return 'url(/local/lovelace/images/Fha_away.jpg)'
]]]
(edit: removed potentially-confusing response to kbrown01’s comment)
petro
(Petro)
April 24, 2024, 10:39am
10
You’re mixing up jinja templates and JS templates. JS templates do not use anything related to Jinja.
Typically, all of the JS templates require []
only and ()
do not work at all. This is true for custom:button-card and custom:config-template-card
1 Like