Quantcast
Channel: Configuration - Home Assistant Community
Viewing all articles
Browse latest Browse all 107839

How to cycle through background images?

$
0
0

I have a number of background images for my project. I want to display a different background image every hour or so.

I’ve got it working with the yaml below but the way i’m doing it seems very clunky (using a global variable to store the current image number) so would appreciate any advice to simplify the code :slight_smile:

Ideally I’d like to store however many images on an SD card and cycle through them regardless of the number and the file names but I suspect this might be a step too far…

image:
  - file: "eli.jpg"
    id: eli
    type: rgb565
  - file: "lake.jpg"
    id: lake
    type: rgb565
  - file: "bull.jpg"
    id: bull
    type: rgb565
  - file: "zebra.jpg"
    id: zebra
    type: rgb565

### cycle background image ####
interval:
  - interval: 3600s
    then:
      - if:
          condition:
            lambda: return id(current_img) == 1;
          then:
            - lvgl.update:
                disp_bg_image: lake
            - globals.set:
                id: current_img
                value: "2"
            - delay: 3500s    
      - if:
          condition:
            lambda: return id(current_img) == 2;
          then:
            - lvgl.update:
                disp_bg_image: eli
            - globals.set:
                id: current_img
                value: "3"
            - delay: 3500s
      - if:
          condition:
            lambda: return id(current_img) == 3;
          then:
            - lvgl.update:
                disp_bg_image: bull
            - globals.set:
                id: current_img
                value: "4"
            - delay: 3500s
      - if:
          condition:
            lambda: return id(current_img) == 4;
          then:
            - lvgl.update:
                disp_bg_image: zebra
            - globals.set:
                id: current_img
                value: "1"
            - delay: 3500s

1 post - 1 participant

Read full topic


Viewing all articles
Browse latest Browse all 107839

Trending Articles