I have an automation that sends a camera image to my TV when the doorbell is rung. I would like the image to stay for a few seconds and then revert the TV back to what it was doing. What is the easiest way to accomplish this? Here is my automation so far:
- alias: Doorbell Cast Front Door Camera Image To TV
initial_state: true
trigger:
platform: state
entity_id: binary_sensor.doorbell
to: 'on'
action:
- service: media_player.turn_on
entity_id: media_player.xbr_85x900f
- delay: 0:0:01
- service: media_player.play_media
data:
media_content_id: http://192.168.1.37/cgi-bin/api.cgi?cmd=Snap&channel=0&rs=wuuPhkmUCeI9WG7C&user=admin&password=xxxxxx
media_content_type: image/jpg
Create a script that accepts all data from the state of the media player. This script will contain all the stuff in your current action section followed by a delay and a service to resume the previous state. Then in your current automation, replace the action section with a single service, calling your script. In the data_template section of that call, get all the state (and attributes), passing them to the script.
Forgive my ignorance but what service do I use to resume the previous state? I thought I would find this under Developer Tools/Services/Media_player But I don’t see a resume so not sure how to call that service.
You don’t use a service, you call the script. As variables you pass the current attributes of the light. You’re using the variables of a script to ‘store’ the previous settings.
→ call script. Pass current media player attributes… i.e. paused, playing, media, etc.
in script:
→ turn on media player
→ delay a second
→ play media
→ delay a second
→ use variables to restore state using whatever service you need to call. You may need to use a service template here calling multiple script scenarios as different services require different fields.
The scene creation approach has worked a treat for me to put my Sonos back to what it was doing after I’d interrupted it with a text to speech message.