How to trigger a Home Assistant script through Alexa and make your Raspberry Pi picture frame do (just about) anything 2

How to trigger a Home Assistant script through Alexa and make your Raspberry Pi picture frame do (just about) anything

The image viewer Pi3D, Home Assistant and Amazon Alexa is a match made in heaven when it comes to magically control your images on the wall.

Almost whatever you want to your digital photo frame to do, you can do by simple voice commands of your choosing.

In this article, I will show you how to do it with Pi3D as the image viewer software and Amazon Alexa in combination with Home Assistant as your humble voice servant.

If you are unfamiliar with the image viewer Pi3D, please look at this article first.

Pi3D and MQTT

Pi3D in the latest version 2.41 can change 17 different parameters with a simple MQTT message. You can find these commands in the PictureFrame2020.py file.

client.subscribe("frame/date_from", qos=0) # needs payload as 2019:06:01 or divided by "/", "-" or "."
client.subscribe("frame/date_to", qos=0)
client.subscribe("frame/time_delay", qos=0) # payload seconds for each slide
client.subscribe("frame/fade_time", qos=0) # payload seconds for fade time between slides
client.subscribe("frame/shuffle", qos=0) # payload on, yes, true (not case sensitive) will set shuffle on and reshuffle
client.subscribe("frame/quit", qos=0)
client.subscribe("frame/paused", qos=0) # payload on, yes, true pause, off, no, false un-pause. Anything toggle state
client.subscribe("frame/back", qos=0)
client.subscribe("frame/next", qos=0)
client.subscribe("frame/subdirectory", qos=0) # payload string must match a subdirectory of pic_dir
client.subscribe("frame/delete", qos=0) # delete current image, copy to dir set in config
client.subscribe("frame/text_on", qos=0) # toggle file name on and off. payload text show time in seconds
client.subscribe("frame/date_on", qos=0) # toggle date (exif if avail else file) on and off. payload show time
client.subscribe("frame/location_on", qos=0) # toggle location (if enabled) on and off. payload show time
client.subscribe("frame/text_off", qos=0) # turn all name, date, location off
client.subscribe("frame/text_refresh", qos=0) # restarts current slide showing text set above
client.publish("frame/paused", payload="off", qos=0) # un-pause the slideshow on start

Among the latest additions, is the ability to show a text overlay with information on the date and location of the image. Especially if you don’t want to permanently show the information, being able to trigger it with a simple voice command is most convenient.

The basic requirement is that you have an MQTT broker installed. If you followed my instructions in the original Pi3D article, you will have installed the MQTT broker Mosquitto already.

In the PictureFrame2020config.py script, you just need to enable MQTT and specify the IP of your MQTT broker, which, with Mosquitto installed, is simply “localhost”.

parse.add_argument("-m", "--use_mqtt",      default=True)
parse.add_argument(      "--mqtt_server",   default="localhost")

Don’t forget to install paho so that Pi3D can connect to the MQTT broker, if you haven’t already done so, with

sudo pip3 install paho-mqtt

Creating the scripts in Home Assistant

Home Assistant is used as the bridge between Alexa and Pi3D. Unfortunately, it is not (yet) possible to send MQTT messages through Alexa directly, so we need this interface through Home Assistant and Nabu Casa. You can read all about it here.

I will show you two examples for scripts. Once you have understood the logic, you can create your own custom scripts for any other commands.

Show the date and location of an image

Create a new script in Home Assistant, and call it “Pi3D Show Date and Location ON”.

How to trigger a Home Assistant script through Alexa and make your Raspberry Pi picture frame do (just about) anything 3

Under Sequence to the right, fill in the information as shown here.

How to trigger a Home Assistant script through Alexa and make your Raspberry Pi picture frame do (just about) anything 4

The reason why I introduced a one second wait period is to avoid any hick-up by sending MQTT messages too fast in a row.

The above script will show the date and location information for 60 seconds every time an image comes up.

Turning off the information overlay

Create a new script in Home Assistant, and call it “Pi3D Turn Text OFF”.

How to trigger a Home Assistant script through Alexa and make your Raspberry Pi picture frame do (just about) anything 5

Under Sequence to the right, fill in the information as shown here.

How to trigger a Home Assistant script through Alexa and make your Raspberry Pi picture frame do (just about) anything 6

The above script will turn off the display of any photo information.

Testing the script

Test the scripts by manually triggering the two scripts in Home Assistant by clicking on the Play Button to the left of the script name.

Connecting the Home Assistant scripts to Alexa

For a more detailed article on this subject, I recommend reading “Voice control your digital photo frame with Amazon Echo and Home Assistant“.

I assume that you have the Alexa app installed on your mobile phone. Let’s go through the steps:

In the Alexa app, tap on the lower top-right icon “More”. Choose “Routines”. Tap on the “+” sign in the upper right to create a new routine.

Enter a name for your routine (this is not the voice command yet). Tap on “When this happens”, select “Voice”.

How to trigger a Home Assistant script through Alexa and make your Raspberry Pi picture frame do (just about) anything 7
How to trigger a Home Assistant script through Alexa and make your Raspberry Pi picture frame do (just about) anything 8
How to trigger a Home Assistant script through Alexa and make your Raspberry Pi picture frame do (just about) anything 9

Enter the Alexa voice command. Add “Action” and choose “Smart Home”. Tap on “Control scene” (Scenes in Alexa are the scripts in Home Assistant).

How to trigger a Home Assistant script through Alexa and make your Raspberry Pi picture frame do (just about) anything 10
How to trigger a Home Assistant script through Alexa and make your Raspberry Pi picture frame do (just about) anything 11
How to trigger a Home Assistant script through Alexa and make your Raspberry Pi picture frame do (just about) anything 12

Choose the script/scene that you created in Home Assistant. Hit “Save”, and “Next”.

How to trigger a Home Assistant script through Alexa and make your Raspberry Pi picture frame do (just about) anything 13
How to trigger a Home Assistant script through Alexa and make your Raspberry Pi picture frame do (just about) anything 14
How to trigger a Home Assistant script through Alexa and make your Raspberry Pi picture frame do (just about) anything 15

Wait a few seconds until the Amazon servers have digested your settings and test the routine by tapping on the “Play” sign on the right of your routine. Your command is now sent to Pi3D on your picture frame. If that works, the voice command will equally work.

Conclusion

Three simple commands that help you to operate your digital picture frame in the most convenient way possible – your voice.

Especially deleting images by voice as you see them has become a feature that we like to use frequently at home to cull those images that may have been nice at the time but are no longer. This way, you have nothing but beautiful memories, nature, or friends & family on your frame.

Is there another command that you would like to see? Let me know!

Was this post helpful?

Scroll to Top