Been playing with the custom:button-card and have run into strange behaviour.
I am trying to create a card that looks at the temperature and an the dewpoint of a sensor (dewpoint is calculated from the T and H of the same sensor).
When the temperature is less than or equal to dewpoint temperature the card text should change colour and show an alert .
It seemed to work until I notice that is the dewpoint temperature is say 9.0C and the temperature is say 10.0C then it seems to return that 9.0C is greater than 10.0C.
To further test this I created a couple of input_number helpers and used the config below.
type: custom:button-card
variables:
entity_4: sensor.living_room_sensor_dewpoint
entity_3: sensor.living_room_sensor_temperature
entity_2: input_number.test_temperature_slider
entity_1: input_number.test_dewpoint_slider
color_condensation: '#0000FF'
color_normal: '#00FF00'
color_unavailable: '#252525'
entity: '[[[return variables.entity_1]]]'
triggers_update:
- '[[[return variables.entity_2]]]'
label: |
[[[
if (entity.state == 'unavailable')
return 'Unknown';
else if (entity.state >= states[variables.entity_2].value)
return "Condensation";
else if (entity.state < states[variables.entity_2].value)
return "OK";
]]]
show_label: true
name: Dewpoint
show_name: true
show_state: false
color-type: icon
styles:
grid:
- position: relative
custom_fields:
temperature:
- border-radius: 10%
- position: absolute
- left: 0%
- top: 20%
- height: 20px
- width: 50px
- font-size: 14px
dewpoint:
- border-radius: 10%
- position: absolute
- left: 0%
- top: 10%
- height: 20px
- width: 50px
- font-size: 14px
alert:
- border-radius: 10%
- position: absolute
- left: 70%
- top: 10%
- height: 80px
- width: 50px
- font-size: 70px
- color: red
- font-weight: bold
- animation: blink 0.5s ease infinite
icon:
- color: |
[[[
if (entity.state == 'unavailable')
return variables.color_unavailable;
else if (entity.state >= states[variables.entity_2].state)
return variables.color_condensation;
else if (entity.state < states[variables.entity_2].state)
return variables.color_normal;
]]]
label:
- color: |
[[[
if (entity.state == 'unavailable')
return variables.color_unavailable;
else if (entity.state >= states[variables.entity_2].state)
return variables.color_condensation;
else if (entity.state < states[variables.entity_2].state)
return variables.color_normal;
]]]
custom_fields:
dewpoint: |
[[[
if (entity.state == 'unavailable')
return '--';
else
return (entity.state) + " °C";
]]]
alert: |
[[[
if (entity.state >= states[variables.entity_2].state)
return '!';
else
return '';
]]]
temperature: |
[[[ return states[variables.entity_2].state]]]
but I still get odd results
The result below is fine because dewpoint is lower than temperature
The result below is also OK because dewpoint = temperature
Again - below is OK
However the result below though is wrong as dewpoint is greater than temperature
If I make the dewpoint 2.5C then every temperature value from 10C to 24.9C is incorrect.
So, basically what am I misunderstanding / doing wrong?