You could something with card mod like that for now. Maybe I will implement something like this in the future but not for now. But it will go on the todo list
Iām loving this card!!
I have an issue with icon templates always looking as if theyāre activated thoughā¦
Could anyone point me in the right direction with this code, which is yellow regardless of the entity state
- entity: media_player.study
name: Homepod
show_icon: true
icon:
template:
icon: |
return 'mdi:speaker-wireless'
styles: >
if (entity.state = 'playing') return 'color: yellow'; else return
'color: blue';
Got it:
- entity: media_player.study
name: Homepod
show_icon: true
icon:
conditions:
- icon: mdi:speaker-off
condition: equals
value: paused
- icon: mdi:speaker-wireless
condition: equals
value: playing
styles:
color: green
Is there a condition option for ābetweenā where we may apply styles to numbers in a range?
The first condition that matches will be returned. So if you put it in the correct order it will work.
Hey,
Thanks for this. But I guess the question is how can I set a tap-action to show a popup card with an entity like a thermostat on it?
You canāt, there is no popup functionality in the card. You can only show/hide cards based on other entities attributes or state.
One more from meā¦
How can I include the status of another entity in icon template?
Iām wanting to check if solar batteries are charging and if so use a āchargingā icon but also ensure the icon reflects the charge level of the battery.
- entity: number.battery_soc
name: Battery SOC
show_icon: true
icon:
template:
styles: >
if (entity.state < 16) return 'color: #8e44ad'; if (entity.state > 16
& entity.state <=40) return 'color: #c0392b'; if (entity.state > 40 &
entity.state <=85) return 'color: #d35400'; if (entity.state > 85 )
return 'color: #27ae60';
icon: >
if (entity.state < 16) return 'mdi:battery-outline';
if (entity.state > 16 & entity.state <=40) return 'mdi:battery-low';
if (entity.state > 40 & entity.state <=85) return 'mdi:battery-medium';
if (entity.state > 40 & entity.state <=85 & states.battery_status_text = 'Charging') return 'mdi:battery-charging-medium';
if (entity.state > 85 ) return 'mdi:battery-high';
This produces the error:
RoomCardJSTemplateError: SyntaxError: Left hand side of operator ā=ā must be a reference. in āif (entity.state < 16) return āmdi:battery-outlineā; if (entity.state > 16 & entity.state <=40) rā¦ā
Iām guessing Iām not using the āstatesā object correctly?
You need to uses states[FULL ENTITY ID] or states.FULLENTITYID. I recommend you read this :
if (entity.state > 40 & entity.state <=85 & states.battery_status_text = 'Charging') return 'mdi:battery-charging-medium';
Itās still complaining about the left hand side of the operator ā=ā. I also tried:
states.battery_status_text = 'Charging'
states.sensor.battery_status_text = 'Charging'
states[battery_status_text] = 'Charging'
states[sensor.battery_status_text] = 'Charging'
states['battery_status_text'] = 'Charging'
states['sensor.battery_status_text'] = 'Charging'
I think = is setting the left part to the right part.
For comparing the left and right you should use == ( = twice)
https://jinja.palletsprojects.com/en/3.1.x/templates/#comparisons
Itās working I reckon?
Mateā¦ Nothing wrong with any of the code! Was a missing unit_of_measurement attribute on the entity.
Even though I tested the condition as both int and string it only started working when I fixed an error on the log.
Hereās what I ended up with:
config YAML:
- platform: template
sensors:
battery_charging_icon:
value_template: >
{% set battState = iif(is_state('number.battery_status', '0'), '-charging', '') %}
{% set SOC = states('sensor.battery_soc')|float %}
{% if SOC <= 16 %}
mdi:battery{{battState}}-outline
{% elif SOC > 16 and SOC <= 40 %}
mdi:battery{{battState}}-low
{% elif SOC > 40 and SOC <= 85 %}
mdi:battery{{battState}}-medium
{% elif SOC > 85 and SOC <= 99 %}
mdi:battery{{battState}}-high
{% elif is_state('number.battery_status', '0') and SOC > 99 %}
mdi:battery-charging-100
{% elif is_state('number.battery_status', '1') and SOC > 99 %}
mdi:battery
{% endif %}
room-card:
- entity: sensor.battery_soc
name: Battery SOC
show_icon: true
icon:
template:
styles: >
if (entity.state < 16) return 'color: #8e44ad'; if (entity.state > 16
& entity.state <=40) return 'color: #c0392b'; if (entity.state > 40 &
entity.state <=85) return 'color: #d35400'; if (entity.state > 85 )
return 'color: #27ae60';
icon: |
states['sensor.battery_charging_icon']
show_state: true
tap_action:
action: more-info
Itās probably overkill, but keeps the code in the card tidy at least.
On to the next challenge!
Edit, acutally it wasnāt working. Finally got it with this:
icon: >
return states['sensor.battery_charging_icon'].state
Cheers
ā=ā is used when setting a value to a variable, while ā==ā should be used when comparing two values in the if clause.
Like this:
if (entity.state > 40 & entity.state <= 85 & states.battery_status_text == 'Charging') return 'mdi:battery-charging-medium';
Yes, that was also part of the problem when comparing the strings. I should have known better there too!
I did learn a bit more about Jinja on this particular journey, so thatās no bad thing.
This is the beauty of exchanging the ideas, experiences, challenges and mistakesā¦ We all learn a bit.
Very nice card, thanks for your work. Quick question: I am trying to add an attribute to info_entities, and it shows, but I cannot append a suffix (it is a temperature, and I want to add Ā°C. Am I doing something wrong?
Try adding āunitā : Configuration Ā· marcokreeft87/room-card Wiki Ā· GitHub. But if your entity is the correct device_class it will auto pick the right unit
It worked, thank you.
@klidberg . I love your room card. Could you please share your code for the living room. I would like to copy it from you if it s ok with you. Thank you