Help with icon color

hey
I have an AQARA FP1 presence sensor, since it has many states I created a template sensor to know if there is presence or no presence and I also added to this sensor an icon for the present state and an icon for the non-present state, is it possible for me to make the present icon yellow?
I am attaching an example of some devices where this happens automatically

this is my template sensor code:

sensor fp1xbox:
  - platform: template
    sensors:
      fp1xbox:
        friendly_name: "חיישן נוכחות חדר אקסבוקס"
        value_template: >-
          {% if is_state('sensor.khyyshn_nvkkhvt_khdr_qsbvqs_presence_event', 'leave') %}
              אין אף אחד
          {% else %}
               זוהתה נוכחות
          {% endif %}
        icon_template: >
          {% if is_state("sensor.khyyshn_nvkkhvt_khdr_qsbvqs_presence_event", "leave") %}
            mdi:motion-sensor-off
          {% else %}
            mdi:motion-sensor
          {% endif %}

thanks

2 options:

  1. custom ui
  2. card-mod

Both have pro & contra.

yep, I know that, just want someone show me how to insert this to my code

Change from a template sensor to template binary sensor. Leave out the icon template alltogether and just set the device class to presence. The functionality you need is all already built in.

like this?
I cant add device class “presence”, not exist
Thanks

binary_sensor:

sensor fp1bath1:
  - platform: template
    sensors:
      fp1bath1:
        friendly_name: "חיישן נוכחות מקלחת"
        value_template: >-
          {% if is_state('sensor.khyyshn_nvkkhvt_mqlkht_presence_event', 'leave') %}
              אין אף אחד
          {% else %}
               זוהתה נוכחות
          {% endif %}
        icon_template: >
          {% if is_state("sensor.khyyshn_nvkkhvt_mqlkht_presence_event", "leave") %}
            mdi:motion-sensor-off
          {% else %}
            mdi:motion-sensor
          {% endif %}

That config you posted is invalid. This won’t work – never mind adding a device class:

binary_sensor:

sensor fp1bath1:

Where and how are you adding it?

It does exist: Binary Sensor - Home Assistant.

Are you using ChatGPT? This seems like a bit of a mix of config.

No, I dont using chatgpt , but I just dont understand how to Change from a template sensor to template binary sensor.
here is not exist: Sensor - Home Assistant

Motion sensors are binary – by definition – and the device class I suggested exists, but only for binary sensors. In HA world, a motion sensor is binary: movement, or no movement. You can’t achieve the same with a normal sensor. You can’t force a sensor to be a binary sensor, but you can wrap your Aqara to get it into a binary state. I don’t own any Aqara products, so I can’t help with the logic unless you state what those states could be, but I’ll just use what you tried.

Using the new/modern style template sensor version:

template:
  - trigger:
      - platform: state
        entity_id: sensor.khyyshn_nvkkhvt_mqlkht_presence_event
    binary_sensor:
      name: fp1bath1
      state: "{{ 'off' if is_state('sensor.khyyshn_nvkkhvt_mqlkht_presence_event', 'leave') else 'on' }}"
      # look at delay on/off if you want/need that behaviour – check the docs posted above
      device_class: presence

Thanks!
so I cant change the name of state?

It shouldn’t be necessary, if your HA is set to use Hebrew as language (not sure if Hebrew is supported natively, but it doesn’t look like it).

Internal state shouldn’t be confused with how it’s presented on a UI, but that’s only a valid point if your language is supported.

To use English as an example. A binary sensor, internally, is true/false or on/off – regardless of the user’s language. HA will display this as detected/clear, and so forth for every language by mapping the internal state accordingly.

So, in your case, if you want to display the translated values, you’ll need to make your two-state “plain sensor” as you had initially and do as Ildar suggested: You’ll need to colour your icon with some UI trickery like using card-mod. There are many examples of that on the card-mod thread.