I am trying to get a custom button card to change background color based on two variables. The variables are:
variables:
color_background: red
color_text: white
dypriggdybde: '[[[ return states[''sensor.dypriggdybde'']?.state; ]]]'
dypriggbunnavstand: '[[[ return states[''sensor.dypriggbunnavstand'']?.state; ]]]'
The statement I’m trying to get to work is this:
styles:
card:
- border-style: none
- background-color: >
[[[ if ((variables.dypriggdybde != 0) and (variables.dypriggbunnavstand ==5)) return variables.color_background; ]]]
- name:
- color: >
[[[ if ((variables.dypriggdybde != 0) and (variables.dypriggbunnavstand ==5)) return
variables.color_text; ]]]
But I get an error message:
ButtonCardJSTemplateError
SyntaxError: Unexpected identifier 'and' in 'if ((variables.dypriggdybde != 0) and (variables.dypriggbunnavstand ==0)) return variables.color_b...'
It works when I remove one of the variables and the “and”, like this:
styles:
card:
- border-style: none
- background-color: >
[[[ if (variables.dypriggdybde != 0) return variables.color_background; ]]]
- name:
- color: >
[[[ if (variables.dypriggdybde != 0) return
variables.color_text; ]]]
But why can’t I evaluate two variables in these? I tried to replace the and with a | but that seems like it’s only evaluationg the last variable.

