Dashboard background as the bing daily wallpaper

I have been interested in writing this up myself but haven’t had the time to actually dig into the code of home assistant and see how difficult it would be. So, I am opening this topic to see if anyone may be interested in doing it themselves.

I would love to be able to change the background of a dashboard to be the daily image from bing, as a bonus be able to get the title/information as well.

The following API URLs can grab the information about the current image -
JSON: http://www.bing.com/HPImageArchive.aspx?format=js&idx=0&n=1&mkt=en-US
XML: http://www.bing.com/HPImageArchive.aspx?format=xml&idx=0&n=1&mkt=en-US
RSS: (There is an RSS link as well but as a new user I can only put 2 links)

I can access this information from inside home assistant or create a sensor for it relatively easily, however I am unsure of how to actually turn it into the dashboards wallpaper.

1 Like

I got something somewhat working using the following, but it probably needs a custom theme designed around it which I am not as familiar with, I may dive deeper into this to see if I can make a theme that looks alright. If I never get back to this I hope it can help someone else.

Inside your configuration.yaml place the following this will run a rest request for the bing api to grab the url path.

downloader:
  download_dir: www/downloads
sensor:
  - platform: rest
    name: Bing Daily Wallpaper
    json_attributes_path: $.images[0]
    json_attributes:
      - startdate
      - enddate
      - title
      - copyright
    resource: https://www.bing.com/HPImageArchive.aspx?format=js&idx=0&n=1&mkt=en-US
    value_template: "{{ value_json.images[0].url }}"

Configure the sensor to update on the daily or at a certain time with something similar to the following -

service: downloader.download_file
data:
  url: {{ sensor.bind_daily_wallpaper }}
  overwrite: true

Inside the dashboards raw yaml configuration

background: center / cover no-repeat fixed url('/local/downloads/wallpaper.jpg')

Finally I found a solution which I think is not all that bad. It’s a mix of your solution with some python script.

Sources:

downloader

Dynamic images

Python scripts

→ For the download service

  1. Add folder “www” to the config path
  2. Add folder “www/bing” to the config path

→ For python scripts

  1. Add folder “python_scripts” to the config path
  2. Add file “download_bing.py”
# get url from the sensor as attribute
url = 'http://www.bing.com' + hass.states.get('sensor.bing_daily_wallpaper').attributes['url']

# `logger` and `time` are available as builtin without the need of explicit import.
logger.info("Start download bing image {} at {}".format(url, time.time()))

# call the service to download the file
service_data = {"overwrite": True, "url": url, "subdir": "bing", "filename": "wallpaper.jpg"}
hass.services.call("downloader", "download_file", service_data, False)

→ Modify the configuration.yaml

downloader:
  download_dir: www
  
python_script:
  
camera:
  - platform: local_file
    file_path: /config/www/bing/wallpaper.jpg
    
sensor:
  - platform: rest
    name: Bing Daily Wallpaper
    unique_id: Bing
    json_attributes_path: $.images[0]
    json_attributes:
      - url
      - startdate
      - enddate
      - title
      - copyright
	resource: https://www.bing.com/HPImageArchive.aspx?format=js&idx=0&n=1&mkt=en-US
    value_template: "{{ value_json.images[0].url }}"

→ on the ui add a card like this

elements: []
camera_image: camera.local_file
type: picture-elements
title: Bing Wallpaper

→ add a automation with trigger 5 o’clock to start the “Python Scripts: download_bing”

Works!!

BingToday