Its_me
(Its me)
April 16, 2019, 8:33am
1
Silly requirement, does anyone know of a component like the Entity Button card that also implements a OnReleased of sort next to the OnHold ?
I’m trying to help someone out with automating their covers so that they roll up or down when they hold the up or down but stop the action when the button is released.
Cheers
Its_me
(Its me)
April 16, 2019, 10:07am
2
well I fabricobbled something together myself;
<html>
<script>
function touchstart(e) {
e.preventDefault();
toggle(e.target.value, true);
}
function touchend(e) {
toggle(e.target.value, false);
}
document.addEventListener("DOMContentLoaded", function (event) {
document.getElementById('btnUp').addEventListener("touchstart", touchstart, false);
document.getElementById('btnDown').addEventListener("touchstart", touchstart, false);
document.getElementById('btnUp').addEventListener("touchend", touchend, false);
document.getElementById('btnDown').addEventListener("touchend", touchend, false);
});
function toggle(entity, state) {
// call upon hass object ..
console.log(`Setting state to ${state} for ${entity}`);
}
</script>
<button type="submit" id="btnUp" value="switch.up">
UP
</button>
<button type="submit" id="btnDown" value="switch.down">
DOWN
</button>
</html>
Works on touch enabled displays, and that’s all I need. Now I’ll just pour it into a custom lovelace card.
Did you ever make this into a custom card?
pigotka
(Pigotka)
December 14, 2020, 12:24pm
4
I would love to use this card. Does it exists?
Maco65
(Maciek)
January 21, 2022, 3:39pm
5
Check this discussion: Button released events?