Colors home/not home

Hi!

I’m new in the Home Assistant’s world.
I made a card with entity button, which watch that the person is at home or not. It’s the same color, but I would like if it change when sy home, and another color when away.

It’s the same problem, that I create an entity button with an automatition, but it doesn’t change the color when it’s on or off.

Thanks!!

cards:
  - cards:
      - entity: device_tracker.adri_iphone
        show_name: false
        tap_action:
          action: more-info
        type: entity-button

So I don’t think that the cards change colour based on their state, well mine don’t.

However you could have an automation that changes the theme on that card depending on it state.

Also badges are quite good for binary sensors.

Can you help me in this? :slight_smile:

Personally I’ve not got this, but a quick search of the fourm turned up this post, however it doesn’t seem as simple as it sounds.
https://community.home-assistant.io/t/lovelace-button-card/65981/535

I have some binary sensor 's that I both change the icon for and change colours on (just like a bulb or switch when they go from off to on, ie I haven’t specified the colours).
Not sure it it helps in your setup as it looks like you want the button.
There are people who specialise in that but maybe @firstof9 can help until they arrive :wink: :rofl:

For the button card to do it’s magic you’d need to make a template binary sensor that’s on when home and off when away.

I prefer using the picture elements for something like this feature found in this thread:

Example picture:
image

Can you help me in making binary sensors?

I am using conditional cards to do this and themes (not probably the best way but it works for me)…
Themes “green” and “red” must exist in themes.yaml…

Here is an example for your case (to be tested):

            - type: conditional
              conditions:
                - entity: device_tracker.adri_iphone
                  state: 'home'
              card:
                type: entity-button
                entity: device_tracker.adri_iphone
                show_name: false             
                theme: green
                tap_action:
                  action: more-info
            - type: conditional
              conditions:
                - entity: device_tracker.adri_iphone
                  state: 'not_home'
              card:
                type: entity-button
                entity: device_tracker.adri_iphone
                show_name: false             
                theme: red
                tap_action:
                  action: more-info

themes.yaml:

#
#
#
green:
  primary-text-color: green
  # paper-card-background-color: white
  paper-item-icon-color: lime
  secondary-text-color: green
  label-badge-background-color: white
  label-badge-text-color: green
  label-badge-red: green
  label-badge-border-color: lightgrey
#
#
#
red:
  primary-text-color: red
  # paper-card-background-color: white
  paper-item-icon-color: red
  secondary-text-color: red
  label-badge-background-color: white
  label-badge-text-color: red
  label-badge-red: green
  label-badge-border-color: lightgrey

Hopefully @browetd 's example will help you but here is an example binary sensor : -

binary_sensor:
  - platform: template
    sensors:
      ## used to indicate evening slot
      bs_heat_evening_active:
        entity_id: sensor.time, input_datetime.id_heat_night_on, input_datetime.id_heat_evening_on
        value_template: >
          {% set time = states('sensor.time') %}
          {% set slt1start = states('input_datetime.id_heat_evening_on') [0:5] %}
          {% set slt1stop = states('input_datetime.id_heat_night_on') [0:5] %}
          {% set slt1on = (slt1start <= time < slt1stop) if (slt1start < slt1stop) else (slt1start <= time or time < slt1stop) %}
          {{ slt1on }}
        icon_template: "{{ 'mdi:glass-cocktail' if is_state('binary_sensor.bs_heat_evening_active', 'on') else 'mdi:timer-sand' }}"
        friendly_name: Evening Heat Slot Active

Change the template conditions to whatever you need
feel free to ask questions

1 Like

There’s also this thread which appears VERY comprehensive.
Not tried any of it myself but given the names involved I would say there is a high degree of confidence and some of the best support available