Change a Sensor Icon color - Very confused

Bingo that works: I just remove the 'state. Thank you very much

icon_view2

climate.sinope_climate_cave:
  templates:
    entity_picture: >
      if (attributes.heatLevel < 1) return '/local/heat-0.png';
      if (attributes.heatLevel < 21) return '/local/heat-1.png';
      if (attributes.heatLevel < 41) return '/local/heat-2.png';
      if (attributes.heatLevel < 61) return '/local/heat-3.png';
      if (attributes.heatLevel < 81) return '/local/heat-4.png';
      return '/local/heat-5.png';
1 Like

a yes, forgot to mention the indeed, sorry, you only need the part of the state your interested in. see it like this:

states.entity_id.state if (state .....)
states.entity_id.attributes.attribute if (attributes.attribute....)

for another entity use:

if (entities['states.entity_id'].state ......)

btw, please share the code for your card? Id be interested to see how you show these double lined temperatures. Havent seen that before I think.

I’m using Sinope thermostat and made a custom component for them as they are not supported yet in HA. You can find my code on my Git:[claudegel/sinope-1](https://github.com/claudegel/sinope-1)
for the second line it’s showing actual temperature:

@property
    def current_temperature(self):
        """Return the current temperature."""
        return self._cur_temp

in the update
self._cur_temp = float(self.sinope_data.data[self.device_id]["data"]["temperature"])

for the last updated info it is

customize: !include customize.yaml
  customize_glob:
    light.*:
      custom_ui_state_card: state-card-custom-ui
      show_last_changed: true
    cover.*:
      custom_ui_state_card: state-card-custom-ui
      show_last_changed: true
    climate.*:
      custom_ui_state_card: state-card-custom-ui
      show_last_changed: true

thanks, that Custom-ui is all familiar territory to me :wink: But it doesn’t show how you display the ‘actuellement: 9.9 C’ below the ‘Inactif 18C’ ?

please show me the full code for that card?

or is all that being done in the CC on https://github.com/claudegel/sinope-1 and is Custom-ui i=only taking care of the show_last_changed?

Cant find it in your code there…

show_last_changed is from custom-ui
actuellement: 9.9 C is from the component. It’s the self._cur_temp
This is the room temperature

Yes thanks. How do you get it to show on the second line though?

@property
def current_temperature(self):
“”“Return the current temperature.”“”
return self._cur_temp

this set the attribute current_temperature and is shown automatically on second line.
The data is from the thermostat with

self._cur_temp = float(device_data[“temperature”])

if you don’t have

@property
    def current_temperature(self):
        """Return the current temperature."""
        return self._cur_temp

the second line won’t show up. So data must be provided by your thermostat and
def current_temperature(self): must be set in your climate component

I don’t have this card at all nor the thermostat, but that shouldn’t matter, Im simply trying to understand how to get an attributes on the second line below the state, as you do.

must be the code in the python sensor declaration somehow. But I can’t find it in you CC.

for comparisons sake:
I use this very simple python script to create sensors, and set its attributes. Would you know how to expand this and have it show the second line below the state:

##########################################################################################
entity_id = data.get('entity_id')
if not entity_id:
    logger.error('No entity_id provided')
state = data.get('state')
if not state:
    logger.error('No state provided')

if entity_id and state:
#    old_state = hass.states.get(entity_id)
#    if old_state:
#        attrs = old_state.attributes
#    else:
#        attrs = None
    theme = 'red' if state == 'on' else 'green'
    friendlyName = entity_id.split('.')[1].title().replace('_',' ')

    hass.states.set(entity_id, state,{
      'custom_ui_state_card': 'state-card-custom-ui',
      'friendly_name': friendlyName,
      'device_class': 'problem',
      'theme': theme,
      'show_last_changed': 'true'
      })

The code to print the second line is in the climate component not in my custom component. I just set the value for current_temperature and the second line is printed. If I don’t provide value for current_temperature nothing is printed on second line.

I see. Thanks. can you point me to that climate component? Or is it somewhere here: core/homeassistant/components/climate at dev · home-assistant/core · GitHub

maybe @pnbruckner would know how to, based on the above? Show an attribute of an entity on the second line under the state as shown inpost 25 of this thread

can’t do that with custom-ui, and supposedly is in the components code.
thanks for having a look if you would.

Yes this is where you’ll find climate component __init__.py

Hi folks! :slight_smile:
Can we somehow use this templating/scripting inside LovelaceUI?
In my floor plan I have entity of type image representing my TV. I have made custom ambilight behind my tv, and I want to apply a filter of the tv image like: “filter: drop-shadow(0px 0px 10px rgb( >> put somehow the rgb value from ambilight << ))”.
How can I achieve this?

Check out this thread. This custom card will allow you to template any card:

Thanks a lot man. It looks exactly what I’m looking for. I will give it a try and I’ll feedback it! :slight_smile:

I do not know if the right section is, but @Mariusthvdb can help me.
I’d like to get something like that:
image
Right now I got this:
image
What do I have to do next?

Soo, in installed the custom-ui files in www, added the custom_component, registered in configuration.yaml and edited my customize.yaml file like this:

automation.smoke_alarm:
  friendly_name: Brandalarm ingeschakeld
  icon: mdi:fire
  icon_color: >
    if (state === 'on') return '#FDD835';
    return '#3F6F9C';

Seems not to work. Then I tried:

automation.smoke_alarm:
  friendly_name: Brandalarm ingeschakeld
  icon: mdi:fire
  icon_color:  green

Which indeed colors the icon green. So the custom_ui thing seems to do something.
What is going wrong?

I have in customize_glob following templates and they are working.

    binary_sensor.*_enabled:
      templates:
        icon_color: >
          if (state == "on") {
            return 'rgb(22, 200, 38)';
          } else {
            return 'rgb(255, 22, 38)';
          }

Give it a try :slight_smile:

I did, but it doesnt work. Soo that tells me there is something wrong with the confguration of custom_ui perhaps…

Make sure you’re using CustomUI: 20190518 (rgb didn’t work in the previous version) and I think you need “===” for “equals” here.

Here’s an example using HSV:

script.disarm_alarm:
  templates:
    icon_color: if (entities['sensor.armed_status'].state === 'disarmed') return 'green';
      else return '#696969';

templates: is a key part

as stated above, for customizing icon_color, you need custom-ui installed. check the /developer-tools/info for that:

then, among the many possible javascript syntaxes available, I find this to be the cleanest:

device_tracker.apple_wireless_keyboard:
  templates:
    icon_color: >
      if (state === 'home') return 'rgb(251, 210, 41)';
      return 'rgb(54, 95, 140)';

any css color-coding can be used, most of the time rgb is used for fine coloring, or simply use the color names available, always between quotes.

the above code is placed in a hierarchy in your config, under

homeassistant:
  customize:

depending on your settings, it could be in your configuration.yaml, or if you want in in a separate file/folder, use eg this:

homeassistant:
  name: Main
  latitude: !secret latitude
  longitude: !secret longitude
  elevation: !secret elevation
  unit_system: metric
  time_zone: !secret time_zone
  customize: !include_dir_merge_named customize    <---- this is the important line
  customize_glob: !include customize_glob.yaml

and have a folder /config/customize , in which you place the file with the above customization directly.

or use the line

 customize: !include customize.yaml

and add the file customize.yaml in which the same customization is written.