Dynamic Playlists
Dynamic Playlists are a powerful feature that allows you to control your Screenly playlists based on dynamic factors like weather conditions, time of day, or even the results of a web API call. This flexibility enables you to create truly engaging and context-aware digital signage experiences.
How it Works:
Dynamic Playlists utilize Screenly’s API to dynamically enable or disable playlists based on pre-defined rules. This means you can create playlists that respond to real-time data and situations, making your signage more dynamic and engaging.
Types of Dynamic Playlists:
- Weather-Based Playlists: Show a playlist featuring winter-themed content during snowy weather, or a playlist showcasing summer activities during a heatwave.
- Time-Based Playlists: Display different content depending on the time of day. For example, play a morning news playlist in the early hours and a lunch specials playlist during the afternoon.
- API-Driven Playlists: Utilize external APIs to trigger playlist changes. This could include displaying weather information, traffic updates, or even real-time social media feeds.
Building Your First Dynamic Playlist:
- Set Up Your Playlists: Create the playlists you want to use for your dynamic content. For example, you might create separate playlists for summer and winter content.
- Define Your Rules: Configure the rules that will trigger playlist changes. This includes specifying the conditions (e.g., weather temperature, time of day, API response) and the playlists to enable or disable.
- Create a Script: Develop a script that integrates with Screenly’s API. This script will monitor your defined rules and update the playlist state accordingly.
Example Scripts:
Weather-Based Script:
// Import necessary libraries const request = require('request'); const screenly = require('screenly-api'); // Set your API credentials const apiUrl = 'https://api.screenly.com/v1'; const apiKey = 'YOUR_API_KEY'; // Define your playlist IDs const winterPlaylistId = 'YOUR_WINTER_PLAYLIST_ID'; const summerPlaylistId = 'YOUR_SUMMER_PLAYLIST_ID'; // Function to get weather data function getWeather() { const weatherUrl = 'https://api.openweathermap.org/data/2.5/weather?q=YOUR_CITY&appid=YOUR_WEATHER_API_KEY'; request(weatherUrl, function (error, response, body) { if (!error && response.statusCode === 200) { const weatherData = JSON.parse(body); const temperature = weatherData.main.temp; // Update playlists based on temperature if (temperature < 10) { enablePlaylist(winterPlaylistId); disablePlaylist(summerPlaylistId); } else { enablePlaylist(summerPlaylistId); disablePlaylist(winterPlaylistId); } } else { console.error('Error getting weather data:', error); } }); } // Function to enable a playlist function enablePlaylist(playlistId) { screenly.enablePlaylist(apiKey, apiUrl, playlistId); } // Function to disable a playlist function disablePlaylist(playlistId) { screenly.disablePlaylist(apiKey, apiUrl, playlistId); } // Call getWeather function to update playlists initially and on an interval getWeather(); setInterval(getWeather, 3600000); // Update every hour
Time-Based Script:
// Import necessary libraries const screenly = require('screenly-api'); // Set your API credentials const apiUrl = 'https://api.screenly.com/v1'; const apiKey = 'YOUR_API_KEY'; // Define your playlist IDs const morningPlaylistId = 'YOUR_MORNING_PLAYLIST_ID'; const afternoonPlaylistId = 'YOUR_AFTERNOON_PLAYLIST_ID'; // Function to update playlists based on time function updatePlaylists() { const currentHour = new Date().getHours(); if (currentHour >= 6 && currentHour < 12) { enablePlaylist(morningPlaylistId); disablePlaylist(afternoonPlaylistId); } else { enablePlaylist(afternoonPlaylistId); disablePlaylist(morningPlaylistId); } } // Function to enable a playlist function enablePlaylist(playlistId) { screenly.enablePlaylist(apiKey, apiUrl, playlistId); } // Function to disable a playlist function disablePlaylist(playlistId) { screenly.disablePlaylist(apiKey, apiUrl, playlistId); } // Call updatePlaylists function initially and on an interval updatePlaylists(); setInterval(updatePlaylists, 3600000); // Update every hour
Resources:
- Screenly API Documentation: https://docs.screenly.com/api/
- Screenly Playground: https://github.com/screenly/playground
Important Notes:
- Make sure to secure your API keys and protect sensitive information.
- Test your scripts thoroughly before deploying them to a live environment.
- Consider using a task scheduler to run your scripts on a regular basis.
- Stay updated on the latest Screenly API changes and features.