I created “input.boolean.xxx_arm” switches for each house sensor, eg “binary_sensor.xxx”, and then created a virtual sensor “binary_sensor.xxx_arm” which is activated like this:
I wish in Lovelace:
if binary_sensor.xxx OFF, then
Yellow color, if input.boolean.xxx_arm ON
Gray color, if input.boolean.xxx_arm OFF
instead
if binary_sensor.xxx ON, then
Red color, if input.boolean.xxx_arm ON
Blue color, if input.boolean.xxx_arm OFF
these are the examples that I have already found but they do not lead me to understand anything!
I need the condition to change the icon color of binary_sensor.xxx! that is, where should the input.boolean.xxx_arm go?
Forgive me, I’m new to this system.
Then I don’t understand your description. Is only the binary sensor „xxx“ supposed to change colours? If so, then:
styles:
icon:
- color: |
[[[
var e = states['binary_sensor.xxx'].state;
var x = states['input_boolean.xxx_arm'].state;
if (e == 'on' && x == 'on') return 'red';
if (e == 'on' && x == 'off') return 'blue';
if (e == 'off' && x == 'on') return 'yellow';
if (e == 'off' && x == 'off') return 'grey';
return 'pink';
]]]
„e“ and „x“ are variables to clear the following if/else conditions.
return 'pink';
is a shortform for else and a kind of fallback, if no condition is met.
Forgive me, the logic of what you wrote is clear and it is what I need but, I have not the faintest idea where to put it.
I am from the Vera system, it was enough to look for a plugin or a Luup code to do actions.
Definitely HA is more complete, I connected my google home, did automation with zwave devices but, HA is not for beginners like me!
Whenever I look for something in the community, it seems to assume that everyone is an expert … I download integrations, I create directories, I copy files, I modify the now very long configuration.yaml that sometimes gives errors, then I look for other solutions that suggest others integrations with installations in an old and modern way with examples that lead to other links … I’m definitely inside a washing machine.
I end up copying and pasting nonsense codes to randomly test … it’s humiliating
My poor logic would like me to insert your code in the button, change the names and everything works … instead I’ll have to add who knows what to get to a solution, believe me, it’s frustrating.
But on the other hand: I think, every system, that allows its users to manipulate the given standards and do their own special stuff, request knowledge about how the „engine runs“. But: It will become easier.
How was this implemented in the Vera system?
It has been a few years since the installation of my Vera system and I don’t remember well, however, each sensor has properties such as parameters and settings with fields such as icon type, color, association etc; Each sensor has by default the switch “ARMED/DISARMED”, to allow the creation of automations on condition. Unfortunately, the Vera System was very old and had been standing still for over 10 years.
Thanks for your interest, I will try a few more attempts but, I would appreciate so much more help on my problem, thanks
Sounds convenient! But: Now you want all the color conditions, and this request a little bit more effort… Here is an example, how you can built your card:
type: custom:button-card
entity: binary_sensor.xxx
triggers_update: all
styles:
icon:
- color: |
[[[
var e = entity.state;
var x = states['input_boolean.xxx_arm'].state;
if (e == 'on' && x == 'on') return 'red';
if (e == 'on' && x == 'off') return 'blue';
if (e == 'off' && x == 'on') return 'yellow';
if (e == 'off' && x == 'off') return 'grey';
else return 'lightgrey';
]]]
Great, it works perfectly, now I know what to work on and thank you.
I will do this to all sensors and, if I may venture, in my opinion, each sensor should have by default a switch that arms or disarms it because the condition would make the automation easier for amateurs. Thank you again.
I went ahead and now I configure the floor plan , so I tried to use your code with “paper-buttons-row” but it doesn’t seem to be compatible, moreover to the touch, it should change the state of the “input_boolean” but it doesn’t happen … where am i wrong?
type: picture-elements
image: /local/piantina/casa.png
elements:
- type: custom:paper-buttons-row
action: call-service
service: input_boolean.toggle
service_data: {}
target:
entity_id: input_boolean.sensorecucinaarm
buttons:
- entity: binary_sensor.sensore_cucina
layout: icon
state_icons:
'on': mdi:motion-sensor
'off': mdi:leak
styles:
button:
color: |
[[[
var e = entity.state;
var x = states['input_boolean.sensorecucinaarm'].state;
if (e == 'on' && x == 'on') return 'red';
if (e == 'on' && x == 'off') return 'white';
if (e == 'off' && x == 'on') return 'yellow';
if (e == 'off' && x == 'off') return 'grey';
else return 'lightgrey';
]]]
style:
top: 18%
left: 35%
I don’t use that, but I think, that a) the indentation is wrong and must be
styles:
button:
color: |
…
and b) that the code must be Jinja (as in Developer Tools → Templates):
{% set e = states('binary_sensor.sensore_cucina') %}
{% set x = states('input_boolean.sensorecucinaarm') %}
{% if (e == 'on' and x == 'on') %} red
{% elif (e == 'on' and x == 'off') %} white
{% elif (e == 'off' and x == 'on') %} yellow
{% elif (e == 'off' and x == 'off') %} grey
{% else %} lightgrey
{% endif %}
Thanks to your help, I went ahead with my project, and made a card with all the sensors that I arm and disarm.
Now I would like to add the “secondary_info: last-changed” function but I would like it to refer to the sensor ‘binary_sensor.senso_soggiorno’, what should I do?
type: entities
entities:
- entity: input_boolean.sensoresoggiornoarm
name: Soggiorno
icon: mdi:walk
secondary_info: last-changed
card_mod:
style: |
:host {
--paper-item-icon-color:
{% set e = states('binary_sensor.sensore_soggiorno') %}
{% set x = states('input_boolean.sensoresoggiornoarm') %}
{% if (e == 'on' and x == 'on') %} red
{% elif (e == 'on' and x == 'off') %} orange
{% elif (e == 'off' and x == 'on') %} blue
{% elif (e == 'off' and x == 'off') %} gray
{% else %} lightgrey
{% endif %}
}
I’ve a picture-elements card where I’m trying to change the icon color based on a motion sensor last trigger time.
Example: If {{ relative_time(states.binary_sensor.front_motion.last_changed) }} is less than 5 minutes I want the icon color to show Red or else Green.
With the following I’m able to change the color based on the state of this sensor, could any one please help me how can I do the same with last changed time.
icon_color: |-
{% if is_state("binary_sensor.front_motion", "on") %}
red
{% else %}
green
{% endif %}
icon_color: |-
{% set ls = (states.binary_sensor.front_motion.last_changed) %}
{% if ( now() - ls < timedelta(minutes=5) ) %}
red
{% else %}
green
{% endif %}
This is what i have been searching for! I do have a question for you tho. I am trying to create a garbage collection card on my dashboard, and I would like to have 1 card with 1 icon or picture displaying. when its recycle day the icon will switch from grey to blue and the following week when its yard waste it will switch from grey to green. that seems the most simple but im not sure how to attach 2 entities to 1 icon. which leaves me to believe it might be easier to get images of a blue trash can and a green trash can and display which ever boolean is currently on.