78 lines
2.8 KiB
YAML
78 lines
2.8 KiB
YAML
# Browser Mod Auto-Scroll Automation
|
|
# Add this to your Home Assistant automations.yaml or create via UI
|
|
|
|
automation:
|
|
- alias: "Kiosk Dashboard Auto-Scroll"
|
|
description: "Auto-scroll dashboard cards every 5 seconds"
|
|
trigger:
|
|
- platform: state
|
|
entity_id: browser_mod.browser_kiosk
|
|
to: "on"
|
|
- platform: homeassistant
|
|
event: start
|
|
condition:
|
|
- condition: state
|
|
entity_id: browser_mod.browser_kiosk
|
|
state: "on"
|
|
action:
|
|
- delay: "00:00:03" # Wait 3 seconds for page to load
|
|
- service: browser_mod.execute_script
|
|
target:
|
|
entity_id: browser_mod.browser_kiosk
|
|
data:
|
|
command: |
|
|
(function() {
|
|
'use strict';
|
|
console.log('Auto-scroll script starting...');
|
|
|
|
// Get all cards
|
|
const cards = Array.from(document.querySelectorAll('ha-card'));
|
|
console.log(`Found ${cards.length} cards`);
|
|
|
|
if (cards.length === 0) {
|
|
console.error('No cards found!');
|
|
return;
|
|
}
|
|
|
|
// Ensure each card takes full viewport height
|
|
cards.forEach((card, index) => {
|
|
card.style.minHeight = window.innerHeight + 'px';
|
|
card.style.scrollMarginTop = '0px';
|
|
console.log(`Card ${index + 1}: Set min-height to ${window.innerHeight}px`);
|
|
});
|
|
|
|
// Scroll to first card
|
|
window.scrollTo({ top: 0, behavior: 'smooth' });
|
|
|
|
let currentIndex = 0;
|
|
|
|
// Function to scroll to next card
|
|
function scrollToNext() {
|
|
currentIndex = (currentIndex + 1) % cards.length;
|
|
const targetCard = cards[currentIndex];
|
|
|
|
if (targetCard) {
|
|
targetCard.scrollIntoView({
|
|
behavior: 'smooth',
|
|
block: 'start',
|
|
inline: 'nearest'
|
|
});
|
|
console.log(`Scrolled to card ${currentIndex + 1} of ${cards.length}`);
|
|
}
|
|
}
|
|
|
|
// Start auto-scrolling every 5 seconds
|
|
const intervalId = setInterval(scrollToNext, 5000);
|
|
console.log('Auto-scroll enabled: scrolling every 5 seconds');
|
|
|
|
// Store interval ID for cleanup
|
|
window.dashboardScrollInterval = intervalId;
|
|
|
|
// Cleanup function (optional)
|
|
window.stopAutoScroll = function() {
|
|
clearInterval(intervalId);
|
|
console.log('Auto-scroll stopped');
|
|
};
|
|
|
|
})();
|