How do I access a dictionary entry for an Entity for use in styles- #23
Unanswered
Extrapilot1
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi-
I didnt get any feedback- perhaps too simple a question, or not enough users yet etc. But I found a working solution to a problem, and I think it may be useful to some.
The issue is- how do I dynamically pass and entity and then also a static or dynamic value into a streamcard template for dynamic formatting.
For me- the goal was to be able to do simple things I do not want to hard code as template sensors (where I might want a physical action as with a TTS message, or an email, etc). Specifically, I tend to use a large number of instances of a given device once I settle on it. For example, I use the S31 power monitoring switch for circuits where I want both switch capability, but also power monitoring. Since it can be flashed with ESPHome, that is a good match, and I can offload a lot of stuff like peak power detection per 10sec independent of HA even being online, and store that locally until HA is online again etc.
But I want to be able to use a generic card to display any given device's data, where all I have to pass is the device name, or if I want, I can pass entities in the case I want more control over what is displayed. And I want to be able to dynamically control background colors, icons, behaviors (like flashing etc) based on sensor values and trigger points I define per card. And this is simple with a single streamcard template once you figure out syntax.
Here is an example of a simple blue vs red background color control for a bubble-card:
.bubble-button-card-container { opacity: 1 !important; background-color: ${(hass.states['[[trigger_sensor_entity]]'].state) < [['trigger_value']] ? 'blue' : 'red'} !important; }
So here, Im passing an entity- which doesnt need to be the core entity used for the card. So, I could pass Power as the primary entity to the Card, and display current and energy and cost for that day, but I can control the background color with another entity- if for example peak current was above 15A that day, or if voltage drooped below 90% nominal, or if my power utilization is more than 1 standard deviation above the average hour for the prior day etc. And I can define a trigger value as a constant as it is here, or replace the trigger value variable with another entity- maybe something like the current temperature, or a dynamic energy cost which is based on the whole-house power usage etc. So maybe this doesnt merit alarms and mesages etc, but it is a simple way to build out a dashboard with objects with very little wasted code...
Beta Was this translation helpful? Give feedback.
All reactions