button-card
button-card copied to clipboard
Change icon with input_button helper
Hi, I’m trying to make a card for input_button.
So this helper has no state on / off but returns the last time has been pressed.
So I would like to change icon for a duration when button is pressed (for eg 20s) and return to this original icon.
At the moment I do this :
type: custom:button-card
entity: input_button.gate_btn
name: Test
show_state: false
icon: >
[[[
var currentTimestamp = Math.floor(new Date().getTime() / 1000)
var lastTimestamp = Math.floor(new Date(states['input_button.gate_btn'].state).getTime() / 1000)
var timeDiff = Math.floor((currentTimestamp - lastTimestamp) / 60)
var timeDiffSecond = timeDiff * 60
if (0 < timeDiffSecond < 20){
return 'mdi:gate-open';
}
else{
return 'mdi:gate'
}
]]]
But not working... What's wrong ? Thanks for your help