@naumz wrote:
First time poster here. I recently setup HA on a Raspberry PI and have had a lot of fun with it. As I create more automations, I was curious about different ways to design automations to be robust to errors/exceptions in actions.
This came to my mind because a recent update changed the behavior of the Roku integration on my TCL TV to raise Connection errors when the current state is
standby
(https://github.com/home-assistant/core/issues/36094). I dealt with it by using a service_template with an explicit condition on the state and using a noop script with 0 delay in the else statement ({% if ... elif ... else %} with no else - what do you do?).I also read about creating a separate script with the action that is likely to throw an error so the main automation doesn’t fail.
The first approach requires knowing the exact state that may cause an error, and the second one doesn’t but requires splitting it out into a separate file.
Are there other/recommended ways of achieving a similar outcome?
For reference, here is the relevant part of my original automation:
- id: '1588671360892' alias: Play Youtube video description: Play Youtube video at a certain time trigger: - platform: template value_template: '{{ as_timestamp(states(''sensor.date_time_iso'')) == as_timestamp(states(''sensor.sunset_time'')) }}' action: - data: is_volume_muted: true entity_id: media_player.living_room_tv service: media_player.volume_mute - entity_id: media_player.living_room_tv service: media_player.media_play_pause - data_template: volume_level: '{{''0.4'' if now().hour >= 21 else ''0.6''}}' entity_id: media_player.bedroom_speaker service: media_player.volume_set - data: entity_id: media_player.bedroom_speaker media_content_id: https://www.youtube.com/watch?v=XYZ media_content_type: music service: media_extractor.play_media - data: is_volume_muted: false entity_id: media_player.bedroom_speaker service: media_player.volume_mute - delay: 00:03:25 - data: volume_level: '0.4' entity_id: media_player.bedroom_speaker service: media_player.volume_set - delay: 00:00:10 - entity_id: media_player.living_room_tv service: media_player.media_play_pause - data: {} entity_id: media_player.living_room_tv service: media_player.volume_up
This is what I had to change the specific action section to:
- entity_id: media_player.living_room_tv service_template: "{% if states('media_player.living_room_tv') != 'standby' %}\n\ \ media_player.media_play_pause\n{% else %}\n script.noop\n{% endif %}\n"
Posts: 1
Participants: 1